%% L14_Filter_Structure %% ====================== %% Script to illustrate and compare filter implementation with %% Matlab and Simulink. %% %% Compare with output from demo Simulink file "fxpdemo_direct_form2", %% which shows the direct-form II implementation. %% %% Created : 29 Aug 2005 %% Modified : 29 Aug 2005 %% %% Copyright (c) 2005 Salman Durrani . %% ------------------------------------------------------------ clc clear all close all %% Filter Coeffs (See Lecture 14) num=[1 2.2 1.85 0.5]; den=[1 -0.5 0.84 0.09]; %% Square wave frequency (Hz) f = 0.005; %% Time vector t = [0:1:200]; %% Create a square wave of unit amplitude and frequency f x = -1.*square(2*pi*f*t); %% Filtered signal y=filter(num,den,x); %% Plot results figure plot(t,x,'k') hold on plot(t,y,'b') xlabel('Time (s)'); ylabel('Amplitude') axis([0 Inf -8 10]) legend('input','output') grid on