You are on page 1of 10

LAB 3:DifferenceEquations,z-Transforms,Pole-

ZeroDiagrams,BIBOStabilityandQuantizationEffects
Présenté à Dr Lise Safatly
Préparé par Christina Hachem
Exercice 1:
a. function y = diffeqn(a,x,yn1)
N = length(x);

y(1)=a*yn1+x(1);
for i=2:N
y(i)=a*y(i-1)+x(i);
end

end
b. >>a=1;
>> yn1=0;

>> x1=[1 zeros(1,30)];

>> y1=diffeqn(a,x1,yn1);

>>stem(y1);
>> ylabel('y1');
>> xlabel('n');
>> title('the response due to the unit impulse’);
>> x2=ones(1,31);

>> y2=diffeqn(a,x2,y1);

>> stem(y2);

>> ylabel('y2')

>> xlabel('n')

>> title('The response due to the unit step ')

c. >> yn1=-1;

>> x1=ones(1,31);

>>y1=diffeqn(a,x1,yn1);

>>x2=2*x1;

>>y2=diffeqn(a,x2,yn1);

>>stem(2*y1-y2);

>>ylabel('2*y1-y2');

>>xlabel('n');

>>title('Graph for 2*y1(n)-y2(n)


d. >> a=0.5;

>>x=ones(1,31)

>>yn1=0;

>>y1=diffeqn(a,x,yn1);

>>subplot(2,1,1);

>>stem(y1);

>>ylabel('y1');

>>xlabel('n');

>>title('The response due to the unit step with yn1=0’)

>>yn2=0.5;

>> y2=diffeqn(a,x,yn2);

>>subplot(2,1,2);

>> stem(y2);

>> ylabel('y2(n)’);

>> xlabel('n');

>> title('The response due to the unit step with yn1=0.5’)


The response converges to 2 faster when yn1 increases.

Exercice 2 :

a. >> b1=[1 -1 0]

>> a1=[1 3 2];

>> dpzplot(b1,a1);

>> title('poles and zeros of H(z)=(z^2-z)/(z^2+3z+2)');

>> xlabel('Re');

>> ylabel('Im');
Not stable.

b. >>b2=1;

>> a2=[1 1 0.5];

>> title('Poles and zeros of y(n)+y(n-1)+0.5y(n-2)=x(n)');

>> xlabel('Re');

>> ylabel('Im');

Stable.

c. >>b3=[1 0.5];

>>a3=[1 -1.25 0.75 -0.125];

>>dpzplot(b3,a3);

>>title('Poles and zeros of y(n)-1.25y(n-1)+0.5y(n-2)-0.125y(n-3)=x(n)+0.5x(n-1)');


>>xlabel('Re');

>>ylabel('Im');

Stable.

Exercice 3:

>> [b,a] = ellip(4,0.2,40,[0.41 0.47]);

>>[H,w] = freqz(b,a,4096);

>> plot(w/pi,20*log10(abs(H)));

>> axis([0 1 -80 10]);

>> title('Magnitude for frequency response');

>> xlabel('frequency');

>> ylabel('|H(w)|(dB)');

a. >> x=[1 zeros(1,4095)];

>>h=filter(b,a,x);

>>plot(h(1:200));
>>title('Impulse response of the filter without quantization (a,b)');

>>xlabel('frequency');

>>ylabel('|H(w)|');

The response converges to 0s it’s a stable filter.

b. >> M=max(abs([b a]));

>>a16=quant(a,16,M);

>>b16=quant(b,16,M);

>>[H16,w] = freqz(b16,a16,4096);

>>plot(w/pi,20*log10(abs(H16)));

>>axis([0 1 -80 10]);

>>title('Magnitude for frequency response of the quantized filter (b16,a16)');

>>xlabel('frequency');

>>ylabel('|H(w)|');
The quantization of the coefficients has affected the frequency response.

c. >>dpzplot(b16,a16);

>>title('Poles and zeros for (b16,a16)');

>>xlabel('Re');

>>ylabel('Im');

Stable since all the poles are inside the unity circle.

d. >>a12=quant(a,12,M);

>>b12=quant(b,12,M);

>>[H12,w] = freqz(b12,a12,4096);

>>plot(w/pi,20*log10(abs(H12)));

>>title('Magnitude for frequency response of the quantized filter (b12,a12)');

>>xlabel('frequency');

>>ylabel('|H(w)|');

>> dpzplot(b12,a12);

>>title('Poles and zeros for (b12,a12)');


>>xlabel('Re(z)');

>>ylabel('Im(z)');

Not causal and not stable.

>> dpzplot(b,a);

>>title('Poles and zeros for (b,a)');

>>xlabel('Re(z)');

>>ylabel('Im(z)');

Stable.

e. >> h12=filter(b12,a12,x);

>>plot(h12(1:200));

>>title('Impulse response of the filter after quantization (b12,a12)');

>>xlabel('frequency');
The response diverges so the filter is not stable.

You might also like