Contents
Home Work 1 - Band Pass Recursive Filtering of Signal
clear, clc, home
fprintf('The date and time: %s \n \n', datestr(now))
The date and time: 03-Mar-2009 11:42:38
The Original Signals
t = 0:.01:1;
x = 5*sin(10*t) + sin(60*t) + .5*sin(200*t) + .5*sin(300*t);
f_s = 100;
f_nyquist = f_s/2;
plot(t, x)
The Theory of Recursive Filtering.
Band Pass Filtering of a Signal x(t).
BW = .002;
fp = .1;
R = 1 - 3*BW;
K = (1 - 2*R*cos(2*pi*fp) + R^4)/(2-2*cos(2*pi*fp));
a0 = 1-K;
a1 = 2*(K-R)*cos(2*pi*fp);
a2 = R^2-K;
b1 = 2*R*cos(2*pi*fp);
b2 = -R^2;
M = 7;
len_x = length(x);
y(M) = 1/M*(x(1) + x(2) + x(3) + x(4) + x(5) + x(6) + x(7));
y(M+1) = y(M) + 1/M*(x(8)-x(1));
for i = (M+2):len_x-M
y(i) = a0*x(i) + a1*x(i-1) + a2*x(i-2) + b1*y(i-1) + b2*y(i-2);
end
y = y(M:len_x-M);
t_sampled = t(M:len_x-M);
len_t = length(t_sampled)
len_y = length(y)
plot(t_sampled, y)
len_t =
88
len_y =
88
Compairson of Sampled Signal to Filtered Signal
plot(t_sampled, y, t, x), xlabel('Time'), ylabel('Amplitude'), ...
legend('Filtered Signal','Sampled Signal','Location','North'), ...
title('Compairson of Sampled Signal to Filtered Signal')
Perform an FFT of both the original and the filtered signal
exp = log(f_s)./log(2);
fft_freq = 2^(ceil(exp));
x_fft = fft(x, fft_freq);
x_fft = abs(x_fft);
x_fft = x_fft(1:(fft_freq/2));
frequency_vector = f_nyquist*linspace(0,1,(fft_freq/2));
y_fft = fft(y, fft_freq);
y_fft = abs(y_fft);
y_fft = y_fft(1:(fft_freq/2));
plot(frequency_vector, x_fft, frequency_vector, y_fft), ...
xlabel('Frequency'), ylabel('Frequency Content'), ...
title('Frequency Content in the Original and Filtered Signal'), ...
legend('Original Signal', 'Filtered Signal')