Home FFTW Output differs from Matlab with the same input dataset

# FFTW Output differs from Matlab with the same input dataset

mrcbis
1#
mrcbis Published in 2018-01-12 17:17:13Z
 I am developing an application that should analyze data coming from an A/D stage and find the frequency peaks in a defined frequency range (0-10kHz). We are using the FFTW3 library, version 3.3.6, running on 64bit Slackware Linux (GCC version 5.3.0). As you can see in the piece of code included, we run the FFTW plan getting result in complex vector result[]. We have verified the operations using MATLAB. We run the FFT on MATLAB (that claims to use the same library) with exactly the same input datasets (complex signal[] as in the source code). We observe some difference between FFTW (Linux ANSI C) and MATLAB run. Each plot is done using MATLAB. In particular, we would like to understand (mag[] array): Why is the noise floor so different? After the main peak (at more or less 3kHz) we observe a negative peak in the Linux result, while MATLAB shows correctly a secondary peak as from the input signal. In these examples, we do not perform any output normalization, neither in Linux nor in MATLAB. The two plots show the magnitude of the FFT results (not converted to dB). The correct result is the MATLAB one. Does someone have any suggestion about this differences? And how can we produce with the FFTW library results closer to MATLAB? Below the piece of C source code and the two plots. // // Part of source code: // // rup[] is filled with unsigned char data coming from an A/D conversion stage (8 bit depth) // Sampling Frequency is 45.454 KHz // Frequency Range: 0 - 10.0 KHz // #define CONVCOST 0.00787401574803149606 double mag[4096]; unsigned char rup[4096]; int i; fftw_complex signal[1024]; fftw_complex result[1024]; ... fftw_plan plan = fftw_plan_dft_1d(1024,signal,result,FFTW_FORWARD,FFTW_ESTIMATE); for(i=0;i<1024;i++) { signal[i][REAL] = (double)rup[i] * CONVCOST; signal[i][IMAG] = 0.0; } fftw_execute(plan); for (i = 0; i < 512; ++i) { mag[i] = sqrt(result[i][REAL] * result[i][REAL] + result[i][IMAG] * result[i][IMAG]); } fftw_destroy_plan(plan); 
 You need to login account before you can post.
Processed in 0.336159 second(s) , Gzip On .