FFT from CSV file

9 Ansichten (letzte 30 Tage)
Ray Fang
Ray Fang am 16 Feb. 2019
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?

Akzeptierte Antwort

dpb
dpb am 16 Feb. 2019
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...
  4 Kommentare
Ray Fang
Ray Fang am 19 Feb. 2019
Thanks. It makes sense now that the sampling rate is 1E6 samples/10ms = 100 MHz. I'm getting the fundamental at 1,KHz and harmonics at 2, 3..., KHz, which looks correct.
dpb
dpb am 19 Feb. 2019
Yeah, I whiffed on that first go 'round; just took the Fs at face value without really looking at the rest that carefully...
Illustrates that the FFT doesn't care a whit about what the actual sample rate is; it just computes the numbers by bin; it's totally up to the user to set the scaling of the frequency axis to match the actual data collection process.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Sofi Fatoni putra
Sofi Fatoni putra am 2 Okt. 2019
Bearbeitet: Sofi Fatoni putra am 2 Okt. 2019
if I can ask for your data once again because the download in your dropbox can't be downloaded

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by