Contents
Home Work 1 - Single Pole High 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:12:21
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.
Single Pole Low Pass Filtering of a Signal x(t).
z = 0.4;
a0 = (1-z)/2;
a1 = -(1-z)/2;
b1 = z;
M = 7;
len_x = length(x);
y(M) = 1/M*(x(1) + x(2) + x(3) + x(4) + x(5) + x(6) + x(7));
for i = (M+1):len_x-M
y(i) = a0*x(i) + a1*x(i-1) + b1*y(i-1);
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')