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
6969 double window [2048] ;
7070 double filter [2048] ;
7171 double mag [1024] ;
72+ double logmag [1024] ;
7273 double phase [1024] ;
7374 } FIR_INTERP ;
7475
@@ -128,7 +129,7 @@ poly_evaluate (int order, const double *coeff, double x) · 53 unmodified lines
128129 static double
129130 evaluate_filter (FIR_INTERP *interp)
130131 {
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) ;
132133
133134 return 1.0 ;
134135 } /* evaluate_filter */
@@ -360,6 +361,14 @@ oct_save (const FIR_INTERP *interp) · 225 unmodified lines
360361 for (k = 0 ; k < ARRAY_LEN (interp->mag) ; k++)
361362 fprintf (file, "% f\n", interp->mag [k]) ;
362363
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+
363372 fprintf (file, "# name: phase\n") ;
364373 fprintf (file, "# type: matrix\n") ;
365374 fprintf (file, "# rows: %d\n", ARRAY_LEN (interp->phase)) ;
FIR-POLY/mag_spectrum.cc+2−1
@@ -26,7 +26,7 @@ · 25 unmodified lines
2626 #include <fftw3.h>
2727
2828 void
29−mag_spectrum (double *input, int len, double *magnitude, double *phase)
29+mag_spectrum (double *input, int len, double *magnitude, double *logmag, double *phase)
3030 { static fftw_plan plan = NULL ;
3131 static int saved_len = -1 ;
3232 static double *fft_data = NULL ;
@@ -61,6 +61,7 @@ mag_spectrum (double *input, int len, double *magnitude, double *phase) · 28 unmodified lines
6161 maxval = 0.0 ;
6262 for (k = 0 ; k < len / 2 ; k++)
6363 { 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]) ;
6465 phase [k] = atan2 (fft_data [len - k - 1], fft_data [k]) ;
6566 } ;
6667
FIR-POLY/mag_spectrum.hh+1−1
@@ -18,7 +18,7 @@ · 17 unmodified lines
1818 ** written permission of Erik de Castro Lopo.
1919 */
2020
21−void mag_spectrum (double *input, int len, double *magnitude, double *phase) ;
21+void mag_spectrum (double *input, int len, double *magnitude, double *logmag, double *phase) ;
2222
2323 // Do not edit or modify anything in this comment block.
2424 // 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