%This script builds the IIR bandstop filter using the bilinear transform. This filter %uses the butterworth characteristic. The output plots include the built in plots when %calling freqz without any output arguments and freqz with output arguments. For this script the %desired cutoff frequency is 2Khz and 3Khz. %MAGNITUDE RESPONSE PLOT - Used to determine the attenuation of the filter at different frequencies. % The plot is calculated in dB so we may notice small changes in the response. % To see the response up to the sampling frequency use the following command: % subplot(2,2,1),axis([0 1 -100 0]); %This shows the axis up to -100 dB %PHASE RESPONSE PLOT - Used to find the phase change the signal will exhibit at different frequencies. %ZPLANE PLOT - Used to determine the stability of the filter. The Unit circle is set to 1. Any poles % outside the unit circle could show that the filter is unstable. %GROUPDELAY PLOT - Used to determine the system delay the filter exhibits by the number of samples. % %NOTE: All desired frequencies are normalized to half the sampling frequency Fs/2. % This is due to Nyquist's Thoerem which states that: Fs > 2F or (Fs/2) > F clear NUM_OF_POINTS = 512; FILTER_ORDER = 2; %Filter Order CUTOFF_FREQ = [2e3 3e3]; %Cutoff Frequency (frequency which gives 3dB attenuation) SAMP_FREQ = 10e3; %Sampling Frequency (frequency used to sample the analog signal) normalized_freq = CUTOFF_FREQ/(SAMP_FREQ/2) %create normalized frequency [B,A]=butter(FILTER_ORDER,normalized_freq,'stop'); %create digital butterworth filter using bilinear transform %freqz(B,A),axis([0 1 -10 0]); %create plot of magnitude and phase response and scale the plot [H,W]=freqz(B,A,NUM_OF_POINTS); %get the magnitude response. figure,subplot(2,2,1),plot(W/pi,20*log10(abs(H))),grid,axis([0 1 -20 1]); %plot the magnitude response. title('Magnitude Response |H(z)|'),xlabel('Normalized Frequency Fcn = F/(Fs/2)'),ylabel('Magnitude (dB)'); subplot(2,2,2),plot(W/pi,angle(H)),grid; %plot the phase response. title('Phase Response |H(z)|'),xlabel('Normalized Frequency Fcn = F/(Fs/2)'),ylabel('Phase (Radians)'); [z,p,k]=tf2zp(B,A); %Transform digital transfer function to zeros and poles. subplot(2,2,3),zplane(z,p),legend('Zeros','Poles'),title('Unit Circle Plot'); %Plot the zeros and poles on the Unit circle (Used to check for stability) subplot(2,2,4),grpdelay(B,A),title('Group Delay');%,CUTOFF_FREQ,SAMP_FREQ),title('Group Delay'); %Plot group delay disp 'Filter Coefficients. B = Numerator Coefficients A = Denominator Coefficients'; disp 'Poles = p Zeros = z Gain = k'; disp '----------------------------------------'; B A p z k