Assuming that you are using a discrete Fourier transform to view frequencies, you should be careful how to interpret normalized frequencies back to physical (i.e. Hz).
According to the FFTW tutorial on how to calculate the signal power spectrum:
#include <rfftw.h> ... { fftw_real in[N], out[N], power_spectrum[N/2+1]; rfftw_plan p; int k; ... p = rfftw_create_plan(N, FFTW_REAL_TO_COMPLEX, FFTW_ESTIMATE); ... rfftw_one(p, in, out); power_spectrum[0] = out[0]*out[0]; /* DC component */ for (k = 1; k < (N+1)/2; ++k) /* (k < N/2 rounded up) */ power_spectrum[k] = out[k]*out[k] + out[Nk]*out[Nk]; if (N % 2 == 0) /* N is even */ power_spectrum[N/2] = out[N/2]*out[N/2]; /* Nyquist freq. */ ... rfftw_destroy_plan(p); }
Note that it processes data lengths that do not match. Please note, especially if the data length is specified, FFTW will give you a βbitβ corresponding to the Nyquist frequency (sampling frequency divided by 2). Otherwise, you will not get it (i.e. the last bit is just below Nyquist).
A MATLAB example is similar, but they choose a length of 1000 (an even number) for the example:
N = length(x); xdft = fft(x); xdft = xdft(1:N/2+1); psdx = (1/(Fs*N)).*abs(xdft).^2; psdx(2:end-1) = 2*psdx(2:end-1); freq = 0:Fs/length(x):Fs/2;
In general, this may be an implementation (from DFT) dependent. You must create a test pure sine wave with a known frequency, and then make sure that the calculation gives the same number.
pelesl
source share