Unified · Split
| @@ -69,6 +69,7 @@ typedef struct · 68 unmodified lines | ||
| 69 | 69 | double window [2048] ; |
| 70 | 70 | double filter [2048] ; |
| 71 | 71 | double mag [1024] ; |
| 72 | + double logmag [1024] ; | |
| 72 | 73 | double phase [1024] ; |
| 73 | 74 | } FIR_INTERP ; |
| 74 | 75 | |
| @@ -128,7 +129,7 @@ poly_evaluate (int order, const double *coeff, double x) · 53 unmodified lines | ||
| 128 | 129 | static double |
| 129 | 130 | evaluate_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 | 134 | return 1.0 ; |
| 134 | 135 | } /* evaluate_filter */ |
| @@ -360,6 +361,14 @@ oct_save (const FIR_INTERP *interp) · 225 unmodified lines | ||
| 360 | 361 | for (k = 0 ; k < ARRAY_LEN (interp->mag) ; k++) |
| 361 | 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 | 372 | fprintf (file, "# name: phase\n") ; |
| 364 | 373 | fprintf (file, "# type: matrix\n") ; |
| 365 | 374 | fprintf (file, "# rows: %d\n", ARRAY_LEN (interp->phase)) ; |
| @@ -26,7 +26,7 @@ · 25 unmodified lines | ||
| 26 | 26 | #include <fftw3.h> |
| 27 | 27 | |
| 28 | 28 | 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) | |
| 30 | 30 | { static fftw_plan plan = NULL ; |
| 31 | 31 | static int saved_len = -1 ; |
| 32 | 32 | static double *fft_data = NULL ; |
| @@ -61,6 +61,7 @@ mag_spectrum (double *input, int len, double *magnitude, double *phase) · 28 unmodified lines | ||
| 61 | 61 | maxval = 0.0 ; |
| 62 | 62 | for (k = 0 ; k < len / 2 ; k++) |
| 63 | 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 | 65 | phase [k] = atan2 (fft_data [len - k - 1], fft_data [k]) ; |
| 65 | 66 | } ; |
| 66 | 67 | |
| @@ -18,7 +18,7 @@ · 17 unmodified lines | ||
| 18 | 18 | ** written permission of Erik de Castro Lopo. |
| 19 | 19 | */ |
| 20 | 20 | |
| 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) ; | |
| 22 | 22 | |
| 23 | 23 | // Do not edit or modify anything in this comment block. |
| 24 | 24 | // The following line is a file identity tag for the GNU Arch |