Você está na página 1de 9

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?

0.8

0.6

0.4

0.2

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

-2

-4
-4 -3 -2 -1 0 1 2 3 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?


f = ω /( 2π ) = fTs = f / f s
- 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

DSP Assignment 4
PHAN ANH HUNG S3219592

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');

0.8

0.6

0.4

0.2

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

Impulse Response
0.1

0.05
Amplitude

-0.05

-0.1
0 5 10 15 20 25
Time (sec)

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 k }={1,-2,1, -1} and
the input sequence is

DSP Assignment 4
PHAN ANH HUNG S3219592

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

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

3. For the FIR filter with coefficients {b k }={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)
title('xx')

DSP Assignment 4
PHAN ANH HUNG S3219592

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

xx
5
x[n]

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

5
y[n]

-5
0 5 10 15 20 25 30 35 40 45 50
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 −1 y[z] + 0.3z −2 y[z] - x[z] + 3 z −3 x[z] – 2z −2 x[z]

DSP Assignment 4
PHAN ANH HUNG S3219592

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

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

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


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]


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

DSP Assignment 4
PHAN ANH HUNG S3219592

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


1 z
H(z) = =
1 + 1/2z -1
z +1 / 2

- What are its poles and zeros?


Zero = 0 , Pole = -1/2

0.8

0.6

0.4
Imaginary Part

0.2

-0.2

-0.4

-0.6

-0.8

-1

-1 -0.5 0 0.5 1
Real Part

- 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] = 1


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

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

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

DSP Assignment 4
PHAN ANH HUNG S3219592

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 z −1 ) Y(z) = X(z)
1 z
H(z) = -1 =
1 + 0.9z z + 0.9

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

0.8

0.6

0.4
Imaginary Part

0.2

-0.2

-0.4

-0.6

-0.8

-1

-1 -0.5 0 0.5 1
Real Part

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.

fc=200;
fs=1000;

DSP Assignment 4
PHAN ANH HUNG S3219592

[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')

0.08

0.07

0.06

0.05

0.04

0.03

0.02

0.01

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

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 given
below.

Filter Implementation FIR


Pass band ripple 0.5dB
Stop band attenuation 25dB
Stop band edge frequencies 900 Hz – 1100Hz
Pass band 990Hz – 1010Hz
Sampling frequency 8 KHz

DSP Assignment 4
PHAN ANH HUNG S3219592

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.

M
y[n] = ∑bk × x[n − k ]
K =0

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

DSP Assignment 4

Você também pode gostar