How to smooth a FFT signal?

160 views (last 30 days)
Wakeel Mohammed
Wakeel Mohammed on 20 Jan 2021
Commented: Star Strider on 21 Jan 2021
I managed to plot the FFT spectrum using the below code. But I couldn't plot the smoothed spectrum. Can anyone suggest me a way to go through it? and How to choose order and frame length for the sgolayfilt code.
clc
data = xlsread('Reading 5(10000).xlsx') ; %Loading Sensor data from Excel file
t = data (1:1024,1); %Selecting Time vector
s = data (1:1024,4); %Selecting Z axis vibrations
L = numel(t); %Signal length
Ts = mean(diff(t)); %Sampling interval
Fs = 1/Ts; %Sampling frequency
Fn = Fs/2; %Nyquist frequency
FTs = fft(s)/L; %Fast fourier transform (s- data)
Fv = linspace(0,1, fix(L/2)+1)*Fn; %Frequency vector
Iv = 1:numel(Fv); %Index vector
IV = Iv-mean(Iv);
FTsiga = double(abs(FTs(Iv))*2); %Magnitude,Convert to double
S_smth = sgolayfilt(FTsiga,20,501); %Savitzky-Golay filtering of FFT
h = figure(1);
subplot(4, 1, 1); %plotting top pane
plot(t,s); %Acceleration vs time
set(gca,'xlim',[1 51.2]); %Scale to fit
grid; %Grids on
title ({'Graph 5','Acceleration vs time'});
xlabel('time(s)');
ylabel('Acceleration (m/s^2)');
subplot(4, 1, 2); %Plotting bottom pane
plot(Fv, abs(FTs(Iv))*2,'red'); %FFT - Amplitude vs Frequency
grid
title ('Fast fourier transform');
xlabel('Frequency (Hz)');
ylabel ('Amplitude (m)');
subplot(4, 1, 3); %FFT
% plot(Fv, abs(FTs(Iv))*2,'red'); %FFT - Amplitude vs Frequency
% grid
% title ('Fast fourier transform');
% xlabel('Frequency (kHz)');
% ylabel ('Amplitude (m)');
% hold on
Y = fft(s-mean(s)); %Subtracting the mean before FFT to remove DC
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
plot(Fv,P1,'Green');
title ('Fast Fourier Transform - "DC removed"');
xlabel('Frequency (Hz)');
ylabel ('Amplitude (m)');
subplot(4,1,4); %Plotting filtered FFT
plot (Fv,S_smth,'-k');
title ('Fast Fourier Transform - "Filtered"');
xlabel('Frequency (kHz)');
ylabel ('Amplitude (m)');
% fig = figure(1);
% print(fig, 'myFileName.pdf', '-dpdf','-r0')
% saveas (h,'Graph5.png')
% saveas (h,'Graph5.eps')
% saveas (h,'Graph5.jpg')
  3 Comments
Wakeel Mohammed
Wakeel Mohammed on 21 Jan 2021
Yes ofcourse! I get the knowledge from on of your post couple of years ago! and thank you very much for your answer above, you are great man!

Sign in to comment.

Answers (0)

Categories

Find more on Vibration Analysis in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!