Exercise 4 F - ece.uwaterloo.caece413/HW/Solution3.pdf · plot the filtered output against the...

8
SOLUTIONS Exercise 1 University of Waterloo Department of Electrical and Computer Engineering ECE 413 – Digital Signal Processing Spring 2019 Home Assignment 3 Solution 1. Determine the value of D such as to make the filter suppress the drift and the interference noises simultaneously. We need D = 4 to supress both frequency components simultaneously. 2. Determine the value of b such that max -!<|H(e j! )| = 1. The magnitude response is maximized when its numerator is maximized and the denominator is minimized. In order to constrain the maximum magnitude response to be equal to 1, we get 1 = b 1+1 1+a = ) b = 1+a 2 . 3. Plot the zero-plot diagram and the frequency response of the filter for a =0.95 and a =0.98. Comment on your results. (a) a=0.95 (b) a=0.98

Transcript of Exercise 4 F - ece.uwaterloo.caece413/HW/Solution3.pdf · plot the filtered output against the...

SOLUTIONS

Exercise 1

University of WaterlooDepartment of Electrical and Computer EngineeringECE 413 – Digital Signal Processing

Spring 2019

Home Assignment №3

Due on July 5, 2019

Exercise 1

An ECG signal s[n] has been sampled at sampling frequency Fs = 200 Hz. The signal is knownto be contaminated by a baseline drift d[n] and a power line interference p[n]. Both the drift andthe interference signals may be assumed to be sinusoidal signals with fundamental frequencies 0.03Hz and 50 Hz, respectively. Our goal is to recover s[n] from its noisy measurement x[n], where

x[n] = s[n] + d[n] + p[n].

To this end, we are going to use a causal IIR filter with the following system function

H(z) =b(1 � z

�D)

1 � az�D,

where D is a positive integer and 0 ⌧ a < 1.

1. Determine the value of D such as to make the filter suppress the drift and the interferencenoises simultaneously.

2. Determine the value of b such that max�⇡!<⇡ |H(ej!)| = 1.

3. Plot the zero-plot diagram and the frequency response of the filter for a = 0.95 and a = 0.98.Comment on your results.

4. For both values of a above, apply the filter to the noisy data (sequence x in data1.mat) andplot the filtered output against the original ECG signal (sequence s in data1.mat). Howdoes the output change as a function of a? Are there any amplitude/phase distortions?

5. Let b and a be the feed-forward and feed-back coe�cients of filter H , respectively. A betterfiltering result can be produced by the following code:

y = flip( filter(b, a, flip( filter(b, a, x) ) ) ).

Plot the system function, magnitude response, and the impulse response of the above filter.Why does this filter perform better? Does it have any phase distortions, and, if not, why?

1

Exercise 4

An ECG signal s[n] has been sampled at sampling frequency Fs = 200 Hz. The signal is knownto be contaminated by a baseline drift d[n] and a power line interference p[n]. Both the drift andthe interference signals may be assumed to be sinusoidal signals with fundamental frequencies 0.03Hz and 50 Hz, respectively. Our goal is to recover s[n] from its noisy measurement x[n], where

x[n] = s[n] + d[n] + p[n].

To this end, we are going to use a causal IIR filter with the following system function

H(z) =b(1 � z

�D)

1 � az�D,

where D is a positive integer and 0 ⌧ a < 1.

Solution

1. Determine the value of D such as to make the filter suppress the drift and the interferencenoises simultaneously.

We need D = 4 to supress both frequency components simultaneously.

2. Determine the value of b such that max�⇡!<⇡ |H(ej!)| = 1.

The magnitude response is maximized when its numerator is maximized and the denominatoris minimized. In order to constrain the maximum magnitude response to be equal to 1, weget 1 = b

1+11+a

=) b = 1+a

2 .

3. Plot the zero-plot diagram and the frequency response of the filter for a = 0.95 and a = 0.98.Comment on your results.

(a) a=0.95 (b) a=0.98

7

Exercise 4

An ECG signal s[n] has been sampled at sampling frequency Fs = 200 Hz. The signal is knownto be contaminated by a baseline drift d[n] and a power line interference p[n]. Both the drift andthe interference signals may be assumed to be sinusoidal signals with fundamental frequencies 0.03Hz and 50 Hz, respectively. Our goal is to recover s[n] from its noisy measurement x[n], where

x[n] = s[n] + d[n] + p[n].

To this end, we are going to use a causal IIR filter with the following system function

H(z) =b(1 � z

�D)

1 � az�D,

where D is a positive integer and 0 ⌧ a < 1.

Solution

1. Determine the value of D such as to make the filter suppress the drift and the interferencenoises simultaneously.

We need D = 4 to supress both frequency components simultaneously.

2. Determine the value of b such that max�⇡!<⇡ |H(ej!)| = 1.

The magnitude response is maximized when its numerator is maximized and the denominatoris minimized. In order to constrain the maximum magnitude response to be equal to 1, weget 1 = b

1+11+a

=) b = 1+a

2 .

3. Plot the zero-plot diagram and the frequency response of the filter for a = 0.95 and a = 0.98.Comment on your results.

(a) a=0.95 (b) a=0.98

7

(c) a=0.95

(d) a=0.98 (Phase and Magnitude distortion is lesser than a=0.95)

Matlab Coder=0.98;b=[1 0 0 0 -1];a=[1 0 0 0 -r];c=(1+r)/2;w = linspace(-pi,pi);hz=freqz(b,a,w)plot(w/pi,abs(hz));plot(w/pi,angle(hz));figure,zplane(roots(b), roots(a));

8

(c) a=0.95

(d) a=0.98 (Phase and Magnitude distortion is lesser than a=0.95)

Matlab Coder=0.98;b=[1 0 0 0 -1];a=[1 0 0 0 -r];c=(1+r)/2;w = linspace(-pi,pi);hz=freqz(b,a,w)plot(w/pi,abs(hz));plot(w/pi,angle(hz));figure,zplane(roots(b), roots(a));

8

(c) a=0.95

(d) a=0.98 (Phase and Magnitude distortion is lesser than a=0.95)

Matlab Coder=0.98;b=[1 0 0 0 -1];a=[1 0 0 0 -r];c=(1+r)/2;w = linspace(-pi,pi);hz=freqz(b,a,w)plot(w/pi,abs(hz));plot(w/pi,angle(hz));figure,zplane(roots(b), roots(a));

8

4. For both values of a above, apply the filter to the noisy data (sequence x in data.mat) andplot the filtered output against the original ECG signal (sequence s in data.mat). Does theychange as a function of a? Are there any amplitude/phase distortions?

(a) a=0.95 (b) a=0.98

5. Let b and a be the feed-forward and feed-back coe�cients of filter H , respectively. A betterfiltering result can be produced by the following code:

y = flip( filter(b, a, flip( filter(b, a, x) ) ) ).

Plot the system function, magnitude response, and the impulse response of the above filter.Why does this filter perform better? Does it have any phase distortions, and, if not, why?

This filter presents better characteristic than the previous; the phase distortion that wasvisible in the first filter has been improved.

Matlab Coder=0.98;b=[1 0 0 0 -1];a=[1 0 0 0 -r];c=(1+r)/2;y1=c*filter(b,a,x);y2=c*flip(filter(b,a,flip(y1)));t=(0:n-1);plot(t,s,t,y1)plot(t,s,t,y2)

(a) filter in part (4) (b) filter in part (5)

9

4. For both values of a above, apply the filter to the noisy data (sequence x in data.mat) andplot the filtered output against the original ECG signal (sequence s in data.mat). Does theychange as a function of a? Are there any amplitude/phase distortions?

(a) a=0.95 (b) a=0.98

5. Let b and a be the feed-forward and feed-back coe�cients of filter H , respectively. A betterfiltering result can be produced by the following code:

y = flip( filter(b, a, flip( filter(b, a, x) ) ) ).

Plot the system function, magnitude response, and the impulse response of the above filter.Why does this filter perform better? Does it have any phase distortions, and, if not, why?

This filter presents better characteristic than the previous; the phase distortion that wasvisible in the first filter has been improved.

Matlab Coder=0.98;b=[1 0 0 0 -1];a=[1 0 0 0 -r];c=(1+r)/2;y1=c*filter(b,a,x);y2=c*flip(filter(b,a,flip(y1)));t=(0:n-1);plot(t,s,t,y1)plot(t,s,t,y2)

(a) filter in part (4) (b) filter in part (5)

9

4. For both values of a above, apply the filter to the noisy data (sequence x in data.mat) andplot the filtered output against the original ECG signal (sequence s in data.mat). Does theychange as a function of a? Are there any amplitude/phase distortions?

(a) a=0.95 (b) a=0.98

5. Let b and a be the feed-forward and feed-back coe�cients of filter H , respectively. A betterfiltering result can be produced by the following code:

y = flip( filter(b, a, flip( filter(b, a, x) ) ) ).

Plot the system function, magnitude response, and the impulse response of the above filter.Why does this filter perform better? Does it have any phase distortions, and, if not, why?

This filter presents better characteristic than the previous; the phase distortion that wasvisible in the first filter has been improved.

Matlab Coder=0.98;b=[1 0 0 0 -1];a=[1 0 0 0 -r];c=(1+r)/2;y1=c*filter(b,a,x);y2=c*flip(filter(b,a,flip(y1)));t=(0:n-1);plot(t,s,t,y1)plot(t,s,t,y2)

(a) filter in part (4) (b) filter in part (5)

9

Exercise 2

Exercise 5

Consider a causal system given by the system function:

H(z) =2 + 3.125z

�2

1 � 0.9z�1 + 0.81z�2.

Solution

1. Compute and plot the magnitude and phase responses of the system.

Frequency response: H(ej!) =2 + 3.125e�2j!

1� 0.9e�j! + 0.81e�2j!

=2 + 3.125cos(2!) + 3.125jsin(2!)

1� 0.9cos(!) + 0.81cos(2!) + j(0.9sin(!)� 0.81sin(2!))

Magnitude response: |H(ej!)| =p

(2 + 3.125cos(2!))2 + 3.1252sin2(2!)p(1� 0.9cos(!) + 0.81cos(2!))2 + (0.9sin(!)� 0.81sin(2!))2

Phase response: \H(ej!) = � tan�1 3.125sin(2!)

2 + 3.125cos(2!)� tan�1 0.9sin(!)� 0.81sin(2!)

1� 0.9cos(!) + 0.81cos(2!)

Matlab Codew = linspace(-pi,pi);hz=freqz([2 0 3.125],[1 -0.9 0.81],w);plot(w/pi,abs(hz));plot(w/pi,angle(hz));

2. Determine the minimum-phase system Hmin(z) corresponding to H(z) and plot its mag-nitude and phase responses.

H(z) = 21 + 25

16z�2

1� 0.9z�1 + 0.81z�2= 2

(1 + 54jz

�1)(1� 54jz

�1)

1� 0.9z�1 + 0.81z�2

Hmin(z) = 2⇥ 25

8⇥

(1 + 45jz

�1)(1� 45jz

�1)

1� 0.9z�1 + 0.81z�2=

3.125 + 2z�2

1� 0.9z�1 + 0.81z�2

10

Exercise 5

Consider a causal system given by the system function:

H(z) =2 + 3.125z

�2

1 � 0.9z�1 + 0.81z�2.

Solution

1. Compute and plot the magnitude and phase responses of the system.

Frequency response: H(ej!) =2 + 3.125e�2j!

1� 0.9e�j! + 0.81e�2j!

=2 + 3.125cos(2!) + 3.125jsin(2!)

1� 0.9cos(!) + 0.81cos(2!) + j(0.9sin(!)� 0.81sin(2!))

Magnitude response: |H(ej!)| =p

(2 + 3.125cos(2!))2 + 3.1252sin2(2!)p(1� 0.9cos(!) + 0.81cos(2!))2 + (0.9sin(!)� 0.81sin(2!))2

Phase response: \H(ej!) = � tan�1 3.125sin(2!)

2 + 3.125cos(2!)� tan�1 0.9sin(!)� 0.81sin(2!)

1� 0.9cos(!) + 0.81cos(2!)

Matlab Codew = linspace(-pi,pi);hz=freqz([2 0 3.125],[1 -0.9 0.81],w);plot(w/pi,abs(hz));plot(w/pi,angle(hz));

2. Determine the minimum-phase system Hmin(z) corresponding to H(z) and plot its mag-nitude and phase responses.

H(z) = 21 + 25

16z�2

1� 0.9z�1 + 0.81z�2= 2

(1 + 54jz

�1)(1� 54jz

�1)

1� 0.9z�1 + 0.81z�2

Hmin(z) = 2⇥ 25

8⇥

(1 + 45jz

�1)(1� 45jz

�1)

1� 0.9z�1 + 0.81z�2=

3.125 + 2z�2

1� 0.9z�1 + 0.81z�2

10

Matlab Codew = linspace(-pi,pi);hz=freqz([3.125 0 2],[1 -0.9 0.81],w);plot(w/pi,abs(hz));plot(w/pi,angle(hz));

3. Determine the equalizer system Heq(z) corresponding to H(z) and choose a gain G so thatthe overall system |H(z)Heq(z)| = 1. Plot the magnitude and phase responses of Heq(z).

Heq(z) =Gz

�nd

Hmin(z)

Choose G = 1 and nd = 0

Heq(z) =1

Hmin(z)=

1� 0.9z�1 + 0.81z�2

3.125 + 2z�2

Matlab Codew = linspace(-pi,pi);hz=freqz([1 -0.9 0.81],[2 0 3.125],w);plot(w/pi,abs(hz));plot(w/pi,angle(hz));

11

Matlab Codew = linspace(-pi,pi);hz=freqz([3.125 0 2],[1 -0.9 0.81],w);plot(w/pi,abs(hz));plot(w/pi,angle(hz));

3. Determine the equalizer system Heq(z) corresponding to H(z) and choose a gain G so thatthe overall system |H(z)Heq(z)| = 1. Plot the magnitude and phase responses of Heq(z).

Heq(z) =Gz

�nd

Hmin(z)

Choose G = 1 and nd = 0

Heq(z) =1

Hmin(z)=

1� 0.9z�1 + 0.81z�2

3.125 + 2z�2

Matlab Codew = linspace(-pi,pi);hz=freqz([1 -0.9 0.81],[2 0 3.125],w);plot(w/pi,abs(hz));plot(w/pi,angle(hz));

11

Matlab Codew = linspace(-pi,pi);hz=freqz([3.125 0 2],[1 -0.9 0.81],w);plot(w/pi,abs(hz));plot(w/pi,angle(hz));

3. Determine the equalizer system Heq(z) corresponding to H(z) and choose a gain G so thatthe overall system |H(z)Heq(z)| = 1. Plot the magnitude and phase responses of Heq(z).

Heq(z) =Gz

�nd

Hmin(z)

Choose G = 1 and nd = 0

Heq(z) =1

Hmin(z)=

1� 0.9z�1 + 0.81z�2

3.125 + 2z�2

Matlab Codew = linspace(-pi,pi);hz=freqz([1 -0.9 0.81],[2 0 3.125],w);plot(w/pi,abs(hz));plot(w/pi,angle(hz));

11

Exercise 3

Exercise 4

Exercise 5