is the FFT right?

1 view (last 30 days)
I am trying to analyze data that I recorded from the Force Sensitive Resistors (FSRs) coded on Arduino through data streamer on excel. I used four FSRs, so there are 4 columns of data over a set of time (1200 rows, about 15 seconds). I seperated time from the FSR data so that I can graph the FFT of the FSR data against the time.
I have made a different question which has been answered, but I was wondering if this method works as well.
Here is the code:
X = importdata('botdata.csv');
t = importdata('botdatatime.csv');
subplot(2,1,1);
plot(t,X);
xft=fft(X,[],1);
xabs = abs(xft);
subplot(2,1,2);
plot(t,xabs);
This is what was displayed.
Now I don't know if it makes sense or not.
What is the meaning of the y axis?
Is this correct?

Accepted Answer

Star Strider
Star Strider on 3 May 2021
‘What is the meaning of the y axis?’
It is necessary to normalise the fft result by the length of the vector it uses as an argument. (This is nin the fft documentation.) Once that is done, the y-axis units make sense.
Is this correct?
Almost. I made a few changes to eliminate the constant offset from the fft result, normalise it, and plot a one-sided Fourier transform. The multiplication-by-2 corrects the one-sided Fourier transform amplitude, since the energy at each frequency is divided evenly betweek the ‘positive’ and ‘negativeÄ fft frequencies.
X = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/606440/botdata.csv');
t = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/606445/botdatatime.csv');
subplot(2,1,1);
plot(t,X);
grid
xlabel('Time')
ylabel('Amplitude')
L = numel(X);
Ts = mean(diff(t))
Ts = 0.0128
% Tsd = std(mean(diff(t)))
Fs = 1/Ts;
Fn = Fs/2
Fn = 39.1012
xft=fft(X-mean(X),[],1)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:numel(Fv);
xabs = abs(xft);
subplot(2,1,2);
plot(Fv,mag2db(xabs(Iv)*2))
grid
ylim([-75 50])
xlabel('Freqency [units]')
ylabel('Power [dB]')
.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!