%% L09_Recursion %% ============== %% Script to illustrate Recursive (IIR) filter implementation. %% See Lecture09 %% %% Created : 15 Aug 2005 %% Modified : 15 Aug 2005 %% %% Copyright (c) 2005 Salman Durrani . %% ------------------------------------------------------------ clc clear all %% Sampling frequency Fs = 500; %% Time vector of 0.5second t = 0:1/Fs:0.5; %% Create a sine wave of 10 Hz corrupted by sine wave of 100 Hz x = sin(2*pi*t*10) +sin(2*pi*t*100); L=length(x); %% Recursive/IIR filter (low pass) fc = 0.05*Fs/2 = 12.5 Hz a0=0.15; b1=0.85; y(1)=0; for k=2:L y(k)=a0*x(k)+b1*y(k-1); end %% Generate the plot, title and labels. figure plot(t,sin(2*pi*t*10),'b'); hold on plot(t,sin(2*pi*t*100),'g') xlabel('Time (s)'); ylabel('Amplitude') legend('10 Hz','100 Hz') axis([0 0.5 -2 2]) figure plot(t,x,'k'); hold on plot(t,y,'r','Linewidth',2) xlabel('Time (s)'); ylabel('Amplitude') legend('Filter Input','Filter Output') axis([0 0.5 -2 2]) figure plot(t,sin(2*pi*t*10),'b'); hold on plot(t,y,'r','Linewidth',2) xlabel('Time (s)'); ylabel('Amplitude') legend('10 Hz','Filter Output') axis([0 0.5 -2 2]) %% Normalised Frequency Response figure num=[a0]; den=[1 -b1]; freqz(num,den) %% Scaled Frequency Response of Filter using knowledge of sampling %% frequency figure num=[a0]; den=[1 -b1]; freqz(num,den,512,Fs)