필터 지우기
필터 지우기

How to smooth a FFT signal?

조회 수: 118 (최근 30일)
Wakeel Mohammed
Wakeel Mohammed 2021년 1월 20일
댓글: Star Strider 2021년 1월 21일
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
Wakeel Mohammed
Wakeel Mohammed 2021년 1월 21일
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!
Star Strider
Star Strider 2021년 1월 21일
Thank you!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Vibration Analysis에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by