You are on page 1of 1

close all;

clear all;
clc;
%---------------- Signal Generator ------------------------------------
Fsampling = 1000; % Sampling frequency
T = 1/Fsampling; % Sampling period
L = 1500; % Length of signal
t = (0:L-1)*T; % Time vector
x = sin(2*pi*20*t)+sin(2*pi*100*t)+sin(2*pi*1000*t);

%-----------------FIR Digital Filter (Fcutoff HPF 500 Hz)-------------

b0= 0.0051 ;b1=-0.0294;b2=0.1107 ;b3=-0.2193;b4=0.2710;b5=-0.2193 ;


b6=0.1107;b7=-0.0294 ;b8= 0.0051;
x7=0;x6=0;x5=0;x4=0;x3=0;x2=0;x1=0;x0=0;

for i=1:L
x8=x7;
x7=x6;
x6=x5;
x5=x4;
x4=x3;
x3=x2;
x2=x1;
x1=x0;
x0=x(i);
y=b0*x0 + b1*x1 + b2*x2 + b3*x3 + b4*x4 + b5*x5 + b6*x6...
+ b7*x7 + b8*x8;
yfilter(i)=y;
end
y = yfilter';

%-----------------Fast Fourier Transform (FFT) ----------------------


n = 2^nextpow2(L);
Yfft = fft(y,n);
P2 = abs(Yfft/L);
P1 = P2(1:n/2+1);
P1(1:end-1) = 2*P1(1:end-1);
figure;
subplot(3,1,1); plot(t,x);
title ('Original Signal');
subplot (3,1,2);plot(t,y);
title ('Filtered Signal');
subplot(3,1,3);plot(0:(Fsampling/n):(Fsampling/2-Fsampling/n),P1(1:n/2));
title ('Frequency of the signal');

You might also like