Académique Documents
Professionnel Documents
Culture Documents
SCRIPT
clear all, clc, close all
Fs = 200;
Ts = 1/Fs;
x = 0:Ts:1;
Nx = length(x);
f = [5 10 15];
ytotal = 0;
for i = 1:length(f)
yi = sin(2*pi*f(i)*x);
ytotal = yi+ytotal;
end
Y = fft(ytotal,Nx);
xf = (0:1:length(Y)-1)*Fs/Nx;
figure(1)
subplot(2,1,1), plot(x,ytotal),hold on, grid on, title('data waktu
domain'), xlabel('waktu'), ylabel('amplitudo')
subplot(2,1,2), plot(xf,abs(Y)./Nx),hold on, grid on, title('data
frekuensi domain'), xlabel('frekuensi'), ylabel('amplitudo')
fc = 5;
Nh = length(x);
hsupp = (-(Nh-1)/2:(Nh-1)/2);
m = 2*fc/Fs;
% h = sin(m*pi.*hsupp)./(pi.*hsupp);
% h(ceil(length(h)/2)) = m/pi;
% h = sin((2*pi*fc/Fs).*hsupp)./(pi.*hsupp);
% h(ceil(length(h)/2)) = (2*pi*fc/Fs)/pi;
% h = (2*fc/Fs)*sinc((2*fc/Fs)*hsupp);
h = m*sinc(m*hsupp);
h = hamming(Nh)'.*h; %h is our filter
% h = blackman(Nh)'.*h; %h is our filter
H = fft(h,Nh);
amp_H = abs(H);
xfh= (0:1:length(H)-1)*Fs/Nh;
% %fdesign---------------
m=2*fc/Fs;
d = fdesign.highpass('Fst,Fp,Ast,Ap',m-0.01,m+0.01,60,1); %mendefinisikan
Hd = design(d,'equiripple');
yfd = filter(Hd,ytotal);
%fir-------------------
Wn = (2/Fs)*fc;
b = fir1(Nx,Wn,'high');
yfir = filter(b,1,ytotal);
%sinc filtering-----------------
figure(2)
subplot(2,1,1), plot(hsupp,h,'-'),hold on,grid on, title('filter domain
waktu'), xlabel('waktu'), ylabel('amplitudo')
subplot(2,1,2), plot(xfh,amp_H,'-'),hold on,grid on, title('filter domain
frekuensi'), xlabel('frekuensi'), ylabel('amplitudo')
Yfil = Y.*H;
yfil = ifft(Yfil);
%-------------------------------
%sinc filtering-----------------
figure(3)
subplot(2,1,1)
plot(xf,abs(Yfil)/Nx,'-'),grid on, hold on, title('hasil filtering,
domain frekuensi')%sinc filtering-
plot(xf,abs(Y)/Nx,'r-'), legend('hasil filter', 'data awal')
subplot(2,1,2)
plot(x,yfil,'-'),grid on, hold on, title('hasil filtering, domain
waktu')%sinc filtering-
plot(x,ytotal,'r-'), legend('hasil filter', 'data awal')%----------------
---------------
figure(4)
plot(yfd,'-'), grid on, hold on
plot(yfir,'-'), grid on, hold on, legend('fdesign','fir1')
fvtool(b)
fvtool(Hd)