Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
DSP LABORATORY REPORT NAME USN SEM/BRANCH : : : VENKATARAGHAVAN.T 1CR07TE057 5th SEM, TCE
LABORATORY CERTIFICATE
This is to certify that Mr.VENKATARAGHAVAN.T bearing USN 1CR07TE057 has satisfactorily completed the course of experiments in DIGITAL SIGNAL PROCESSING Laboratory(06ECL57) prescribed by the VTU for 5th semester BE TELECOMUNICATION course in the laboratory of this college in the year 2008 2009.
DATE:
Signature of HOD
(Mrs.Pakia Rani)
1C
CONTENTS
I. Verification of Sampling Theorem....1 II. Impulse Response of a given system.......3 III. Calculation of N Point DFT ..5 IV. Linear Convolution of two given finite length sequences.............9 V. Circular convolution of two given finite length sequences.......11 VI. Linear convolution of two given finite length sequences
using DFT-IDFT method............................................................13 using DFT-IDFT method...........................................................16
MATLAB Programs
VIII. Calculate Auto Correlation and verify its Properties ............19 IX. Calculate Cross Correlation...21 X. Solve a given Difference Equation23 XI. Realization of IIR filters ...25 XII. Realization of FIR filters...32
QUESTION BANK
MATLAB PROGRAMS
1. Write a MATLAB program to verify the sampling theorem for the following three cases Right sampling Under sampling Over sampling 2. Write a MATLAB program to determine the impulse response of the given system whose difference equation is given by: y (n) y (n-1) + 1/8 y (n-2) = x (n) 1/3 x (n-1). 3. Write a MATLAB program to compute the N-Point DFT of the sequence x(n) = {1,1,1,1} taking N=4 and N=8. 4. Write a MATLAB program to perform the linear convolution of the sequences given x1(n) = {1, 2, 3, 4, 5} x2(n) = {2, 3, 4} 5. Write a MATLAB program to perform circular convolution of the given sequences x1(n) = {1, 2, 3, 4} and x2(n) = {4, 3, 2, 2} 6. Write a MATLAB program to perform linear convolution of the given sequences x1(n) = {2, 3, 4, 0} x2(n) = {2, 1, 0, 0} by using DFT and IDFT method. 7. Write a MATLAB program to perform circular convolution of the given sequences x1(n) = {1, 2, 3, 4} x2(n) = {4, 3, 2, 2} by using DFT and IDFT method. 8. Write a MATLAB program to compute the autocorrelation of the given sequence and verify its properties. X = {1, 2, 3, 6, 2, 4} 9. Write a MATLAB program to find the cross correlation of the given two sequences x = {1, 2, 4, 6, 5} and y = {1, 3, 2, 1, 4}
10. Write a MATLAB program to solve the given difference equation y (n) 3/2 y (n-1) + y (n-2) = x (n). Given x(n) = (1/4)n y(n). Assume initial conditions as y(-1) = 4,y(-2) = 10.
11. Using MATLAB design an IIR filter with pass band edge frequency at 1500Hz and stop band edge at 2000Hz for a sampling frequency of 8000Hz.passband attenuation is 1dB and stop band attenuation is 15dB. Use butter worth prototype design and bilinear transformation. 12. Using MATLAB design an FIR filter with pass band edge frequency at 1500Hz and stop band edge at 2000Hz for a sampling frequency of 8000Hz.passband attenuation is 1dB and stop band attenuation is 15dB. Use chebyshev prototype design and bilinear transformation. PART B Code Composer Studio Programs 1. Find out the Discrete Time Convolution of the sequences x(n)={1 2 3 4 5 6} and h(n)={1 2 3 4}, using Code Composer Studio. Verify the results graphically. 2. Perform Circular Convolution of the given sequence using Code Composer Studio. 3. Compute the response of the system whose co-efficients are a0=0.1311, a1=0.2622, a2=0.1311 and b0=1, b1= -0.7478, b2=0.2722, when the input is a unit impulse signal. 4. Compute the DFT of an N Point sequence from a lookup table.
PROGRAM 1:
PROBLEM:
Using MATLAB, sample a band limited continuous time signal, band limited to fm=400Hz under the following conditions: 1. Nyquist rate 2. Under sampling 3. Over sampling
MATLAB CODE:
s=800; t=0:1/ s:256/ s; X=sin(2*pi*400*t); Xm=abs(fft(X)); K=0:length(X)-1; Subplot(2,2,1); Stem(k,Xm); xlabel(Hz); ylabel(Magnitude); title(Nyquist Rate Sampling);
s=200; t=0:1/ s:256/ s; X=sin(2*pi*400*t); Xm=abs(fft(X)); K=0:length(X)-1; Subplot(2,2,2); Stem(k,Xm); xlabel(Hz); ylabel(Magnitude); title(Under Sampling); s=1000; t=0:1/ s:256/ s; X=sin(2*pi*400*t); Xm=abs(fft(X)); K=0:length(X)-1; Subplot(2,2,3); Stem(k,Xm); xlabel(Hz); ylabel(Magnitude); title(Over Sampling); OUTPUT:
PROGRAM 2:
PROBLEM:
Obtain the Impulse response of a system described by the difference equationy(n)-3/4 y(n-1)+1/8 y(n-2) = x(n)-1/3 x(n-1) Solution: Y(z) - 3/4 Y(z)z-1 + 1/8 Y(z)z-2 = X(z) - 1/3 X(z) z-1 H(z) = Y(z) / X (z) = (1-1/3 z-1) / (1-3/4 z-1+1/8 z-2) Applying partial fractions , H (z) = (1-1/3 z-1) / (1-1/2 z-1)(1-1/4 z-1) = A / (1-1/2 z-1) + B / (1-1/4 z-1) A=2/3; B=1/3; H(z) = (2/3) / (1-1/2 z-1) + (1/3) / (1-1/4 z-1) h(n) = (2/3) (1/2)n u(n) + (1/3) (1/4)n u(n) h(0)=1 h(1)=0.416 h(2)=0.187 h(3)=0.088 h(4)=0.0429 h(5)=0.02116 h(6)=0.0105 h(7)=0.0052 h(8)=0.0026 h(9)=0.0013
MATLAB CODE:
N=input('enter the length of impulse response'); b=input('enter the numerator coeff'); a=input('enter the denominator coeff'); [r,p,k]=residuez(b,a) [h,t]=impz(b,a,N) stem(t,h); grid; xlabel('time index'); ylabel('amplitude'); title('impulse response');
INPUT:
enter the length of impulse response 5
enter the numerator coeff [1 -1/3] enter the denominator coeff [1 -3/4 1/8]
OUTPUT:
r= 0.6667 0.3333 p= 0.5000 0.2500 k= [] h= 1.0000 0.4167 0.1875 0.0885 0.0430 0.0212
PROGRAM 3:
PROBLEM:
Obtain the N point- dft of the sequence x (n) = {1 1 1 1} Case1: With N=4 Solution: 1 1 1 1 1 -j -1 j 1 -1 1 -1 1 j -1 -j 1 1 = 1 1 0 0 4 0
MATLAB CODE:
x1=input('enter the sequence X1='); N=input('enter the value of N='); xk=fft(x1,N) subplot(2,2,1); n=0:1:length(xk)-1; stem(n,abs(xk)); disp(abs(xk)); xlabel('time index');
ylabel('amplitude'); title('magnitude plot'); subplot(2,2,2); stem(n,angle(xk)); disp(angle(xk)); xlabel('time index'); ylabel('amplitude'); title('angle plot'); xk1=ifft(xk,N) subplot(2,2,3); stem(n,(xk1)); xlabel('time index'); ylabel('amplitude'); title('inverse fourier transform'); Case2: With N=8 1 0 W 20
W2 0 -1 W2 0 -1
1 -1 1 W40 -1 1 W41 1 -1 -1
4 1j2.414 0 1-j0.414 W8 W8
1
1 W 20
W2 0 W2 0
-1 0 -1 1+j0.414 -1
3
W20 1 0 1 0 -1 W20 -1 1 1 1 1 -1 -1
W8
0 1+j2.414
W41
1 + j W8
-1
INPUT:
Case1: enter the sequence X1=[1 1 1 1] enter the value of N=5 Case2: enter the sequence X1=[1 1 1 1] enter the value of N=8
OUTPUT:
Case1: xk = 4 0 4 0 0 0 0 0 0 0 0 0
GRAPH:
Columns 6 through 8 1.0000 + 0.4142i 4.0000 2.6131 0 1.0000 + 2.4142i 0 0 1.0824 0.3927 0 0 2.6131 1.1781
0 1.0824 0 -0.3927
0 -1.1781
GRAPH:
PROGRAM 4:
The output using the convolution operation, is: y(t) = x(t) * h(t) The asterisk operator means convolution. LINEAR CONVOLUTION: Let x1(n) be the input sequence and h(n) be the impulse response of the system as shown below.i.e y(n)=x1(n)*h(n) where y(n) is the output sequence. X1(n) h(n) y(n)
Solution: 1 2 3 4 2 4 6 8 3 6 9 12 4 8 12 16 5 10 15 20
2 3 4
MATLAB CODE:
X1=input('First Sequence'); X2=input('Second Sequence'); subplot(2,2,1); n1=0:1:length(X1)-1; stem(n1,X1); xlabel('Time'); ylabel('Amplitude'); title('First sequence'); subplot(2,2,2); n2=0:1:length(X2)-1; stem(n2,X2); xlabel('Time'); Department of Telecommunication CMRIT 9
ylabel('Amplitude'); title('Second Sequence'); Y=conv(X1,X2) subplot(2,2,3); n3=0:1:length(Y)-1; stem(n3,Y); xlabel('Time'); ylabel('Amplitude'); title('Linear Convolution Output');
INPUT:
first sequence=[1 2 3 4 5] second sequence=[2 3 4]
OUTPUT:
Y= 2 7 16 25 34 31 20
GRAPH:
10
Circular Convolution
THEORY:
A circular convolution of two functions is defined in terms of the periodic extension of one or both functions. Periodic extension means a new function is formed by shifting the original function by multiples of some period, T, and adding all the copies together.
PROGRAM 5:
PROBLEM:
For a given two sequences x(n) and h(n) compute the circular convolution. Solution: Finding Circular convolution using Matrix method: 1 2 Y= 3 4 4 1 2 3 3 4 1 2 2 3 4 1 4 3 2 2 = 26 25 28 31
MATLAB CODE:
x=input('Enter the sequence x(n) '); h=input('Enter the sequence h(h) '); N1=length(x); N2=length(h); N=max(N1,N2); N3=N1N2; if(N3>0) h=[h zeros(1,N3)]; else x=[x zeros(1,N3);]; end disp('Sequence x(n) '); disp(x); disp('Sequence h(n) '); disp(h); n=1:N; disp(n); y=0; for m=1:N disp(m); y=y+x(m)*h(mod(n-m,N)+1)
11
end disp('circular covolution'); disp(y); subplot(2,2,1); stem(n,x); title('Sequence x(n)'); xlabel('n'); ylabel('Amplitude'); subplot(2,2,2); stem(n,h); title('Sequence h(n)'); xlabel('n'); ylabel('Amplitude'); subplot(2,2,3); stem(n,y); title('Sequence y(n)'); xlabel('n'); ylabel('Amplitude');
INPUT:
Enter the sequence x(n) [1 2 3 4] Enter the sequence h(h) [4 3 2 2]
OUTPUT:
y= 26 25 28 3
12
PROGRAM 6:
PROBLEM:
Linear convolution using DFT IDFT method. Solution: Finding the DFT of the two input sequences: 1 1 X1 = 1 1 1 1 X2 = 1 1 1 -j -1 j 1 -j -1 j 1 -1 1 -1 1 -1 1 -1 1 j -1 -j 1 j -1 -j 2 3 4 0 2 1 0 0 = = 9 -2-3j 4 -2+3j 3 2-j 1 2+j
1 1 Y= 1 1
1 j -1 -j
1 -1 1 -1
1 -j -1 j
27 -7-4j 3 -7+4j =
16 32 44 16
MATLAB CODE:
x1=input('Enter the sequence x1(n) '); x2=input('Enter the sequence x2(n) '); N1=length(x1); N2=length(x2); N3=N1+N2-1; if (N3>N2) x2=[x2 zeros(1,N3-N2)]; end if (N3>N1) x1=[x1 zeros(1,N3-N1)]; end X1=fft(x1,N3) X2=fft(x2,N3) Y=X1.*X2; y=ifft(Y,N3) subplot(3,1,1); n1=0:1:length(x1)-1; stem(n1,x1); xlabel('Time'); ylabel('Amplitude'); title('First Sequence'); subplot(3,1,2); n2=0:1:length(x2)-1; stem(n2,x2); xlabel('Time'); ylabel('Amplitude'); title('Second Sequence'); subplot(3,1,3); n=0:1:length(y)-1; stem(n,y); xlabel('Time');
14
INPUT:
Enter the sequence x1(n) [2 3 4 0] Enter the sequence x2(n) [2 1 0 0]
OUTPUT:
X1 = Columns 1 through 5 9.0000 2.9804 - 6.2452i -2.2714 - 1.1892i 1.7911 + 1.8257i 1.7911 - 1.8257i Columns 6 through 7 -2.2714 + 1.1892i 2.9804 + 6.2452i X2 = Columns 1 through 5 3.0000 2.6235 - 0.7818i 1.7775 - 0.9749i 1.0990 - 0.4339i 1.0990 + 0.4339i Columns 6 through 7 1.7775 + 0.9749i 2.6235 + 0.7818i y= 4.0000 8.0000 11.0000 4.0000 0.0000 0.0000 0.0000
15
PROGRAM 7:
PROBLEM:
Write a MatLab program to compute the circular convolution using DFT IDFT method for the given to sequences. Solution: Finding the DFT of the two input sequences: 1 X1 = 1 1 1 1 X2 = 1 1 1 1 -j -1 j 1 -j -1 j 1 -1 1 -1 1 -1 1 -1 1 j -1 -j 1 j -1 -j 1 2 3 4 4 3 2 2 11 2-j = 1 2+j = 10 -2+2j -2 -2-2j
MATLAB CODE:
x1 = input('Enter the first sequence'); x2 = input('Enter the second sequence'); N1= length(x1); N2= length(x2); N=max(N1,N2); N3=N1-N2; if(N3>0) x2=[x2 zeros(1,N3)]; else x1=[x1 zeros(1,N3)]; end X1=fft(x1,N) X2=fft(x2,N) y=X1.*X2 y=ifft(y,N) subplot(3,1,1); n1=0:1:length(X1)-1; stem(n1,X1); xlabel('Time'); ylabel('Amplitude'); title('First sequence'); subplot(3,1,2); n2=0:1:length(X2)-1; stem(n2,X1); xlabel('Time'); ylabel('Amplitude'); title('Second sequence'); subplot(3,1,3); n=0:1:length(y)-1; stem(n,y); xlabel('Time'); ylabel('Amplitude'); title('Circular Convolution using DFT and IDFT');
OUTPUT:
X1 = 10.0000 -2.0000 + 2.0000i -2.0000 -2.0000 - 2.0000i
17
X2 = 11.0000 y= 26 25 28
2.0000 + 1.0000i
18
Auto Correlation
THEORY:
Autocorrelation is a mathematical tool for finding repeating patterns, such as the presence of a periodic signal which has been buried under noise, or identifying the missing fundamental frequency in a signal implied by its harmonic frequencies. It is used frequently in signal processing for analyzing functions or series of values, such as time domain signals. Informally, it is the similarity between observations as a function of the time separation between them. More precisely, it is the cross-correlation of a signal with itself.
PROGRAM 8:
PROBLEM:
Write a MatLab program to compute the auto correlation of the given sequence and verify its properties. Solution: 1 4 2 8 2 3 12 4 6 6 24 6 12 3 2 8 12 18 6 2 46 4 16 4 36 9 4 1 70 8 12 18 6 2 46
24 6 12 3 45
12 4 6 22
8 2 10
4 4
10
22
45
MATLAB CODE:
x=[1 2 3 6 2 4]; subplot(2,2,1); n=0:1:length(x)-1; stem(n,x); xlabel('n'); ylabel('amplitude'); title('input sequence'); Rxx=xcorr(x,x); subplot(2,2,2); nRxx=-length(x)+1:length(x)-1; stem(nRxx,Rxx); xlabel('auto correlation axis'); ylabel('auto correlation magnitude'); title('auto correlation output'); %verification of properties energy=sum(x.^2) center_index=ceil(length(Rxx)/2) Rxx_0=Rxx(center_index)
19
if Rxx_0==energy disp('Rxx(0) gives energy - proved'); else disp('Rxx(0) gives energy - not proved'); end Rxx_right=Rxx(center_index:1:length(Rxx)) Rxx_left=Rxx(center_index:-1:1) if Rxx_right == Rxx_left disp('Rxx is even'); else disp('Rxx is odd'); end
OUTPUT:
energy = Rxx_0 = 70 6 70 70 70 46 46 45 45 22 22 10 10 4 4 center_index =
20
Cross correlation
THEORY:
In signal processing, cross-correlation is a measure of similarity of two waveforms as a function of a time-lag applied to one of them. This is also known as a sliding dot product or inner-product. It is commonly used to search a long duration signal for a shorter, known feature. It also has applications in pattern recognition and cryptanalysis.For continuous functions f and g the cross-correlation is defined as:
PROGRAM 9:
PROBLEM:
Compute the cross correlation of the two sequences. Solution: 1 1 3 2 1 4 4 9 20 35 4 2 8 1 4 16 2 2 6 24 4 4 3 5 20 6 8 6 1 41 5 12 12 2 31 10 18 4 32 15 6 21 5 5
MATLAB CODE:
X=[1 2 4 6 5] Y=[1 3 2 1 4] n = 0:1:length(X)-1; m = 0:1:length(Y)-1; subplot(2,2,1); stem(n,X); xlabel('n'); ylabel('amplitude'); title('input1 sequence'); subplot(2,2,2); stem(m,Y); xlabel('n'); ylabel('amplitude'); Department of Telecommunication CMRIT 21
title('input2 sequence'); RXY = Xcorr(X,Y) nRXY = -length(X) +1:length(X)-1 subplot(2,2,3); stem(nRXY,RXY); xlabel('crosscorr axis'); ylabel('crosscorr magnitude'); title('crosscorr output');
OUTPUT:
RXY = 4.0000 nRXY = -4 -3 9.0000 20.0000 35.0000 41.0000 31.0000 32.0000 21.0000 5.0000 -2 -1 0 1 2 3 4
GRAPH:
22
PROGRAM 10:
n=0 y(0)=1+6-5 =2 n=1 y(1) =.25+3-2 =1.2500 n=2 y(2)=0.625+1.875-1 =0.7969 n=3 y(3)=0.0156+1.40625-0.625 =0.7969 n=4 y(4)=0.0039+1.19535-0.46625 =0.7365
23
MATLAB CODE:
a=[1 -3/2 1/2] b=[1] n=0:5; xn=(1/4).^n; disp('values of x(n)'); disp(xn); y=[4,10]; xic=filtic(b,a,y); y=filter(b,a,xn,xic); disp('the solution for difference equation'); disp(y) OUTPUT: a = 1.0000 -1.5000 0.5000
0.0156
0.0039
0.0010 0.6982
the solution for difference equation 2.0000 1.2500 0.9375 0.7969 0.7305
24
PROGRAM 11:
1 1 4
Order
1 2
H j
N1
N2
N3
N2
N3
Butterworth filter tables N=1 (s + 1) N=2 (s^2 +0.5 s^1 +1) N=3 (s^2 +s+1)(s+1) N=4 (s^2+0.76536s+1)(s^2+1.864776s+2)
25
N=5 (s+1)(s^2+0.6180s+1)(s^2+1.6180s+1) CHEBYSHEV FILTERS: Chebyshev filters are equiripple in either the passband or stopband. Hence the magnitude response oscillates between the permitted minimum and maximum values in the band a number of times depending upon the order of filters. There are two types of chebyshev filters. The chebyshev I filter is equiripple in passband and monotonic in the stopband, where as chebyshev II is just the opposite. The Chebyshev low-pass filter has a magnitude response given by
H j
where
A 1
2 2 CN 0.5 c
A is the filter gain is a constant and is the 3-dB cutoff frequency c The Chebyshev polynomial of the 1st kind of Nth order, CN(x) is given by
cos N cos 1 x , CN x cosh N cosh 1 x ,
H j
for x for x
1, passband 1, stopband
N odd
K1
N even N1 N 2
N 2 N3
K2
N3
The magnitude response has equiripple pass band and maximally flat stop band. It can be seen that by increasing the filter order N, the Chebyshev response approximates the ideal response. The phase response of the Chebyshev filter is more non-linear than the Butter worth filter for a given filter length N.
26
PROBLEM:
Using MATLAB design an IIR filter with passband edge frequency 1500Hz and stop band edge at 2600Hz for a sampling frequency of 8000Hz, variation of gain within pass band 1db and stopband attenuation of 15 db. Use Butterworth prototype design and Bilinear Transformation. Design: W1=(2*pi* F1 )/ Fs = 2*pi*250)/1000 =0.5 rad W2=(2*pi* F2 )/ Fs = 2*pi*375)/1000 =0.75 rad Prewarp: 1 = 2/T tan (w1/2) = 2 rad/sec 2 = 2/T tan (w2/2) = 4.8rad/sec Order: n = log[(10-Ap/10 - 1)/ log[(10-As/10 - 1) 2*log[1 / 2 ] n = 1.956 = 2 Cut-off Frequency: c1 = 1 / [(10-Ap/10 - 1)](1/2n) c1 = 2 c2 = 2 / [(10-As/10 - 1)](1/2n) c2 = 2.04 Choose c = 2 rad\sec Normalized Transfer Function: Hn(s) = 1/[ s2 + 1.4142s + 1] T=1sec
H(s) = 1/[(s/2)2 + (s/2) + 1 = 4\[s2 + 2.8484s + 4] Apply BLT: H(Z) = H(s)|s=(2/T)[(1-z-1)/(1+z-1)] H(Z) = 0.29+0.586z-1 +0.29z-2 1+0.172 z-2
27
MATLAB CODE:
%Butterworth Prototype Ap=input(enter passband attenuation =); As=input(enter stopband attenuation =); fp=input(enter passband frequency =); fs= input(enter stopband frequency =); Fs=input(enter sampling frequency=); W1=2* fp / Fs ; W2=2* fs / Fs ; [N,Wn]=buttord(W1,W2,Ap,As) [b,a]=butter(N,Wn) freqz(b,a); title(Butterworth frequency response)
INPUT:
enter passband attenuation =1 enter stopband attenuation =15 enter passband frequency =1500 enter stopband frequency =2000 enter sampling frequency=8000
OUTPUT:
N= 6 Wn = 0.4104 b = 0.0117 0.0699 0.1748 0.2331 0.1748 0.0699 0.0117 a = 1.0000 -1.0635 1.2005 -0.5836 0.2318 -0.0437 0.0043
28
Chebyshev Filter
PROBLEM:
Using MATLAB design an IIR filter with passband edge frequency 1500Hz and stop band edge at 2600Hz for a sampling frequency of 8000Hz, variation of gain within pass band 1 db and stopband attenuation of 15 db. Use Chebyshev prototype design and Bilinear Transformation. DESIGN: W1=(2*pi* F1 )/ Fs = 2*pi*100)/4000 =0.05 rad W2=(2*pi* F2 )/ Fs = 2*pi*500)/4000 =0.25 rad Prewarp: 1 = 2/T tan (w1/2) = 0.157 rad/sec 2 = 2/T tan (w2/2) = 0.828 rad/sec Order: = 10-Ap/10 - 1 T=1sec
A=10
g=
(A2 - 1) /
, g = 13.01
r= 2 / 1
29
n=log10 n= 1.388
g+
(g2-1)
log10{r+
(r2 1) }
Therefore n= 2.
= 0.505/[ s2+0.8s+0.036] Denormalized Transfer Function: H(s)= Hn(s) |s-s/c H(s)= Hn(s) |s-s/0.157
H(s) = 0.0125 / [s2+0.125s+0.057] Apply BLT: H(Z) = H(s)|s=(2/T)[(1-z-1)/(1+z-1)] H(Z) = 0.0125+0.025Z-1 + 0.0125 Z-2 4.2769-7.96Z-1 + 3.76Z-2 H(Z) = 0.0029+0.0052Z-1 + 0.0029 Z-2 1-1.86Z-1 + 0.88Z-2
MATLAB CODE:
%Chebyshev Prototype Ap=input(enter passband attenuation =); As=input(enter stopband attenuation =); fp=input(enter passband frequency =); f s= input(enter stopband frequency =); Fs=input(enter sampling frequency=); W1=2* fp / Fs ; W2=2* fs / Fs ; [N,Wn]=cheb1ord(W1,W2,Ap,As) [b,a]=cheby1(N,Ap,Wn) freqz(b,a); title(Chebyshev frequency response);
30
INPUT:
enter passband attenuation =1 enter stopband attenuation =15 enter passband frequency =1500 enter stopband frequency =2000 enter sampling frequency=8000
OUTPUT:
N= 4 Wn = 0.3750 b = 0.0191 0.0764 0.1147 0.0764 0.0191 a= 1.0000 -1.7994 1.9637 -1.1513 0.3301
31
PROGRAM 12:
The impulse response hd(n) is truncated at n = 0, since we are interested in causal FIR Filter. It is possible to write above equation alternatively as h(n) = hd(n)w(n) where w(n) is said to be a rectangular window defined by w(n) = 1 0nN-1 =0 otherwise Taking DTFT on both the sides of equation(b), we get H() = Hd()*W() .(b)
HAMMING WINDOW:
The impulse response of an N-term Hamming window is defined as follows: wHam(n) = 0.54 0.46cos(2n / (N-1)) 0nN-1 =0 otherwise
PROBLEM:
Using MATLAB design an IIR filter to meet the following specifications choosing Hamming window: Window length, N = 27 Stop band attenuation = 50dB Cut-off frequency = 100 Hz
32
MATLAB CODE:
N=input(Enter the window length=); fc=input(Enter cut-off frequency=); Fs=input(Enter sampling frequency=); Wc=2*fc/ Fs; Wh = (hamming(N)) b = fir1(N-1, Wc ,Wh) [h,omega] = freqz(b,1,256); mag = 20*log10(abs(h)); plot(omega/pi,mag); grid; xlabel(Frequncy in radians in terms of pi); ylabel(gain in dB); title(Response of FIR filter using Hamming window);
INPUT:
Enter the window length=27 Enter cut-off frequency=100 Enter sampling frequency=1000
OUTPUT:
Wh = 0.0800 0.0934 0.1327 0.1957 0.2787 0.3769 0.4846 0.5954 0.7031 0.8013 0.8843 0.9473 0.9866 1.0000 0.9866 0.9473 0.8843 0.8013 0.7031 0.5954 0.4846 0.3769 Department of Telecommunication CMRIT 33
0.2787 0.1957 0.1327 0.0934 0.0800 b= Columns 1 through 6 0.0019 0.0023 0.0022 -0.0000 -0.0058 -0.0142 Columns 7 through 12 -0.0209 -0.0185 0.0000 Columns 13 through 18 0.1840 0.1994 0.1840
0.0374
0.0890
0.1429
0.1429
0.0890
0.0374
Columns 19 through 24 0.0000 -0.0185 -0.0209 -0.0142 -0.0058 -0.0000 Columns 25 through 27 0.0022 0.0023 0.0019
34
7. After the addition of all three files ,the expanded project tree on left hand side will resemble this format.(observe the LHS project tree which contains a library file, a source code and linker command file.) 8. Now we need to compile and build our program. To compile go to project -- > compile file. Now the project will be compiled and any errors will be displayed below if there. To build go to project - - >build. Now project will be built and any errors or warnings will be displayed below. 9. Now we need to load program in CPU or simulator . Go to file - - > load program. A dialog box will open in which we have select executable .out file. The usual path is \ti\MyProjects\linear\debug\linear.out 10. Now we can assembly equivalent of C source code which the simulator has generated. 11. To see the output of the program we have to run the program. Go to Debug - - > Run . 12. Now we can see output of the program below. If the program needs any user input, a pop-up window will open. 13. Now we need to see the plot of output . Go to View - - > Graph - - > Time\frequency.. Now a graph property dialog box will open up. Select Display type = single time. Graph title = Any name. Start address = the variable which we want to display. Index increment= 1(usually). DSP data type = 32-bit signed integer. DATA plot style = bar(for displaying discrete values). Grid style = Full grid. Now the graph will be displayed. *We can select different elements by using left and right keys of keyboard.
36
PROGRAM 1:
37
38
Circular Convolution
PROBLEM:
Perform the Circular Convolution of the given sequence using Code Composer Studio. #include<stdio.h> int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30]; void main() { printf(" enter the length of the first sequence\n"); scanf("%d",&m); printf(" enter the length of the second sequence\n"); scanf("%d",&n); printf(" enter the first sequence\n"); for(i=0;i<m;i++) scanf("%d",&x[i]); printf(" enter the second sequence\n"); for(j=0;j<n;j++) scanf("%d",&h[j]); if(m-n!=0) { if(m>n) { for(i=n;i<m;i++) h[i]=0; n=m; } for(i=m;i<n;i++) x[i]=0; m=n; } y[0]=0; a[0]=h[0]; for(j=1;j<n;j++) a[j]=h[n-j];
PROGRAM 2:
39
for(i=0;i<n;i++) { a[i]=x2[i]; y[k]+=x[i]*x2[i]; } } printf(" the circular convolution is\n"); for(i=0;i<n;i++) printf("%d \t",y[i]); } INPUT: Length of first sequence = 4 Length of second sequence = 4 First sequence =[1 2 2 1 ] Second sequence =[1 2 2 1] OUTPUT: The circular convolution is [9 8 9 10]
40
PROGRAM 3:
for(j=0;j<10;j++) { x[0]=impulse[j]; y[0] = (a[0] *x[0]) +(a[1]* x[1] ) +(x[2]*a[2]) - (y[1]*b[1])-(y[2]*b[2]); printf("%f\n",y[0]); z[j]=y[0]; y[2]=y[1]; y[1]=y[0]; x[2]=x[1]; x[1] = x[0]; } }
INPUT:
Coefficient of x(n)={0.1311,0.2622,0.1311} Coefficient of y(n)={1,-0.7478,0.2722}
OUTPUT:
0.131100 0.360237 0.364799 0.174741 0.031373 -0.024104 -0.026565 -0.013304
41
42
PROGRAM:4
Input:
Output:
43
44