How to smooth a Fourier transform plot?

22 vues (au cours des 30 derniers jours)
Hussam Eldin Rabah
Hussam Eldin Rabah le 5 Déc 2018
Hey everyone!
Actually, I have plotted FFT of a system in some range of frequencies. However, the plot isn't smooth at all, which I can't use for my project, but the results almost right.
I tried to use smooth function in matlab, but it doesn't work as I want. Furthermore, I tried to use moving average filter with different weights, and was the same thing!
The following is the output of the system without and with a moving average filter filter
  3 commentaires
Hussam Eldin Rabah
Hussam Eldin Rabah le 5 Déc 2018
clear all; close all; clc;
Meq = 0.0282354; %%The Equivalent Mass
Keq = 269.5; %%The Equivalent Stiffness
Ceq = 0.05517; %%The Equivalent Damping
Wn = 97.6973; %%Natural Frequency
Rload = 105522.6537;
EMCC = 1.71e-4;
M = 1.0154;
Cs = 97e-9;
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 5000; % Length of signal
t = (0:L-1)*T; % Time vector
A = [0 1 0 ; -Keq/Meq -Ceq/Meq -EMCC/Meq ; 0 EMCC/Cs -1/(Cs*Rload)];
B = [0 ; 1 ; 0];
C = [1 0 0];
D = [0];
freq1 = 11;
freq2 = 11.5;
freq3 = 12;
freq4 = 12.5;
freq5 = 13;
freq6 = 13.5;
freq7 = 14;
freq8 = 14.5;
freq9 = 15;
freq10 = 15.5;
freq11 = 16;
freq12 = 16.5;
freq13 = 17;
freq14 = 17.5;
freq15 = 18;
freq16 = 18.5;
freq17 = 19;
freq18 = 19.5;
freq19 = 20;
freq20 = 20.5;
freq21 = 21;
s = sin(2*pi*freq1*t) + sin(2*pi*freq2*t) + sin(2*pi*freq3*t) + sin(2*pi*freq4*t) + sin(2*pi*freq5*t) + sin(2*pi*freq6*t) + sin(2*pi*freq7*t) + sin(2*pi*freq8*t) + sin(2*pi*freq9*t) + sin(2*pi*freq10*t) + sin(2*pi*freq11*t) + sin(2*pi*freq12*t) + sin(2*pi*freq13*t) + sin(2*pi*freq14*t) + sin(2*pi*freq15*t) + sin(2*pi*freq16*t) + sin(2*pi*freq17*t) + sin(2*pi*freq18*t) + sin(2*pi*freq19*t) + sin(2*pi*freq20*t) + sin(2*pi*freq21*t) + 2*rand(size(t));
system = ss(A , B , C , D);
y = lsim(system,s,t);
Y = fft(y);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
%Moving Average Filter
Width = 2;
FR = ones(1,Width) / Width;
FR1 = filter(FR, 1, P1);
%Savitzky-Golay Filters
%a = sgolayfilt(P1, 3, 5);
f = Fs*(0:(L/2))/L;
plot(f,P1)
hold on
plot(f,FR1)
hold on
legend("No filters","Moving Average Filter","Savitzky-Golay Filters")
grid on
xlim([12 20])
title('Spectrum of System')
xlabel('Frequency (Hz)')
ylabel('Magnitude')
hold on
Hussam Eldin Rabah
Hussam Eldin Rabah le 5 Déc 2018
You can use random function or multi tune function as a summation of multi sin waves of multi frequencies instead of makin a loop.

Connectez-vous pour commenter.

Réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by