How to take the FFT of CSV data collected from Arduino
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a CSV data that I want to use spectral analysis on. I've tried looking at examples but they all create their own signal (for example sin(2*PI*f*t)) and that works out, but what about when you just have the data, since I can't model my signal? I input a sin function my code below to test the code. The output should have a peak at 2 Hz but it doesn't look anything like that although the time domain graph shows the correct sin wave. The sin CSV data had 2000 samples.
if true
%code starts here
array = csvread('fakesig.csv'); %Signal import
signaltime = array(:, 2); %Creating signal time
signaldata = array(:, 1); %Creating signal data
N = 2^nextpow2(length(signaldata));
p = abs(fft(signaldata,N))/N; %Power of signal
Fs = 2000; %Sampling frequency
f = Fs/2*linspace(0,1,N); %Frequency spacing
subplot(1,2,1), plot(signaltime,signaldata)
xlabel('Time(s)'),ylabel('Amplitude')
subplot(1,2,2), plot(f,p)
xlabel('Frequency (Hz)'),ylabel('Amplitude')
end
and heres the output:

0 Kommentare
Antworten (2)
Geoff Hayes
am 29 Dez. 2014
Dutchy - what is the length of the signalData which determines the block size N? The discrete outputs from the FFT N-point transform can only be associated with frequencies that are multiples of Fs/N where the multiples are
m*Fs/N for m=0,1,2,...,N-1
If there does not exist an m such that m*Fs/N is equal to 2, then you will not see the peak at 2 Hz.
Try changing N to 2000, and see what happens.
0 Kommentare
Star Strider
am 29 Dez. 2014
Change your ‘frequency spacing’ line to:
f = Fs/2*linspace(0,1,N/2+1); %Frequency spacing
and you should get the result you want.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Parametric Spectral Estimation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!