History

Add log magnitude calculations.

Erik de Castro Lopo committed 22 years ago

Commit 18106d31 parent 3ab82163 files · +13 −3Browse files

Unified · Split

3 files
  1. FIR-POLY/fir_interp.cc +10 −1
  2. FIR-POLY/mag_spectrum.cc +2 −1
  3. FIR-POLY/mag_spectrum.hh +1 −1
FIR-POLY/fir_interp.cc+10−1
@@ -69,6 +69,7 @@ typedef struct · 68 unmodified lines
69 double window [2048] ;69 double window [2048] ;
70 double filter [2048] ;70 double filter [2048] ;
71 double mag [1024] ;71 double mag [1024] ;
72 double logmag [1024] ;
72 double phase [1024] ;73 double phase [1024] ;
73} FIR_INTERP ;74} FIR_INTERP ;
74 75
@@ -128,7 +129,7 @@ poly_evaluate (int order, const double *coeff, double x) · 53 unmodified lines
128static double129static double
129evaluate_filter (FIR_INTERP *interp)130evaluate_filter (FIR_INTERP *interp)
130{131{
131 mag_spectrum (interp->filter, ARRAY_LEN (interp->filter), interp->mag, interp->phase) ;132 mag_spectrum (interp->filter, ARRAY_LEN (interp->filter), interp->mag, interp->logmag, interp->phase) ;
132 133
133 return 1.0 ;134 return 1.0 ;
134} /* evaluate_filter */135} /* evaluate_filter */
@@ -360,6 +361,14 @@ oct_save (const FIR_INTERP *interp) · 225 unmodified lines
360 for (k = 0 ; k < ARRAY_LEN (interp->mag) ; k++)361 for (k = 0 ; k < ARRAY_LEN (interp->mag) ; k++)
361 fprintf (file, "% f\n", interp->mag [k]) ;362 fprintf (file, "% f\n", interp->mag [k]) ;
362 363
364 fprintf (file, "# name: logmag\n") ;
365 fprintf (file, "# type: matrix\n") ;
366 fprintf (file, "# rows: %d\n", ARRAY_LEN (interp->logmag)) ;
367 fprintf (file, "# columns: 1\n") ;
368
369 for (k = 0 ; k < ARRAY_LEN (interp->logmag) ; k++)
370 fprintf (file, "% f\n", interp->logmag [k]) ;
371
363 fprintf (file, "# name: phase\n") ;372 fprintf (file, "# name: phase\n") ;
364 fprintf (file, "# type: matrix\n") ;373 fprintf (file, "# type: matrix\n") ;
365 fprintf (file, "# rows: %d\n", ARRAY_LEN (interp->phase)) ;374 fprintf (file, "# rows: %d\n", ARRAY_LEN (interp->phase)) ;
FIR-POLY/mag_spectrum.cc+2−1
@@ -26,7 +26,7 @@ · 25 unmodified lines
26#include <fftw3.h>26#include <fftw3.h>
27 27
28void28void
29mag_spectrum (double *input, int len, double *magnitude, double *phase)29mag_spectrum (double *input, int len, double *magnitude, double *logmag, double *phase)
30{ static fftw_plan plan = NULL ;30{ static fftw_plan plan = NULL ;
31 static int saved_len = -1 ;31 static int saved_len = -1 ;
32 static double *fft_data = NULL ;32 static double *fft_data = NULL ;
@@ -61,6 +61,7 @@ mag_spectrum (double *input, int len, double *magnitude, double *phase) · 28 unmodified lines
61 maxval = 0.0 ;61 maxval = 0.0 ;
62 for (k = 0 ; k < len / 2 ; k++)62 for (k = 0 ; k < len / 2 ; k++)
63 { magnitude [k] = sqrt (fft_data [k] * fft_data [k] + fft_data [len - k - 1] * fft_data [len - k - 1]) ;63 { magnitude [k] = sqrt (fft_data [k] * fft_data [k] + fft_data [len - k - 1] * fft_data [len - k - 1]) ;
64 logmag [k] = (magnitude [k] < 1e-10) ? -200.0 : 20 * log10 (magnitude [k]) ;
64 phase [k] = atan2 (fft_data [len - k - 1], fft_data [k]) ;65 phase [k] = atan2 (fft_data [len - k - 1], fft_data [k]) ;
65 } ;66 } ;
66 67
FIR-POLY/mag_spectrum.hh+1−1
@@ -18,7 +18,7 @@ · 17 unmodified lines
18** written permission of Erik de Castro Lopo.18** written permission of Erik de Castro Lopo.
19*/19*/
20 20
21void mag_spectrum (double *input, int len, double *magnitude, double *phase) ;21void mag_spectrum (double *input, int len, double *magnitude, double *logmag, double *phase) ;
22 22
23// Do not edit or modify anything in this comment block.23// Do not edit or modify anything in this comment block.
24// The following line is a file identity tag for the GNU Arch24// The following line is a file identity tag for the GNU Arch

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t