Hi, I would like to take the FFT of a signal but for some reason I do something wrong.
May someone could help me out?
I would like to see the FFT Spectrum for 2 seconds.
I attached the Excel file and the code.
Thanks!

 Accepted Answer

Star Strider
Star Strider on 26 Feb 2017
The constant (‘direct current’ or ‘d-c’ 0 Hz) offset is hiding the rest of your spectrum. This is a common problem, and since removing the constant offset does not affect the rest of your signal (and you can easily recover it if needed, since it is the mean of your signal), remove it before calculating the fft to see the rest of your spectrum.
This works:
[d,s] = xlsread('Good State.xls');
Time = d(:,1);
Good = d(:,2);
L = size(d,1); % Vector Length
Ts = mean(diff(Time)); % Sampling Interval (Assume ‘seconds’)
Fs = 1/Ts; % Sampling Frequency (Assume ‘Hz’)
Fn = Fs/2; % Nyquist Frequency (Assume ‘Hz’)
Good = Good - mean(Good); % Remove D-C (Constant) Offset
Y = fft(Good)/L; % Scaled Two-Sided Discrete Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector For Plot
figure(1)
plot(Fv, 2*abs(Y(Iv)))
grid
xlabel('Frequency')
ylabel('Magnitude')

More Answers (1)

Harry
Harry on 26 Feb 2017

0 votes

Brilliant! Thank you!

5 Comments

Star Strider
Star Strider on 26 Feb 2017
My pleasure!
Harry
Harry on 26 Feb 2017
May I ask you one more question?
I would like to apply feature extraction to a good and bad signal.
The FFT of the two signals is attached as a picture to this question.
How would you proceed?
Star Strider
Star Strider on 26 Feb 2017
I’ve not done this in a while.
I would use principal components analysis (the pca function in the Statistics and Machine Learning Toolbox) as a first approach. We did that with EEGs a couple decades ago with good results. It will tell you the components of the signal responsible for the maximum variance between the two, so I would begin there.
This is no longer an area of my expertise, so there may be better approaches. Consulting with a statistician would be appropriate.
Harry
Harry on 27 Feb 2017
Nice one!
Much appreciated!
Thank you
Star Strider
Star Strider on 27 Feb 2017
My pleasure!

Sign in to comment.

Asked:

on 26 Feb 2017

Commented:

on 27 Feb 2017

Community Treasure Hunt

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

Start Hunting!