How to smooth a FFT signal?
120 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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. ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/495059/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/495059/image.jpeg)
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 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Vibration Analysis 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!