Skip to content

Instantly share code, notes, and snippets.

@johnnyferreiradev
Last active April 9, 2019 00:05
Show Gist options
  • Save johnnyferreiradev/d1af324889f2c612b579bab69eaf5f79 to your computer and use it in GitHub Desktop.
Save johnnyferreiradev/d1af324889f2c612b579bab69eaf5f79 to your computer and use it in GitHub Desktop.
Transformada de Fourier com Filtro Passa Baixa
%Deve-se digitar na janela de comandos para funcionar: pkg load signal
clear all;
close all;
clc;
fs=1000; Ts=1/fs;
f1=20;
DigFreq1=2*pi*f1/fs;
f2=30;
DigFreq2=2*pi*f2/fs;
f3=40;
DigFreq3=2*pi*f3/fs;
N=1500;
n = 0:1:N-1;
t_sample = (0: Ts : (N-1)*Ts);
x=3.*cos(DigFreq1.*n+0.2) + cos(DigFreq2.*n-0.3) + 2.*cos(DigFreq3.*n+2.4);
figure; plot(t_sample, x)
X=fft(x);
X_mag=abs(X);
figure;
Fbin=0:1:N-1;
plot((fs/N).*Fbin, X_mag/(N/2));
xlim([0 fs/2])
set(gca, 'FontSize', 16)
xlabel('$f(Hz)$', 'Interpreter', 'LaTex', 'FontSize', 18);
ylabel('$|X(\omega)|$', 'Interpreter', 'LaTex', 'FontSize', 18);
fcorte = 25;
[D,C] = butter(10, 2*pi*fcorte, 'low', 's');
plantaFiltro = tf(D, C);
xF = lsim(plantaFiltro, x, t_sample);
figure(3); plot(t_sample, xF)
XF = fft(xF);
X_magF = abs(XF);
figure(4);
plot((fs/N).*Fbin, X_magF/(N/2))
xlim([0 fs/2])
set(gca, 'FontSize', 16)
xlabel('$f(Hz)$', 'Interpreter', 'LaTex', 'FontSize', 18);
ylabel('$|X(\omega)|$', 'Interpreter', 'LaTex', 'FontSize', 18);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment