EE422

Solution to Homework #24

1a)

Response of analog filter:

i)

ii)

iii)

b)

For the low pass filter in part a), design a digital filter H(z) with Ts=10 msec using the following techniques:

i)

Impulse Invariant Design(the correct way, unlike the book!!):

ii)

Step Invariant Design:

iii)

Bilinear Transformation:

c) Matlab Code to obtain the plots:

» T=0.01;

» w=1/T*[1 zeros(1,100];

» w=1/T*[1 zeros(1,100)];

» w_impulse=1/T*[1 zeros(1,100)];

» w_step=ones(1,101);

» t=[0:T:1];

» w_exponential=exp(-4*t);

» num_impulse=5*T;

» den_impulse=[1 -exp(-0.04)];

» num_step=5/4*(1-exp(-0.04))*[0 1];

» den_step=[1 -exp(-0.04)];

» num_bilinear=5/204*[1 1];

» den_bilinear=[1 -196/204];

» y_impulse_impulse=filter(num_impulse,den_impulse,w_impulse);

» y_impulse_step=filter(num_impulse,den_impulse,w_step);

» y_impulse_exponential=filter(num_impulse,den_impulse,w_exponential);

» y_step_impulse=filter(num_step,den_step,w_impulse);

» y_step_step=filter(num_step,den_step,w_step);

» y_step_exponential=filter(num_step,den_step,w_exponential);

» y_bilinear_impulse=filter(num_bilinear,den_bilinear,w_impulse);

» y_bilinear_step=filter(num_bilinear,den_bilinear,w_step);

» y_bilinear_exponential=filter(num_bilinear,den_bilinear,w_exponential);

» y_analog_impulse=5*exp(-4*t);

» y_analog_step=5/4*(1-exp(-4*t));

» y_analog_exponential=5*t.*(exp(-4*t));

» plot(t,y_impulse_impulse,'o',t,y_step_impulse,'*',t,y_bilinear_impulse,'x',t,y_analog_impulse)

» grid,title('EE422 - Response of 3 digital and analog filters to impulse')

» plot(t,y_impulse_step,'o',t,y_step_step,'*',t,y_bilinear_step,'x',t,y_analog_step)

» grid,title('EE422 - Response of 3 digital and analog filters to step')

» plot(t,y_impulse_exponential,'o',t,y_step_exponential,'*',t,y_bilinear_exponential,'x',t,y_analog_exponential)

» grid,title('EE422 - Response of 3 digital and analog filters to exp(-4t)')

»

Plots:

As expected, the impulse invariant design response agrees exactly with the analog filter when the input is an impulse and similarly, the step invariant design response agrees exactly with the analog filter when the input is a step. The bilinear transformation does well when the analog response is relatively smooth.

Just out of curiousity, I designed the low pass digital filter using an discrete impulse instaed of 1/T times a discrete impulse. If you do this, your response will be off by a factor of T (see below) and this is why the book suggests that in the invariant design procedure you need to multiply by T. Of course, this trick will only work for the impulse invariant design and will result in designs which are scaled by an unwanted factor of T if you try to use any other input other than an impulse!

 

 

2a)

Phase Variables:

Draw simulation diagram:

 

2b)

2c)

2d)

For the digital low-pass filter designed using the bilinear transformation,

b0=5/204

b1=5/204

a0=1

a1= -196/204

2e)

#include <stdio.h>

#include <stdio.h>

#include <math.h>

main(){

int temp;

float a0,a1,b0,b1,yk,yk_minus_1,wk,wk_minus_1;

yk=0.0; /*Initialize values */

yk_minus_1=0.0;

wk=0.0;

wk_minus_1=0.0;

b0=5/204 ;

b1=5/204 ;

a0=1 ;

a1= -196/204 ;

while(1){ /*Loop forever*/

temp=in(); /*Store A/D encoded value temporarily in temp*/

wk=(float)(wtemp/204.8)-10; /*Convert encoded input to floating pt. number*/

yk=1/a0*(b0*wk+b1*wk_minus_1-a1*yk_minus_1); /*Form the equation for yk*/

temp=(int)204.8*(yk+10) /*Convert yk to encoded number and store in temp*/

out(temp); /*Output encoded value*/

wk_minus_1= wk ; /*Store new values in old variables*/

yk_minus_1= yk ; /*Store new values in old variables*/

sleep( 2 ); /*We have 8 statements so delay 2 msec to get Ts=10 msec*/

}

}

#include <math.h>main(){int temp;float a0,a1,b0,b1,yk,yk_minus_1,wk,wk_minus_1;

/*Initialize values */

yk=0.0;

yk_minus_1=0.0;

wk=0;

wk_minus_1=0;

b0=5/204;

b1=5/204;

a0=1;

a1=-196/204;

while(1){

yk=1/a0*(b1*(wk_minus_1-a1*yk_minus_1) /*Form a partial sum for yk*/

temp=in(); /*Store A/D encoded value temporarily in temp*/

wk=(float)(wtemp/204.8)-10; /*Convert encoded input to floating pt. number*/

yk=yk+1/ao*(bo*wk); /*Complete the equation for yk*/

temp=(int)204.8*(yk+10) /*Convert yk to encoded number and store in temp*/

out(temp); /*Output encoded value*/

wk_minus_1=wk; /*Store new values in old variables*/

yk_minus_1=yk; /*Store new values in old variables*/

sleep(2); /*We have 8 statements so delay 2 msec to get Ts=10 msec*/

}

}