dsp major

12
PHAN ANH HUNG S3219592 Digital Signal Processing Assessment 4 1. Type the following Matlab code and save it as an m file. bb= 1/3 * ones (1 ,3); ww = -pi: (pi/200) : pi; H = freqz (bb, 1, ww ); subplot (2, 1, 1) plot (ww, abs(H)) subplot(2,1,2) plot(ww,angle(H) ) xlabel (‘Normalized Frequency’) - Run the above Matlab program. What does it plot? -4 -3 -2 -1 0 1 2 3 4 0 0.2 0.4 0.6 0.8 1 -4 -3 -2 -1 0 1 2 3 4 -4 -2 0 2 4 Norm alized Frequency - What is the function ‘freqz’ used for? DSP Assignment 4

Upload: phan-anh-hung

Post on 22-Nov-2014

120 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: DSP major

PHAN ANH HUNG S3219592

Digital Signal ProcessingAssessment 4

1. Type the following Matlab code and save it as an m file.

bb= 1/3 * ones (1 ,3);ww = -pi: (pi/200) : pi;H = freqz (bb, 1, ww );subplot (2, 1, 1)plot (ww, abs(H))subplot(2,1,2)plot(ww,angle(H) )xlabel (‘Normalized Frequency’)

- Run the above Matlab program. What does it plot?

-4 -3 -2 -1 0 1 2 3 40

0.2

0.4

0.6

0.8

1

-4 -3 -2 -1 0 1 2 3 4-4

-2

0

2

4

Normalized Frequency

- What is the function ‘freqz’ used for?h = frequz (bb, 1, ww) returns the frequency response vector h calculated at the frequencies supplied by the vector ww. The vector ww can have any length.

- What do you mean by Normalized frequency?

DSP Assignment 4

Page 2: DSP major

PHAN ANH HUNG S3219592

- The frequency distribution is periodic with period, when the actual frequency has units of hertz (SI units), the normalized frequencies, also denoted by have units of cycles per sample, and the periodicity of the normalized distribution is 1.  And when the actual frequency has units of radians per second (angular frequency), the normalized frequencies have units of radians per sample, and the periodicity of the distribution is 2п.

- Modify the program to get the impulse response (h) from the frequency response and plot it.

bb= 1/3 * ones (1, 3);ww = -pi: (pi/200) : pi;H = freqz (bb, 1, ww );subplot (2, 1, 1)plot (ww, abs(H))subplot(2,1,2)plot(ww,angle(H) )xlabel ('Normalized Frequency')sys = rss(2);H = impulseplot(sys);setoptions(h,'normalize','on');

-4 -3 -2 -1 0 1 2 3 40

0.2

0.4

0.6

0.8

1

0 5 10 15 20 25-0.1

-0.05

0

0.05

0.1Impulse Response

Time (sec)

Am

plitu

de

2. Draw the block diagram of 3rd order FIR filter. Write the difference equation for the filter and find out the output y[n] of the filter when the filter coefficients are {b }={1,-2,1, -1} and the input sequence is

DSP Assignment 4

Page 3: DSP major

PHAN ANH HUNG S3219592

x[n]= [1,2,1,3,4,5,2,1,3]

N 0 1 2 3 4 5 6 7 8X[n] 1 2 1 3 4 5 2 1 3Y[n] 1 0 -2 2 -3 -1 -7 -10 -2

3. For the FIR filter with coefficients {b }={1,2,1}, find the output of the filter y[n] when the input is

x[n] = 4 + 3 cos[(pi/3 )n – ( pi/2)] + 3cos[(20*pi/21)n]

>> n = 0:7;>> x = 4+3*cos((pi/3)*n-(pi/2))+3*cos((20*pi/21)*n);>> bb = [1,2,1];>> conv(bb,x) ans =7.0000 17.6316 23.7280 23.8583 15.9396 8.2611 8.1566 16.0418 16.0666 5.0981

4. Generate 50 samples of a discrete time cosine wave with A= 5,

=pi/4, =0.125pi. Store this signal in the vector xx so it can be used in succeeding parts. Now use filter( ) or filtfilt( ) to implement the following filter with the signal xx as input.

y[n] = 2x[n]-2x[n-1]The above equation is called a first difference equation filter, but with a gain of 5. In Matlab you must define the vector bb required for filter.

- Plot the first 50 samples of both waveforms x[n] and y[n] on the same figure using subplot. Use the stem function to make a discrete time plot.n = 0:49;xx = 5*cos(0.125*pi*n+pi/4);y = filter([2 -2], 1, xx);subplot(2,1,1)stem(xx)

DSP Assignment 4

Page 4: DSP major

PHAN ANH HUNG S3219592

title('xx')xlabel('n')ylabel('x[n]')subplot(2,1,2)stem(y)title('y')xlabel('n')ylabel('y[n]')

0 5 10 15 20 25 30 35 40 45 50-5

0

5xx

n

x[n]

0 5 10 15 20 25 30 35 40 45 50-5

0

5

10y

n

y[n]

- Verify the amplitude and phase of x[n] directly from its plot in the time domain.- Determine the frequency, amplitude and phase of y[n] directly from the plot.

Frequency = 1/16 Amplitude = /4 Phase = 3.83

5. Draw the block diagram of the Direct Form I difference equation given below.

y[n]=0.5 y[n-1] + 0.3 y[n-2] - x[n] + 3x[n-1] – 2x[n-2]

- Find the system function H(z) for the above filter.

V[n] = - x[n] + 3x[n-1] – 2x[n-2]

Y[n] = 0.5 y[n-1] + 0.3 y[n-2] + V[n]

y[z]=0.5z y[z] + 0.3z y[z] - x[z] + 3 z x[z] – 2z x[z]

DSP Assignment 4

Page 5: DSP major

PHAN ANH HUNG S3219592

y[z]- 0.5 z y[z] - 0.3 z y[z] = - x[z] + 3 z x[z] – 2z x[z]

y[z] (1- 0.5z + 0.3z ) = x[z] (-1 + 3 z – 2z )

H(z) = y(z) / x(z) = (-1 + 3 z – 2z ) / (1- 0.5z + 0.3z )Block Diagram

In hard copy

- What kind of filter does the above equation represent and why?This is a 2nd – order IIP system, because ‘– 2x [n-2]’ is given in the equation.- Where do the poles and zeros for the above equation lie. Show the pole-zero plot on a unit circle.- Write the equation for the impulse response h[n] and derive the coefficients for the impulse response. Plot h[n] versus n and show that the impulse response never reaches zero(is infinite).

6. Given an IIR filter defined by the difference equation

y[n]= -1/2y[n-1] + x[n]

- Determine the system function H(z).

y[n] = -1/2y[n-1] + x[n]

DSP Assignment 4

Page 6: DSP major

PHAN ANH HUNG S3219592

Y(z) =-1/2 Y(z) + X(z)Y(z) + 1/2 Y(z) = X(z)(1 + 1/2 ) Y(z) = X(z)

H(z) = =

- What are its poles and zeros? Zero = 0 , Pole = -1/2

-1 -0.5 0 0.5 1

-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Real Part

Imag

inar

y P

art

- When the input to the system is x[n] = [n] + [n-1] + [n-2]

determine the output signal y[n]. Assume that y[n] is zero for n<0.

x[0] = [0] + [ -1] + [ -2] = 1x[1] = [1] + [ 0 ] + [ -1] = 1x[2] = [2] + [ 1 ] + [ 0 ] = 1x[3] = [3] + [ 2 ] + [ 1 ] = 1

y[0] = -1/2y[-1] + x[ 0 ] = 1y[1] = -1/2y[ 0 ] + x[ 1 ] = 1/2y[2] = -1/2y[ 1 ] + x[ 2 ] = 3/4y[3] = -1/2y[ 2 ] + x[ 3 ] = -3/8y[n] = (-1/2) y[2] for n ≥ 3

N -1 0 1 2 3

DSP Assignment 4

Page 7: DSP major

PHAN ANH HUNG S3219592

X[n] 0 1 1 1 0Y[n] 0 1 1/2 3/4 -3/8

7. Given an IIR filter defined by the difference equation y[n] = -0.9y[n-6] + x[n]

- Find the z transform system function for the system.y[n] = -0.9y[n-6] + x[n](1+0.9 ) Y(z) = X(z)

H(z) = =

- Find the poles of the system and plot their location in the z plane. Zero = 0 and Pole = -0.9

-1 -0.5 0 0.5 1

-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Real Part

Imag

inar

y P

art

8. Design a Low Pass Filter using Matlab for a signal sampled at 1000 Hz using Butterworth algorithm with the following specifications.

- Cut off frequency = 200Hz- Linear Phase Filter (FIR) of the order = 4- Plot the absolute value of the frequency response.- Plot the magnitude and the phase response of the filter.- Plot the impulse response of the filter.

DSP Assignment 4

Page 8: DSP major

PHAN ANH HUNG S3219592

fc=200;fs=1000;[bb]=butter(4,fc/fs,'low');w=-pi:(pi/50):pi;xx=0:1:10;H=freqz(bb,1,w);[G,T]=impz(b,1,xx);sys=H;plot(w,abs(H));x label('absolute value')fvtool(bb)x label ('magnitude and phase response')

-4 -3 -2 -1 0 1 2 3 40

0.01

0.02

0.03

0.04

0.05

0.06

0.07

0.08

9. What are the advantages of IIR filter over FIR filter? Describe the applications of these two types of filters?

IIR filters can achieve a given filtering characteristic using less memory and calculations than a similar FIR filter.

10. Design an FIR filter. The specifications for this filter are givenbelow.

Filter Implementation FIRPass band ripple 0.5dBStop band attenuation 25dBStop band edge frequencies 900 Hz – 1100Hz

DSP Assignment 4

Page 9: DSP major

PHAN ANH HUNG S3219592

Pass band 990Hz – 1010HzSampling frequency 8 KHz

Use MATLAB (Filter Design Toolbox) to - Calculate the filter coefficients and plot the frequency response for the above filter.- Generate three sine waves of the same amplitude (2Vp-p) but different frequencies of 500Hz, 1KHz and 2KHz. - Create a fourth composite signal by adding the three sine waves and plot all the signals in Matlab- Sample the fourth composite signal and export the samples to the DSP Processor.

Implement the above designed FIR filter using DSP56803 processor. Using the following equation and the filter coefficients, filter the composite signal and store the samples of the output signal in another array in the DSP Processor. Export the output signal to Matlab and plot the signal to observe the frequency of the signal.

Where M is the order of the filter, y[n] is the output of the FIR filter, x[n] is the input, b are the filter coefficients.

DSP Assignment 4