You are on page 1of 25

NORTHERN INDIA ENGINEERING COLLEGE NEW DELHI (Department of Electronics & Communication Engg.

DSP LAB MANUAL

Prepared by:

LIST OF Experiments
1. Write a program for the Generation of following Basic signals : (a) Sine Signal, (b) Cosine Signal, (c) Exponential Sequence, (d) Unit Step Sequence, (e) Ramp Sequence, (f) Unit Impulse Signal. 2. Write a program for Computing (a) Linear Convolution, (b) Circular Convolution, (c) Auto-correlation, (d) Cross-correlation of the Sequence x = [1, 2] and h = [1, 2, 4].

3. Write a program for Computing (a) Discrete Fourier Transform (DFT), (b) Inverse Discrete Fourier Transform (IDFT). (c) Fast Fourier Transform (FFT). (d) Inverse Fast Fourier Transform (IFFT).

4. Write a program of Sampling at: (a) Less than Nyquist Rate (Fs < 2Fm), (b) Nyquist Rate (Fs = 2Fm ), (c) Above Nyquist Rate (Fs > 2Fm). 5. Write a program for the design of Butterworth (a) Low Pass digital filter, (b) High Pass digital filter, (c) Band Pass digital filter, (d) Band Stop digital filter. 6. Write a program for the design of Chebyshev (e) Low Pass digital filter, (f) High Pass digital filter, (g) Band Pass digital filter, (h) Band Stop digital filter. 7. Write a program for the design of FIR (a) Low Pass, (b) High Pass, (c) Band Pass, (d) Band Stop filters using rectangular window. 8. Generation of Sine Wave through DSP Kit 6713 (DSP LAB 2.0).

EXPERIMENT NO. 1 OBJECTIVE:Write a program for the Generation of following Basic signals : (a) Sine Sequence, (b) Cosine Sequence, (c) Exponential Sequence, (d) Unit Step Sequence, (e) Ramp Sequence, (f) Unit Impulse Signal.

APPARATUS :PROGRAM :-

Use Software ( Matlab version )

clc; clear all; close all; % Program (1)(a) for the generation of Sine Sequence t = 0 : .01 : pi; x = sin(2*pi*t); subplot(2,3,1); plot(t,x); ylabel('Amplitude ----->'); xlabel('Time-->'); title('Exp no.1(a) Sine Wave'); % Program (1)(b) for the generation of cosine Sequence t = 0 : .01 : pi; y = cos(2*pi*t); subplot(2,3,2); plot(t,y); ylabel('Amplitude ----->'); xlabel('Time--->'); title('Exp no.1(b) Cosine Wave'); % Program (1)(c) for the generation of Exponential Sequence N = input('Enter the Length of sequence N:-'); n = 0 : N-1; a = input('Enter the value of a:-'); e = exp(a*n); subplot(2,3,3); stem(n,e); grid on ylabel('Amplitude ----->'); xlabel('n ----->'); title('Exp no.1(c) Exponential Sequence'); % Program (1)(d) for the generation of Unit Step Sequence (u(n)) u = ones(1,N); subplot(2,3,4); stem(n,u); grid on ylabel('Amplitude ----->'); xlabel('n ----->'); title('Exp no.1(d) Unit Step Sequence');

% Program (1)(e) for the generation of Ramp Sequence r = n; subplot(2,3,5); stem(n,r); grid on ylabel('Amplitude ----->'); xlabel('n ----->'); title('Exp no.1(e) Ramp Sequence');

% Program (1)(f) for the generation of Unit Impulse Signal (I(n)) ni = - 2 : 1 : 2; I = [zeros(1,2),ones(1,1),zeros(1,2)]; subplot(2,3,6); stem(ni,I); grid on ylabel('Amplitude ----->'); xlabel('n ------>'); title('Exp no. 1(f) Unit impulse signal');

INPUT :Enter the Length of sequence N:-5 Enter the value of a :- -1 OUTPUT :-

Questions

What is meant by MAT? What is digital signal processing (DSP)? Explain different sequences. What are the advantages and disadvantages of DSP? Give some applications of DSP.

EXPERIMENT NO. 2

OBJECTIVE :Write a program for Computing (a) Linear Convolution, (b) Circular Convolution, (c) Auto-correlation, (d) Cross-correlation of the Sequence x = [1, 2] and h = [1, 2, 4].

APPARATUS :PROGRAM :clc; clear all; close all;

Use Software (Matlab version )

% Program for Computing 2(a) Discrete Linear Convolution

x=input('Enter the first sequence x(n):-'); h=input('Enter the second sequence h(n):-'); y=conv(x,h) subplot(3,2,1) stem(x) ylabel('Amplitude ----->'); xlabel(' n -----> input signals x(n)'); subplot(3,2,2); stem(h); ylabel('Amplitude ----->'); xlabel(' n ------> input signals h(n)'); subplot(3,2,3); stem(y); ylabel('Amplitude ------>'); xlabel('(c) n ------> output signals y(n)'); title('Exp no. 2(a) Discrete Linear Convolution'); % Program for Computing 2(b) Circular Convolution y1 = cconv(x,h,3) subplot(3,2,4); stem(y1); ylabel('Amplitude ------>'); xlabel(' n ------> '); title('Exp no. 2(b) Circular Convolution ');

% Program for Computing 2(c) Auto-Correlation y2 = xcorr(x) subplot(3,2,5); stem(y2); ylabel('Amplitude ------>'); xlabel('n ------> '); title('Exp no. 2(c) Auto-Correlation '); % Program for Computing 2(d) Cross-Correlation y3 = xcorr(x,h) subplot(3,2,6); stem(y3); ylabel('Amplitude ------>'); xlabel(' n ------> '); title('Exp no. 2(d) Cross-Correlation ');

Alternatively
clc; clear all; close all; x = [1 2]; nx = 0:1; subplot(3,2,1) stem(nx,x); grid on ylabel('Amplitude ----->'); xlabel(' n -----> '); title('input signals x(n)') h = [1 2 4]; nh = 0:2; subplot(3,2,2) stem(nh,h); grid on ylabel('Amplitude ---->'); xlabel(' n -----> '); title('impulse response h(n)') %Program for computing 2(a) Linear convolution nyl = nx(1) + nh(1); % left edge of y nyr = nx(length(x))+nh(length(h)); % right edge of y yl = conv(x,h) % linear convoltion ny = nyl:nyr; subplot(3,2,3) stem(ny,yl); grid on ylabel('Amplitude ----->'); xlabel(' n -----> '); title('Linear Convolution y(n)') %Program for computing 2(b) Circular convolution m = max(length(x),length(h)) ; % to find length of y for cicular convolution yc = cconv(x,h,m) nyc = 0:m-1; subplot(3,2,4) stem(nyc,yc); grid on ylabel('Amplitude ----->'); xlabel(' n -----> '); title('Circular Convolution y(n)') %Program for computing 2(c) Auto- Correlation x1 = fliplr(x); nx1 = -1:0; nRl = nx(1) + nx1(1); nRr = nx(length(x))+nx1(length(x1));

Rxx = conv(x,x1) nR = nRl:nRr; subplot(3,2,5) stem(nR,Rxx); grid on ylabel('Amplitude ----->'); xlabel(' n -----> '); title('Auto correlation Rxy(n)') %Program for computing 2(d) Cross- Correlation h1 = fliplr(h);nh1 = -2:0; nRl = nx(1) + nh1(1); nRr = nx(length(x))+nh1(length(h1)); Rxy = conv(x,h1) nR = nRl:nRr; subplot(3,2,6) stem(nR,Rxy); grid on ylabel('Amplitude ----->'); xlabel(' n -----> '); title('Cross correlation Rxy(n)')

INPUT :Enter the first sequence x(n):-[1 2] Enter the second sequence h(n):-[1 2 4]
OUTPUT :Linear Convolution yl(n) [1 4 8 8] Circular Convolution yc(n) [9 4 8] Auto-Correlation Rxx(n) [2 5 2] Cross-Correlation Rxy(n) [4 10 5 2 0]

QUESTIONS

Explain Computing Circular Convolution. Distinguish between the Linear and Circular Convolution. State the properties of Linear Convolution. What is clc , clear all , close all in MATLAB program ?

EXPERIMENT NO. 3 OBJECTIVE:Write a program for Computing (a) Discrete Fourier Transform (DFT). (b) Inverse Discrete Fourier Transform (IDFT). (c) Fast Fourier Transform (FFT). (d) Inverse Fast Fourier Transform (IFFT).

APPARATUS:PROGRAM:-

Use Software (Matlab version

clc; clear all; close all; %Program for Computing 3(a) Discrete Fourier Transform (DFT) x=input('Enter the sequence :-'); N=length(x); n= 0:1:N-1; k= 0:1:N-1; WN = exp(-1i*2*pi/N); nk = n'*k; WNnk = WN.^nk; %To compute element wise POWER, use POWER (.^) Xk = x*WNnk %Program for Computing 3(b) Inverse Discrete Fourier Transform (IDFT) %Xk output of DFT is Input for IDFT WNnk1 = WN.^(-nk); xn = (Xk*WNnk1)/N %Program for Computing 3(c) Fast Fourier Transform (FFT) X = fft(x,N) %Program for Computing 3(d) Inverse Fast Fourier Transform (IFFT) x = ifft(X)

INPUT :Enter the sequence

:-

[1 2 3 0]

OUTPUT :Xk =6.0000 -2.0000 - 2.0000i 2.0000 + 0.0000i 0 + 0.0000i -2.0000 + 2.0000i

xn = 1.0000 - 0.0000i 2.0000 - 0.0000i 3.0000 + 0.0000i X =6.0000 x =1 2 3 0 -2.0000 - 2.0000i 2.0000

-2.0000 + 2.0000i

QUESTIONS

Define DFT. Explain any two properties of DFT. Define FFT. Why FFT is needed. What is a decimation-in-time algorithm ? What is a decimation-in-frequency algorithm ? What is the main advantage of FFT ? What is meant by radix-2 FFT ?

EXPERIMENT NO. 4

OBJECTIVE:Write a program of Sampling at: (a) Less than Nyquist Rate (Fs < 2Fm), (b) Nyquist Rate (Fs = 2Fm ), (c) Above Nyquist Rate (Fs > 2Fm).

APPARATUS:PROGRAM :-

Use Software (Matlab version

%Sampling Theorem clc; clear all; close all; t = 0:0.01 : 1; fm= input('enter frequency fm: '); xt = cos(2*pi*fm*t); subplot(4,1,1); plot(t,xt); title('cos function '); xlabel('time'); ylabel('amplitude'); % Program Sampling at 4(a) Fs<2Fm (fs < 2fm) fs1=1.3 * fm; n1=0:1/fs1:1; xn1 = cos(2*pi*fm*n1); subplot(4,1,2); plot(t,xt,'r',n1,xn1,'b'); title('undersampling'); xlabel('time'); ylabel('amplitude'); % Program Sampling at 4(b) Fs = 2Fm fs2=2 * fm; n2=0:1/fs2:1; xn2 = cos(2*pi*fm*n2); subplot(4,1,3); plot(t,xt,'r',n2,xn2,'b'); title('nyquist rate'); xlabel('time'); ylabel('amplitude'); % Program Sampling at 4(c) Fs>2Fm fs3=2.9 * fm; n3=0:1/fs3:1; xn3 = cos(2*pi*fm*n3); subplot(4,1,4); plot(t,xt,'r',n3,xn3,'b'); title('oversampling'); xlabel('time'); ylabel('amplitude');

INPUT
Enter frequency fm: 10

OUTPUT

Alternatively, PROGRAM:clc; close all; clear all; t=-10:0.01:10; T=8; fm=1/T; x=cos(2*pi*fm*t); fs1=1.2*fm; fs2=2*fm; fs3=8*fm; n1=-4:1:4; xn1=cos(2*pi*n1*fm/fs1); subplot(221) plot(t,x); xlabel('time in seconds'); ylabel('x(t)'); title('continuous time signal'); subplot(222) stem(n1,xn1); hold on;

plot(n1,xn1); xlabel('n'); ylabel('x(n)'); title('discrete time signal with fs<2fm'); n2=-5:1:5; xn2=cos(2*pi*n2*fm/fs2); subplot(223) stem(n2,xn2); hold on; plot(n2,xn2); xlabel('n'); ylabel('x(n)'); title('discrete time signal with fs=2fm'); n3=-20:1:20; xn3=cos(2*pi*n3*fm/fs3); subplot(224) stem(n3,xn3); hold on; plot(n3,xn3); xlabel('n'); ylabel('x(n)'); title('discrete time signal with fs>2fm');

Output:

EXPERIMENT NO. 5

OBJECTIVE:Write a program for the design of Butterworth (a) Low Pass digital filter, (b) High Pass digital filter, (c) Band Pass digital filter, (d) Band Stop digital filter.

APPARATUS:- Use Software (Matlab version ) PROGRAM:clc; clear all;close all; %Program for the design of Butterworth 5(a) Low Pass digital filter. rp=input('Enter the passband ripple :-'); rs=input('Enter the stopband ripple :-'); wp=input('Enter the passband freq :-'); ws=input('Enter the stopband freq :-'); fs=input('Enter the sampling freq :-'); w1=2*wp/fs; w2=2*ws/fs; [n,wn]=buttord(w1,w2,rp,rs); % returns the lowest order, n, of the digital Butterworth filter that loses no more than rp dB in the passband and has at least rs dB of attenuation in the stopband. [b,a]=butter(n,wn); w=0:.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,2,1); plot(om/pi,m); xlabel('normalised freq ---->'); ylabel('Gain in db ---->'); title('Exp No.5(a) Bw IIR LPF (Amplitude Response)'); subplot(2,2,2); plot(om/pi,an); xlabel('normalisd freq ---->'); ylabel('Phase in radians ---->'); title('BW IIR LPF (Phase Response)'); %Program for the design of Butterworth 5(b) High Pass digital filter. [n1,wn1]=buttord(w1,w2,rp,rs); [b1,a1]=butter(n1,wn1,'high'); w=0:.01:pi; [h1,om1]=freqz(b1,a1,w); m=20*log10(abs(h1)); an=angle(h1); subplot(2,2,3); plot(om/pi,m); xlabel('normalised freq ---->'); ylabel('Gain in db ---->'); title('Exp No.5(b) BW IIR HPF(Amplitude Response)'); subplot(2,2,4);

plot(om/pi,an); xlabel('normalisd freq ---->'); ylabel('Phase in radians ---->'); title('BW IIR HPF (Phase Response)'); %Program for the design of Butterworth 5(c) Band Pass digital filter. [n2]=buttord(w1,w2,rp,rs); wn = [w1 w2]; [b2,a2]=butter(n2,wn,'bandpass'); w=0:.01:pi; [h2,om2]=freqz(b2,a2,w); m=20*log10(abs(h2)); an=angle(h2); figure; subplot(2,2,1); plot(om/pi,m); xlabel('normalised freq ---->'); ylabel('Gain in db ---->'); title('Exp No.5(c) BW IIR BPF(Amplitude Response)'); subplot(2,2,2); plot(om/pi,an); xlabel('normalisd freq ---->'); ylabel('Phase in radians ---->'); title('BW IIR BPF (Phase Response)'); %Program for the design of Butterworth 5(d) Band Stop digital filter. [n2]=buttord(w1,w2,rp,rs); wn = [w1 w2]; [b2,a2]=butter(n2,wn,'stop'); w=0:.01:pi; [h2,om2]=freqz(b2,a2,w); m=20*log10(abs(h2)); an=angle(h2); subplot(2,2,3); plot(om/pi,m); xlabel('normalised freq ---->'); ylabel('Gain in db ---->'); title('Exp No.5(d) BW IIR BSF(Amplitude Response)'); subplot(2,2,4); plot(om/pi,an); xlabel('normalisd freq ---->'); ylabel('Phase in radians ---->'); title('BW IIR BSF (Phase Response)');

INPUT :Enter the passband ripple :Enter the stopband ripple : Enter the passband freq :Enter the stopband freq :Enter the sampling freq :.5 50 1200 2400 10000

OUTPUT

QUESTIONS

Explain IIR filter. What are the steps to design Butterworth Low Pass digital filter ? Give the bilinear transform equation between s-plane and z- plane. What are the steps to design Butterworth High Pass digital filter . What do you understand by backward difference ? What is bilinear transformation ? What are the properties of the bilinear transformation What are the steps to design Butterworth Band Pass digital filter ? What is pre - warping ? What is analog - to- analog spectral transformations ? Explain analog design using digital filters. Explain the impulse invariance method of designing IIR digital filters. Explain the Step - invariance technique of designing IIR digital filters.

EXPERIMENT NO. 6

OBJECTIVE:Write a program for the design of Chebyshev (a) Low Pass digital filter, (b) High Pass digital filter, (c) Band Pass digital filter, (d) Band Stop digital filter.

APPARATUS :PROGRAM :clc; clear all; close all;

Use Software (Matlab version

%Program for the design of Chebyshev 6(a) Low Pass digital filter. rp=input('Enter the passband ripple :-'); rs=input('Enter the stopband ripple :-'); wp=input('Enter the passband freq :-'); ws=input('Enter the stopband freq :-'); fs=input('Enter the sampling freq :-'); w1=2*wp/fs; w2=2*ws/fs; [n,wn]=cheb1ord(w1,w2,rp,rs); [b,a]=cheby1(n,wn,rp); w=0:.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,2,1); plot(om/pi,m); xlabel('normalised freq ---->'); ylabel('Gain in db ---->'); title('Exp No.6(a) Bw IIR LPF (Amplitude Response)'); subplot(2,2,2); plot(om/pi,an); xlabel('normalisd freq ---->'); ylabel('Phase in radians ---->'); title('BW IIR LPF (Phase Response)'); %Program for the design of Chebyshev 6(b) High Pass digital filter. [n1,wn1]=cheb1ord(w1,w2,rp,rs); [b1,a1]=cheby1(n1,rp,wn1,'high'); w=0:.01:pi; [h1,om1]=freqz(b1,a1,w); m=20*log10(abs(h1)); an=angle(h1); subplot(2,2,3);

plot(om/pi,m); xlabel('normalised freq ---->'); ylabel('Gain in db ---->'); title('Exp No.6(b) BW IIR HPF(Amplitude Response)'); subplot(2,2,4); plot(om/pi,an); xlabel('normalisd freq ---->'); ylabel('Phase in radians ---->'); title('BW IIR HPF (Phase Response)'); %Program for the design of Chebyshev 6(c) Band Pass digital filter. [n2]=cheb1ord(w1,w2,rp,rs); wn = [w1 w2]; [b2,a2]=cheby1(n2,rs,wn,'bandpass'); w=0:.01:pi; [h2,om2]=freqz(b2,a2,w); m=20*log10(abs(h2)); an=angle(h2); figure; subplot(2,2,1); plot(om/pi,m); xlabel('normalised freq ---->'); ylabel('Gain in db ---->'); title('Exp No.6(c) BW IIR BPF(Amplitude Response)'); subplot(2,2,2); plot(om/pi,an); xlabel('normalisd freq ---->'); ylabel('Phase in radians ---->'); title('BW IIR BPF (Phase Response)');

%Program for the design of Chebyshev 6(d) Band Stop digital filter. [n2]=cheb1ord(w1,w2,rp,rs); wn = [w1 w2]; [b2,a2]=cheby1(n2,rs,wn,'stop'); w=0:.01:pi; [h2,om2]=freqz(b2,a2,w); m=20*log10(abs(h2)); an=angle(h2); subplot(2,2,3); plot(om/pi,m); xlabel('normalised freq ---->'); ylabel('Gain in db ---->'); title('Exp No.6(d) BW IIR BSF(Amplitude Response)'); subplot(2,2,4); plot(om/pi,an); xlabel('normalisd freq ---->'); ylabel('Phase in radians ---->'); title('BW IIR BSF (Phase Response)');

INPUT :Enter the passband ripple :- .5 Enter the stopband ripple : 50 Enter the passband freq :- 1200 Enter the stopband freq :- 2400 Enter the sampling freq :- 10000

OUTPUT :-

QUESTIONS
What are the properties of Chebyshev filter? What are the characteristics of Chebyshev filters ? Compare Butterworth and Chebyshev filters.

EXPERIMENT NO. 7 OBJECTIVE:Write a program for the design of Low Pass FIR Filter using following Windows (a) Rectangular, (b) Hamming, (d) Hanning, (e) Kaiser.

APPARATUS :PROGRAM

Use Software (Matlab version

clc;clear all;close all; %Program for the design of 7(a) Low Pass FIR Filter using Rectangular Windows fc = 0.5; %Matlab procedure requires normalizing fc by half of fs N = 11;% length of the filter wn1 = rectwin(N); hn1 = fir1((N-1), fc,wn1); subplot(2,2,2) plot(hn1) title('LPF Response Using Rectangular Window 7(a)') subplot(2,2,1) plot(wn1) title(' Rectangular Window') %Program for the design of 7(b) Low Pass FIR Filter using Hamming Windows wn2 = hamming(N); %hd2 = fir1((N-1), fc,wn1); hn2 = fir1((N-1),fc,wn2); subplot(2,2,3) plot(wn2) title('Hamming Window') subplot(2,2,4) plot(hn2) title('LPF Response Using Hamming Window 7(b)') figure; %Program for the design of 7(c) Low Pass FIR Filter using Hanning Windows wn3 = hanning(N); %hd3 = fir1((N-1), fc,wn1) hn3 = fir1((N-1), fc,wn3); subplot(2,2,2) plot(hn3) title('LPF Response Using Hanning Window 7(c)') subplot(2,2,1) plot(wn3) title(' Hanning Window')

%Program for the design of 7(d) Low Pass FIR Filter using Kaiser Windows wn4 = kaiser(N) %hd4 = fir1((N-1), fc,wn1) hn4 = fir1((N-1),fc,wn4) subplot(2,2,3) plot(wn4) title('Kaiser Window') subplot(2,2,4) plot(hn4) title('LPF Response Using Kaiser Window 7(d)')

OUTPUT:-

QUESTIONS

Explain FIR filter. Explain the characteristics of FIR digital filter. List the design techniques for linear phase FIR filters. Compare IIR and FIR filters. Explain the steps to design FIR digital filter using rectangular window technique.

You might also like