You are on page 1of 19

DIGITAL SIGNAL PROCESSING 4.

4 Exercises:
a) Generation of unit impulse. Code:
k1 = -5; k2 = 10; k = k1:k2; x = (k==0); stem(k, x) xlabel('k') ylabel('\delta_k') title('Unit impulse sequence') axis([k1 k2 -0.1 1.1])

Output:

b) Generation of unit step.


Code: n=input ('Enter the length of the step sequence N='); % Get the length of the require sequence from the user t=0:n-1; y=ones(1,n); stem(t,y); ylabel ('Amplitude'); xlabel ('Time Index'); TITLE ('Unit Step Signal');

Output:

(for N=5)

c) Generation of sinusoidal sequence. Code:


n = 0:40; f = 0.1; phase = 0; A = 1.5; arg = 2*pi*f*n - phase; x = A*cos(arg); clf; % Clear old graph stem(n,x); % Plot the generated sequence axis([0 40 -2 2]); grid; title('Sinusoidal Sequence'); xlabel('Time index n'); ylabel('Amplitude'); axis;

Output:

d) Generation of random corrupted sequence.


Code: sig_length = 1001; sig = rand(1,sig_length); noise=[1.02].^20; p=sig+noise; plot(1:sig_length,p)

Output:

e) Generation of sinusoidal corrupted sequence.


Code: n = 0:40; f = 0.1; phase = 0; A = 1.5; arg = (((2*pi*n)/8)+(pi/8)); x = A*cos(arg); y=[1.02].^n;

p=x+y; clf; % Clear old graph stem(p,x); % Plot the generated sequence axis([0 40 -2 2]); grid; title('corrupted Sinusoidal Sequence'); xlabel('Time index n'); ylabel('Amplitude'); axis;

Output:

5.4 Exercises
a). Convolve a[n]=[-2 0 1 -1 3] and b[n]=[1 2 0 -1] CODE:
a=[-2, 0, 1 ,-1 ,3]; subplot(3,1,1) stem(a) title('Discrete signal a') b=[1,2,0,-1]; subplot(3,1,2) stem(b) title('Discrete signal b') ylabel('Amplitude') c=conv(a,b); subplot(3,1,3) stem(c) xlabel('[n]') title('The convulation result of a and b') OUTPUT

b).Convolve x[n]=exp(j*pi/13*m) and h[n]=[1 1] when the value of j=1 and m=1. CODE:
j=1 m=1 h=[1,1] subplot(3,1,1) stem(h) title('Discrete signal h') l=exp(j*pi/13*m) subplot(3,1,2) stem(l) title('Discrete signal l') o=conv(h,l) subplot(3,1,3) title('The convulation result of h and l') xlabel('n') stem(O)

OUTPUT

c).Compute cross correlation of two sequences given in part (a) CODE:


a=[-2, 0, 1 ,-1 ,3]; subplot(3,1,1) stem(a) title('Discrete signal a') b=[1,2,0,-1]; subplot(3,1,2) stem(b) title('Discrete signal b') ylabel('Amplitude') c=xcorr(a,b); subplot(3,1,3) stem(c) xlabel('[n]') title('The cross correlation result of a and b')

OUTPUT

d).Compute autocorrelation of any sequence CODE:


a=[-2, 0, 1 ,-1 ,3]; subplot(4,1,1) stem(a) grid; title('Discrete signal a') b=[1,2,0,-1]; subplot(4,1,2) stem(b) grid; title('Discrete signal b') ylabel('Amplitude') c=autocorr(a) subplot(4,1,3) stem(c) grid; xlabel('[n]') title('The autocorrelation result of a') c=autocorr(b) subplot(4,1,4) stem(c) grid; xlabel('[n]') title('The autocorrelation result of b')

OUTPUT

EXERCISE: 9.4
a) Write a MATLAB program to compute the first L samples of the inverse of a rational z-transform where the value of L is provided by the user through the command input.
Answer: L=input('Input the samples of the inverse transform: L= '); num = [2 5 9 5 3]; den = [5 45 2 1 1]; stem(impz(num,den,L)); title(['The inverse transform with Samples with ',num2str(L),'Samples']) xlabel('Time ')

Using this program, compute and plot the first 50 samples of the inverse of any G(z). Use the command stem for plotting the sequence generated by the inverse transform.
G(z) =4-9.3z-1 -0.66z-2-z-3-0.59z-4 1-0.95z-1+0.18z-2+0.66z-3-0.32z-4

b) Write a MATLAB program to determine the partial fraction expansion of a rational z-transform.
Answer: num = [2 5 9 5 3]; den = [5 45 2 1 1]; [r,p,k]=residuez(num,den); disp('r='),disp(r); disp('p='),disp(p); disp('k='),disp(k);

Using this program, determine the partial fraction expansion of any G(z) and then its inverse z-transform g[n] in closed form. Assume g[n] to be a causal sequence.
G(z) =4-9.3z-1 -0.66z-2-z-3-0.59z-4 1-0.95z-1+0.18z-2+0.66z-3-0.32z-4 The partial fraction expansion of G(z) is as follows: r= 0.3109-1.0254 - 0.3547i-1.0254 + 0.3547i-0.8601 p= -8.95760.1147 + 0.2627i0.1147 - 0.2627i-0.2718 k= 3.0000 The inverse z-transform g[n] from this partial fraction expansion is as follows: G(z)= 0.31 + 1-(-8.96)z-1 -1.03-0.35i 1-(0.11+0.26i)z-2 + -1.03+0.35i 1-(0.11-0.26i)z-3 + -0.86 +3 -4 1-(-0.27)z

EXERCISE# 7.4

Q. Prove the Linearity property of fourier transform. Linearity:

Q. Prove the Time shift property of fourier transform. Time shift:

Proof: Let

, i.e.,

, we have

Q. Prove the frequency shift property of fourier transform. Frequency shift:

Proof: Let

, i.e.,

, we have

Q. Prove the convolution property of Fourier transform. Convolution property:


The convolution theorem states that convolution in time domain corresponds to multiplication in frequency domain and vice versa:

Proof of (a):

Proof of (b):

Exercise 13.4
a- Create the GUI with buttons and axes for the following: Convolution: button for x[n], and a button for y[n] = x[n]*h[n]. Also show the figure of above three sequences in axes. OUTPUT:

Button 1 coding:
x =[-2 0 1 -1 3]; stem(x); axes(handles.axes1);

Button 2 coding:
h=[1 1 1]; stem(h); axes(handles.axes2);

Button 3 coding:
x =[-2 0 1 -1 3]; h=[1 1 1]; y=conv(x, h); stem(y); axes(handles.axes3);

Convolve x[n] and h[n] in frequency domain and show them using buttons and axes.

Button 1 coding:
x =[-2 0 1 -1 3]; x1=fft(x); plot(x1); axes(handles.axes1);

Button 2 coding:
h=[1 1 1]; h1=fft(h); plot(h1); axes(handles.axes2);

Button 3 coding:
x =[-2 0 1 -1 3]; h=[1 1 1]; y=(ifft(fft(h).*fft(x))); plot(y);

axes(handles.axes3);
Convolve x[n] and h[n] in z transform domain and show them in separate bottons and axes.

Button 1 coding:
x =[-2 0 1 -1 3]; x1=czt(x); plot(x1); axes(handles.axes1);

Button 2 coding:
h=[1 1 1]; h1=czt(h); plot(h1); axes(handles.axes2);

Button 3 coding:
x =[-2 0 1 -1 3];

h=[1 1 1]; y=conv(x, h); z=czt(y); plot(z); axes(handles.axes3);

You might also like