Contents
Home Work 1 - Single Pole Low Pass Recursive Filtering of Signal
% Programmer: Aaron Klapheck % Date: 3-Mar-09 clear, clc, home fprintf('The date and time: %s \n \n', datestr(now))
The date and time: 03-Mar-2009 11:11:35
The Original Signals
t = 0:.01:1; % Sample time x = 5*sin(10*t) + sin(60*t) + .5*sin(200*t) + .5*sin(300*t); % Signal with noise f_s = 100; % Hz. Sample rate. Given by (c-a)/b, where t = a:b:c. . f_nyquist = f_s/2; % By definition % give a top signal frequency: % sample frequency => 2*(signal frequency) plot(t, x)
The Theory of Recursive Filtering.
% Recursive Equation: % y[n] = a0*x[n] + a1*x[n-1] + a2*x[n-2] + ... + b1*y[n-1] + b2*y[n-2] ... % Note: Usually less than 24 terms used (12 a's and 12 b's). % Single pole low pass filter % Physical representation: % A single pole low pass filter can be represented as an RC circuit where % Vin is the applied voltage across both circuit elements (which are in % series) and Vout is the voltage across the capaciter. % Equation: % y[n] = a0*x[n] + b1*y[n-1]
Single Pole Low Pass Filtering of a Signal x(t).
% low pass filter equation: % y[n] = a0*x[n] + b1*y[n-1] % Select z z = .75; % arbitrary value a0 = 1-z; b1 = z; M = 7; % Numbr of points to average. 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) + b1*y(i-1); end % get rid of the fist few data points which are zero. y = y(M:len_x - M); t_sampled = t(M:len_x - M); % Make sure the length of y matches the lenght of t. 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') % Notice that the filtered signal is phase shifted ahead of the original % signal.
Perform an FFT of both the original and the filtered signal
% Decide which exponant of 2 to use to make the fft go faster. % This involves changing the sample frequecy to a larger number. % This change of the sample frequency will change the look of the fft plot % but the peaks which tell us where the natural frequencies are present will % not change depending on fft_freq. To test this out set fft_freq equal to % 100 or any other similar value and view the graph before and after. exp = log(f_s)./log(2); fft_freq = 2^(ceil(exp)); x_fft = fft(x, fft_freq); x_fft = abs(x_fft); % Eliminate immaginary componant x_fft = x_fft(1:(fft_freq/2)); % Plot from 0 to .5*f_s frequency_vector = f_nyquist*linspace(0,1,(fft_freq/2)); y_fft = fft(y, fft_freq); y_fft = abs(y_fft); % Eliminate immaginary componant 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')