MATLAB: FFT from CSV file

csvfft

I'm trying to perform FFT on the 2nd data column of a .csv file. The .csv file is quite large and the zipped version can be found here: https://www.dropbox.com/s/87l5vtxdqfbtt6x/Tridral_1m_1ms.7z?dl=0
The signal is 10 milliseconds long, and is sampled 1 million times over that time period. I've tried following the FFT example provided by the help file, but the frequency domain signal does not come out right. The FFT output gives a strong DC signal (that could be right), and a signal at 50 KHz. Based on the time domain signal, i should expect approximately a 1 KHz fundamental with recurrent harmonics at 2, 3, 4 KHz…, but it comes out empty… am i doing something wrong in my code?

Best Answer

Follow the recipe provided precisely...you've doubled the DC and Fmax components so that the DC bias is shown as twice what it would really be--and to find the frequency content in the signal you should either remove the mean first or, alternatively, just zero-out the DC component of the PSD. The former will be better numerically in preventing loss of precision in low-energy bins in the FFT, so that would be my recommendation.
...
y=raw_data(:,2)-mean(raw_data(:,2)); % eliminate DC bias
L=length(y);
Y = fft(y); % with 1E6 points, don't need interpolating
P2 = abs(Y/L); % two-sided spectrum
P1 = P2(1:L/2+1); % one-sided
P1(2:end-1) = 2*P1(2:end-1); % normalize; except not DC and Fmax that are only one point
f = Fs*(0:(L/2))/L;
plot(f,P1) % should show you actual frequency content
Undoubtedly, using semilogy() to amplify the dynamic range and zooming in on the lower frequency range will help to be able to see what structure there is in the signal.
You'll need to ensure the input signal is actually quality data and not contaminated somehow, too, of course...
Related Question