dspman

78
DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA DEPT:ECE 1 JAFERKHAN.P DIGITAL SIGNAL PROCESSING LAB MANUAL PREPARED BY: JAFERKHAN.P ASSISTANT PROFESSOR IN ECE COLLEGE OF ENGINEERING KOTTARAKKARA DEPT: ELECTRONICS AND COMMUNICATION

Transcript of dspman

Page 1: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 1 JAFERKHAN.P

DIGITAL SIGNAL PROCESSING

LAB MANUAL

PREPARED BY: JAFERKHAN.P

ASSISTANT PROFESSOR IN ECE

COLLEGE OF ENGINEERING KOTTARAKKARA

DEPT: ELECTRONICS AND COMMUNICATION

Page 2: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 2 JAFERKHAN.P

FAMILIARISATION WITH MATLAB Aim: To familiarise with MATLAB software, general functions and signal processing toolbox functions. The name MATLAB stands for MATrix LABoratory produced by Mathworks Inc., USA. It is a matrix-based powerful software package for scientific and engineering computation and visualization. Complex numerical problems can be solved in a fraction of the time that required with other high level languages. It provides an interactive environment with hundreds of built -in –functions for technical computation, graphics and animation. In addition to built-in-functions, user can create his own functions. MATLAB offers several optional toolboxes, such as signal processing, control systems, neural networks etc. It is command driven software and has online help facility. MATLAB has three basic windows normally; command window, graphics window and edit window. Command window is characterized by the prompt ‘>>’. All commands and the ready to run program filename can be typed here. Graphic window gives the display of the figures as the result of the program. Edit window is to create program files with an extension .m. Some important commands in MATLAB Help List topics on which help is available Help command name Provides help on the topic selected Demo Runs the demo program Who Lists variables currently in the workspace Whos Lists variables currently in the workspace with their size Clear Clears the workspace, all the variables are removed Clear x,y,z Clears only variables x,y,z Quit Quits MATLAB Some of the frequently used built-in-functions in Signal Processing Toolbox filter(b.a.x) Syntax of this function is Y = filter(b.a.x) It filters the data in vector x with the filter described by vectors a and b to create the filtered data y. fft (x) It is the DFT of vector x ifft (x) It is the DFT of vector x conv (a,b) Syntax of this function is C = conv (a,b) It convolves vectors a and b. The resulting vector is of Length, Length (a) + Length (b)-1 deconv(b,a) Syntax of this function is [q,r] = deconv(b,a) It deconvolves vector q and the remainder in vector r such that b = conv(a,q)+r

Page 3: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 3 JAFERKHAN.P

butter(N,Wn) designs an Nth order lowpass digital Butterworth filter and returns the filter coefficients in length N+1 vectors B (numerator) and A (denominator). The coefficients are listed in descending powers of z. The cutoff frequency Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. buttord(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital Butterworth filter that loses no more than Rp dB in the passband and has at least Rs dB of attenuation in the stopband. Wp and Ws are the passband and stopband edge frequencies, Normalized from 0 to 1 ,(where 1 corresponds to pi rad/sec) Cheby1(N,R,Wn) designs an Nth order lowpass digital Chebyshev filter with R decibels of peak-to-peak ripple in the passband. CHEBY1 returns the filter coefficients in length N+1 vectors B (numerator) and A (denominator). The cutoff frequency Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. Cheby1(N,R,Wn,'high') designs a highpass filter. Cheb1ord(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital Chebyshev Type I filter that loses no more than Rp dB in the passband and has at least Rs dB of attenuation in the stopband. Wp and Ws are the passband and stopband edge frequencies, normalized from 0 to 1 (where 1 corresponds to pi radians/sample) cheby2(N,R,Wn) designs an Nth order lowpass digital Chebyshev filter with the stopband ripple R decibels down and stopband edge frequency Wn. CHEBY2 returns the filter coefficients in length N+1 vectors B (numerator) and A . The cutoff frequency Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. cheb2ord(Wp, Ws, Rp, Rs) returns the order N of the lowest order digital Chebyshev Type II filter that loses no more than Rp dB in the passband and has at least Rs dB of attenuation in the stopband. Wp and Ws are the passband and stopband edge frequencies, abs(x) It gives the absolute value of the elements of x. When x is complex, abs(x) is the complex modulus (magnitude) of the elements of x.

Page 4: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 4 JAFERKHAN.P

angle(H) It returns the phase angles of a matrix with complex elements in radians. freqz(b,a,N) Syntax of this function is [h,w] = freqz(b,a,N) returns the N- point frequency vector w in radians and the N-point complex frequency response vector h of the filter b/a. stem(y) It plots the data sequence y aa stems from the x axis terminated with circles for the data value. stem(x,y) It plots the data sequence y at the values specified in x. ploy(x,y) It plots vector y versus vector x. If x or y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. title(‘text’) It adds text at the top of the current axis. xlabel(‘text’) It adds text beside the x-axis on the current axis. ylabel(‘text’) It adds text beside the y-axis on the current axis.

Page 5: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 5 JAFERKHAN.P

GENERATION OF BASIC CONTINUES SIGNALS

Experiment No: - 01(a)

AIM: - TO write a MATLAB program to common continues time signals PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the amplitude and frequency of the signal Use ‘sin’, ’cos’ ,’square’ matlab built in functions Using ‘plot’ function plot the signal

MATLAB CODE:-

clc; clear all; close all; t=0:.001:1; f=input('Enter the value of frequency'); a=input('Enter the value of amplitude'); subplot(3,3,1); y=a*sin(2*pi*f*t); plot(t,y,'r'); xlabel('time'); ylabel('amplitude'); title('sine wave') grid on; subplot(3,3,2); z=a*cos(2*pi*f*t); plot(t,z); xlabel('time'); ylabel('amplitude'); title('cosine wave') grid on; subplot(3,3,3); s=a*square(2*pi*f*t); plot(t,s); xlabel('time'); ylabel('amplitude'); title('square wave') grid on; subplot(3,3,4); plot(t,t); xlabel('time'); ylabel('amplitude'); title('ramp wave') grid on;

Page 6: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 6 JAFERKHAN.P

subplot(3,3,5); plot(t,a,'r'); xlabel('time'); ylabel('amplitude'); title('unit step wave') grid on;

FIGURE:-

SAMPLE INPUT:-

Enter the value of frequency2 Enter the value of amplitude1

RESULTS:- Thus the generation of continues time signals using matlab was verified

0 0.5 1-1

0

1

time

ampl

itude

sine wave

0 0.5 1-1

0

1

time

ampl

itude

cosine wave

0 0.5 1-1

0

1

time

ampl

itude

square wave

0 0.5 10

0.5

1

time

ampl

itude

ramp wave

0 0.5 10

1

2

time

ampl

itude

unit step wave

Page 7: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 7 JAFERKHAN.P

GENERATION OF BASIC DISCRETE SIGNALS

Experiment No: - 01(b)

AIM: - TO write a MATLAB program to common discrete time signals PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the amplitude and frequency of the signal Use ‘sin’, ’cos’ ,’square’ matlab built in functions Using ‘stem’ function plot the signal

MATLAB CODE:-

clc; clear all; close all; n=0:1:50; f=input('Enter the value of frequency'); a=input('Enter the value of amplitude'); N=input('Enter the length of unit step'); subplot(3,3,1); y=a*sin(2*pi*f*n); stem(n,y,'r'); xlabel('time'); ylabel('amplitude'); title('sine wave') grid on; subplot(3,3,2); z=a*cos(2*pi*f*n); stem(n,z); xlabel('time'); ylabel('amplitude'); title('cosine wave') grid on; subplot(3,3,3); s=a*square(2*pi*f*n); stem(n,s); xlabel('time'); ylabel('amplitude'); title('square wave') grid on; subplot(3,3,4);

Page 8: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 8 JAFERKHAN.P

stem(n,n); xlabel('time'); ylabel('amplitude'); title('ramp wave') grid on; x=0:N-1; d=ones(1,N); subplot(3,3,5); stem(x,d,'r'); xlabel('time'); ylabel('amplitude'); title('unit step wave') grid on;

FIGURE:-

SAMPLE INPUT:-

Enter the value of frequency 0.03 Enter the value of amplitude 1 Enter the length of unit step 9

RESULTS:- Thus the generation of discrete time signals using matlab was verified

0 50-1

0

1

time

ampl

itude

sine wave

0 50-1

0

1

time

ampl

itude

cosine wave

0 50-1

0

1

time

ampl

itude

square wave

0 500

50

time

ampl

itude

ramp wave

0 5 100

0.5

1

time

ampl

itude

unit step wave

Page 9: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 9 JAFERKHAN.P

IMPULSE RESPONSE OF AN LTI SYSTEM

Experiment No: - 02

AIM: - TO write a MATLAB program to find the impulse response of a system defined by a difference equation PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Create a matrix a for the coefficient of y[n] Create a matrix b for the coefficient of x[n] Generate an impulse signal Find the response h[n] of the system defined by a and b coefficient

To the impulse signal using ‘filter ‘command

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the required length of impulse response N='); n=0:N-1; b=input('Enter the co-efficients of x(n),b='); a=input('Enter the co=efficients of y(n),a='); x=[1,zeros(1,N-1)]; y=filter(b,a,x); stem(n,y); xlabel('time'); ylabel('amplitude'); title('IMPULSE RESPONSE'); grid on;

Page 10: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 10 JAFERKHAN.P

FIGURE:-

SAMPLE INPUT:-

Y[n]+0.7y[n-1]-0.45y[n-2]-0.6y[n-3]=0.8x[n]-0.44x[n-1]+0.36x[n-2]+0.2x[n-3]

Enter the required length of impulse response N=40 Enter the co-efficients of x(n),b=[0.8 -0.44 0.36 0.02] Enter the co=efficients of y(n),a=[1 0.7 -0.45 -0.6] RESULTS:- Thus the program for impulse response of an LTI system is written using MATLAB and verified.

0 5 10 15 20 25 30 35 40-1

-0.5

0

0.5

1

1.5

time

ampl

itude

IMPULSE RESPONSE

Page 11: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 11 JAFERKHAN.P

LINEAR CONVOLUTION USING MATLAB

Experiment No: - 03

AIM: - TO write a MATLAB program to compute linear convolution of two given sequences

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Read the input sequence x[n] ,and plot

Read the impulse sequence h[n] , and plot

Use the matlab function ‘conv’

Convolve the two sequence and plot the result

MATLAB CODE:-

clc; clear all; close all; a=input('Enter the starting point of x[n]='); b=input('Enter the starting point of h[n]='); x=input('Enter the co-efficients of x[n]='); h=input('Enter the co-efficients of h[n]='); y=conv(x,h); subplot(3,1,1); p=a:(a+length(x)-1); stem(p,x); grid on; xlabel('Time'); ylabel('Amplitude'); title('INPUT x(n)'); subplot(3,1,2); q=b:(b+length(h)-1); stem(q,h); grid on; xlabel('Time'); ylabel('Amplitude'); title('IMPULSE RESPONSE h(n)'); subplot(3,1,3); n=a+b:length(y)+a+b-1; stem(n,y); grid on; disp(y) xlabel('Time');

Page 12: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 12 JAFERKHAN.P

ylabel('Amplitude'); title('LINEAR CONVOLUTION');

FIGURE:-

SAMPLE INPUT:--

Enter the starting point of x(n)=0 Enter the starting point of h(n)=-1 Enter the co-efficient of x(n)=[1 2 3] Enter the co-efficient of h(n)=[1 1 1] 1 3 6 5 3 RESULTS :- Thus the program for linear convolution is written using MATLAB and verified.

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 20

1

2

3

Time

Am

plitu

de

INPUT x(n)

-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 10

0.5

1

Time

Am

plitu

de

IMPULSE RESPONSE h(n)

-1 -0.5 0 0.5 1 1.5 2 2.5 30

2

4

6

Time

Am

plitu

de

LINEAR CONVOLUTION

Page 13: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 13 JAFERKHAN.P

DE CONVOLUTION USING MATLAB

Experiment No: - 04

AIM: - TO write a MATLAB program to compute deconvolution of two given sequences

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Read the input sequence x[n] ,and plot

Read the output sequence y[n] , and plot

Use the matlab function ‘deconv’

Deconvolve the two sequence and plot the result

MATLAB CODE:-

clc; clear all; close all; a=input('Enter the starting point of x[n]='); b=input('Enter the starting point of y[n]='); x=input('Enter the co-efficients of x[n]='); y=input('Enter the co-efficients of y[n]='); h=deconv(y,x); subplot(3,1,1); p=a:a+length(x)-1; stem(p,x); xlabel('TIME'); ylabel('AMPLITUDE'); grid on; title('INPUT x[n]'); subplot(3,1,2); q=b:b+length(y)-1; stem(q,y); xlabel('TIME'); ylabel('AMPLITUDE'); grid on; title('OUTPUT y[n]'); subplot(3,1,3); n=(b-a):(length(h)+b-a-1);

Page 14: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 14 JAFERKHAN.P

stem(n,h); xlabel('TIME'); ylabel('AMPLITUDE'); grid on; disp(h) title('IMPULSE h[n]');

FIGURE:-

SAMPLE INPUT:--

Enter the starting point of x[n]=0 Enter the starting point of y[n]=-1 Enter the co-efficients of x[n]=[1 2 3] Enter the co-efficients of y[n]=[1 3 6 5 3] 1 1 1

RESULTS :- Thus the program for de- convolution is written using MATLAB and verified.

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 20

1

2

3

TIME

AM

PLI

TUD

E

INPUT x[n]

-1 -0.5 0 0.5 1 1.5 2 2.5 30

2

4

6

TIME

AM

PLI

TUD

E

OUTPUT y[n]

-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 10

0.5

1

TIME

AM

PLI

TUD

E

IMPULSE h[n]

Page 15: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 15 JAFERKHAN.P

CIRCULAR CONVOLUTION USING MATLAB

Experiment No: - 05

AIM: - TO write a MATLAB program to compute circular convolution of two given sequences

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Read the input sequence x1[n] ,and plot

Read the input sequence x2[n] , and plot

Use the user defined matlab function ‘crconc’

Convolve the two sequence and plot the result

USER DEFINED FUNCTION:-

function y=crconc(x,h) n1=length(x); n2=length(h); N=max(n1,n2); x=[x,zeros(1,N-n1)]; h=[h,zeros(1,N-n2)]; for n=0:N-1; y(n+1)=0; for k=0:N-1; j= mod(n-k,N); y(n+1)=y(n+1)+x(k+1)*h(j+1); end end

Page 16: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 16 JAFERKHAN.P

MATLAB CODE:-

clc; clear all; close all; x=input('Enter the co-efficients of x1[n]='); h=input('Enter the co-efficients of x2[n]='); y=crconc(x,h); subplot(3,1,1); n=0:(length(x)-1); stem(n,x); grid on; xlabel('TIME'); ylabel('AMPLITUDE'); title('x1[n]'); subplot(3,1,2); n=0:(length(h)-1); stem(n,h); grid on; xlabel('TIME'); ylabel('AMPLITUDE'); title('x2[n]'); subplot(3,1,3); n=0:(length(y)-1); stem(n,y); grid on; disp(y) xlabel('TIME'); ylabel('AMPLITUDE'); title('OUTPUTx3[n]');

FIGURE:-

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 20

1

2

3

TIME

AM

PLI

TUD

E

x1[n]

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

1

2

TIME

AM

PLI

TUD

E

x2[n]

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 20

5

10

TIME

AM

PLI

TUD

E

OUTPUTx3[n]

Page 17: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 17 JAFERKHAN.P

SAMPLE INPUT:--

Enter the co-efficients of x1[n]=[1 2 3] Enter the co-efficients of x2[n]=[1 2 ] 7 4 7

RESULTS :- Thus the program for circular convolution is written using MATLAB and verified.

DIGITAL BUTTERWORTH LOW PASS FILTER

Experiment No: - 06(a)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital Butter worth Low pass filter PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the passband and stopband ripples Get the passband and stopband edge frequencies Calculate the order of the filter using ‘ buttord ’ function Find the filter coefficients, using ‘butter’ function Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; rp=input('enter the passband attenuation:'); rs=input('enter the stop band attenuation:'); wp=input('enter the pass band frequency:'); ws=input('enter the stop band frequency:'); [N,wn]=buttord(wp/pi,ws/pi,rp,rs); [b,a]=butter(N,wn); freqz(b,a);

Page 18: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 18 JAFERKHAN.P

FIGURE:-

SAMPLE INPUT:-

enter the passband attenuation:0.4 enter the stop band attenuation:30 enter the pass band frequency:0.2*pi enter the stop band frequency:0.4*pi

RESULTS:- Thus the magnitude response and phase response of Digital Butter worth Low pass filter was verified.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-600

-400

-200

0

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-400

-300

-200

-100

0

100

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 19: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 19 JAFERKHAN.P

DIGITAL BUTTERWORTH HIGH PASS FILTER

Experiment No: - 06(b)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital Butter worth High pass filter PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the passband and stopband ripples Get the passband and stopband edge frequencies Calculate the order of the filter using ‘ buttord ’ function Find the filter coefficients, using ‘butter’ function Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; rp=input ('Enter the pass band attenuation:'); rs=input ('Enter the stop band attenuation:'); wp=input ('Enter the pass band frequency:'); ws=input ('Enter the stop band frequency:'); [N,wn]=buttord(wp/pi,ws/pi,rp,rs); [b,a]=butter(N,wn,'high'); freqz(b,a);

FIGURE:-

SAMPLE INPUT:-

Enter the pass band attenuation:0.4 Enter the stop band attenuation:30 Enter the pass band frequency:0.6*pi Enter the stop band frequency:0.2*pi RESULTS:- Thus the magnitude response and phase response of Digital Butter worth High pass filter was verified 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-400

-300

-200

-100

0

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-200

-150

-100

-50

0

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 20: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 20 JAFERKHAN.P

DIGITAL BUTTERWORTH BAND PASS FILTER

Experiment No: - 06(C)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital Butter worth Band pass filter PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the passband and stopband ripples Get the passband and stopband edge frequencies Calculate the order of the filter using ‘ buttord ’ function Find the filter coefficients, using ‘butter’ function Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; rp=input('enter the passband attenuation:'); rs=input('enter the stop band attenuation:'); wp=input('enter the pass band frequency:'); ws=input('enter the stop band frequency:'); [N,wn]=buttord(wp/pi,ws/pi,rp,rs); [b,a]=butter(N,wn); freqz(b,a);

Page 21: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 21 JAFERKHAN.P

FIGURE:-

SAMPLE INPUT:-

enter the passband attenuation:0.2 enter the stop band attenuation:20 enter the pass band frequency:[0.2*pi,0.4*pi] enter the stop band frequency: [0.1*pi,0.5*pi]

RESULTS:- Thus the Amplitude response and phase response of Butter worth band pass filter was verified

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-800

-600

-400

-200

0

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-250

-200

-150

-100

-50

0

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 22: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 22 JAFERKHAN.P

DIGITAL BUTTERWORTH BAND STOP FILTER

Experiment No: - 06(a

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital Butter worth band stop filter PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the passband and stopband ripples Get the passband and stopband edge frequencies Calculate the order of the filter using ‘ buttord ’ function Find the filter coefficients, using ‘butter’ function Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; rp=input('enter the passband attenuation:'); rs=input('enter the stop band attenuation:'); wp=input('enter the pass band frequency:'); ws=input('enter the stop band frequency:'); [N,wn]=buttord(wp/pi,ws/pi,rp,rs); [b,a]=butter(N,wn,’stop’); freqz(b,a); FIGURE:-

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1500

-1000

-500

0

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-300

-200

-100

0

100

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 23: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 23 JAFERKHAN.P

SAMPLE INPUT:-

enter the passband attenuation:0.2 enter the stop band attenuation:20 enter the pass band frequency:[0.1*pi,0.5*pi] enter the stop band frequency:[0.2*pi,0.4*pi] RESULTS:- Thus the Amplitude response and phase response of Butter worth band stop filter was verified

Page 24: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 24 JAFERKHAN.P

DIGITAL CHEBYSHEV(TYPE-1) LOW PASS FILTER

Experiment No: - 07(a)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital Chebyshev type-1 Low pass filter PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the passband and stopband ripples Get the passband and stopband edge frequencies Calculate the order of the filter using ‘ cheb1ord ’ function Find the filter coefficients, using ‘cheby1’ function Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; rp=input ('Enter the pass band attenuation:'); rs=input ('Enter the stop band attenuation:'); wp=input ('Enter the pass band frequency:'); ws=input ('Enter the stop band frequency:'); [N,wn]=cheb1ord(wp/pi,ws/pi,rp,rs); [b,a]=cheby1(N,rp,wn); freqz(b,a); FIGURE:-

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-500

-400

-300

-200

-100

0

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-400

-300

-200

-100

0

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 25: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 25 JAFERKHAN.P

SAMPLE INPUT:-

Enter the pass band attenuation:20 Enter the stop band attenuation:50 Enter the pass band frequency:0.3*pi Enter the stop band frequency:0.4*pi RESULTS:- Thus the Amplitude response and phase response of chebyshev type 1 Low pass filter was verified

Page 26: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 26 JAFERKHAN.P

DIGITAL CHEBYSHEV(TYPE-1)HIGH PASS FILTER

Experiment No: - 07(b)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital Chebyshev type-1 high pass filter PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the passband and stopband ripples Get the passband and stopband edge frequencies Calculate the order of the filter using ‘ cheb1ord ’ function Find the filter coefficients, using ‘cheby1’ function Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; rp=input ('Enter the pass band attenuation:'); rs=input ('Enter the stop band attenuation:'); wp=input ('Enter the pass band frequency:'); ws=input ('Enter the stop band frequency:'); [N,wn]=cheb1ord(wp/pi,ws/pi,rp,rs); [b,a]=cheby1(N,rp,wn,'high'); freqz(b,a); FIGURE:-

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-400

-300

-200

-100

0

100

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-300

-200

-100

0

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 27: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 27 JAFERKHAN.P

SAMPLE INPUT:-

Enter the pass band attenuation:20 Enter the stop band attenuation:50 Enter the pass band frequency:0.4*pi Enter the stop band frequency:0.3*pi RESULTS:- Thus the Amplitude response and phase response of chebyshev type 1 high pass filter was verified

Page 28: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 28 JAFERKHAN.P

DIGITAL CHEBYSHEV(TYPE-1) BAND PASS FILTER

Experiment No: - 07(c)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital Chebyshev type-1 Band pass filter PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the passband and stopband ripples Get the passband and stopband edge frequencies Calculate the order of the filter using ‘ cheb1ord ’ function Find the filter coefficients, using ‘cheby1’ function Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; rp=input ('Enter the pass band attenuation:'); rs=input ('Enter the stop band attenuation:'); wp=input ('Enter the pass band frequency:'); ws=input ('Enter the stop band frequency:'); [N,wn]=cheb1ord(wp/pi,ws/pi,rp,rs); [b,a]=cheby1(N,rp,wn); freqz(b,a); FIGURE:-

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-800

-600

-400

-200

0

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-400

-300

-200

-100

0

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 29: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 29 JAFERKHAN.P

SAMPLE INPUT:-

Enter the pass band attenuation:20 Enter the stop band attenuation:98 Enter the pass band frequency:[0.3*pi,0.5*pi] Enter the stop band frequency:[0.1*pi,0.8*pi]

RESULTS:- Thus the Amplitude response and phase response of chebyshev type 1 band pass filter was verified

DIGITAL CHEBYSHEV(TYPE-1)BAND STOP FILTER

Experiment No: - 07(d)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital Chebyshev type-1 band stop filter PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the passband and stopband ripples Get the passband and stopband edge frequencies Calculate the order of the filter using ‘ cheb1ord ’ function Find the filter coefficients, using ‘cheby1’ function Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; rp=input('Enter the pass band attenuation:'); rs=input('Enter the stop band attenuation:'); wp=input('Enter the pass band frequency:'); ws=input('Enter the stop band frequency:'); [N,wn]=cheb1ord(wp/pi,ws/pi,rp,rs); [b,a]=cheby1(N,rp,wn,'stop'); freqz(b,a);

Page 30: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 30 JAFERKHAN.P

FIGURE:-

SAMPLE INPUT:-

Enter the pass band attenuation:20 Enter the stop band attenuation:98 Enter the pass band frequency:[0.1*pi,0.8*pi] Enter the stop band frequency:[0.3*pi,0.5*pi] RESULTS:- Thus the Amplitude response and phase response of chebyshev type 1 band stop pass filter was verified

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-800

-600

-400

-200

0

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-300

-200

-100

0

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 31: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 31 JAFERKHAN.P

DIGITAL CHEBYSHEV(TYPE-2) LOW PASS FILTER

Experiment No: - 08(a)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital Chebyshev type-2 Low pass filter PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the passband and stopband ripples Get the passband and stopband edge frequencies Calculate the order of the filter using ‘ cheb2ord ’ function Find the filter coefficients, using ‘cheby2’ function Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; rp=input ('Enter the pass band attenuation:'); rs=input ('Enter the stop band attenuation:'); wp=input ('Enter the pass band frequency:'); ws=input ('Enter the stop band frequency:'); [N,wn]=cheb2ord(wp/pi,ws/pi,rp,rs); [b,a]=cheby2(N,rp,wn); freqz(b,a); FIGURE:-

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-300

-200

-100

0

100

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-80

-60

-40

-20

0

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 32: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 32 JAFERKHAN.P

SAMPLE INPUT:-

Enter the pass band attenuation:20 Enter the stop band attenuation:70 Enter the pass band frequency:0.3*pi Enter the stop band frequency:0.4*pi RESULTS:- Thus the Amplitude response and phase response of chebyshev type 2 Low pass filter was verified

DIGITAL CHEBYSHEV(TYPE-2)HIGH PASS FILTER

Experiment No: - 08(b)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital Chebyshev type-2 high pass filter PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the passband and stopband ripples Get the passband and stopband edge frequencies Calculate the order of the filter using ‘ cheb2ord ’ function Find the filter coefficients, using ‘cheby2’ function Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; rp=input ('Enter the pass band attenuation:'); rs=input ('Enter the stop band attenuation:'); wp=input ('Enter the pass band frequency:'); ws=input ('Enter the stop band frequency:'); [N,wn]=cheb2ord(wp/pi,ws/pi,rp,rs); [b,a]=cheby2(N,rp,wn,'high'); freqz(b,a);

Page 33: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 33 JAFERKHAN.P

FIGURE:-

SAMPLE INPUT:-

Enter the pass band attenuation:20 Enter the stop band attenuation:70 Enter the pass band frequency:0.4*pi Enter the stop band frequency:0.3*pi RESULTS:- Thus the Amplitude response and phase response of chebyshev type 2 high pass filter was verified

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-100

0

100

200

300

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-80

-60

-40

-20

0

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 34: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 34 JAFERKHAN.P

DIGITAL CHEBYSHEV(TYPE-2) BAND PASS FILTER

Experiment No: - 08(c)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital Chebyshev type-2 Band pass filter PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the passband and stopband ripples Get the passband and stopband edge frequencies Calculate the order of the filter using ‘ cheb2ord ’ function Find the filter coefficients, using ‘cheby2’ function Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; rp=input ('Enter the pass band attenuation:'); rs=input ('Enter the stop band attenuation:'); wp=input ('Enter the pass band frequency:'); ws=input ('Enter the stop band frequency:'); [N,wn]=cheb2ord(wp/pi,ws/pi,rp,rs); [b,a]=cheby2(N,rp,wn); freqz(b,a);

Page 35: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 35 JAFERKHAN.P

FIGURE:-

SAMPLE INPUT:-

Enter the pass band attenuation:2 Enter the stop band attenuation:20 Enter the pass band frequency:[0.3*pi,0.4*pi] Enter the stop band frequency:[0.1*pi,0.5*pi] RESULTS:- Thus the Amplitude response and phase response of chebyshev type 2 band pass filter was verified

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-200

-100

0

100

200

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-50

-40

-30

-20

-10

0

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 36: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 36 JAFERKHAN.P

DIGITAL CHEBYSHEV(TYPE-2)BAND STOP FILTER

Experiment No: - 08(d)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital Chebyshev type-2 band stop filter PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the passband and stopband ripples Get the passband and stopband edge frequencies Calculate the order of the filter using ‘ cheb2ord ’ function Find the filter coefficients, using ‘cheby2’ function Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; rp=input('Enter the pass band attenuation:'); rs=input('Enter the stop band attenuation:'); wp=input('Enter the pass band frequency:'); ws=input('Enter the stop band frequency:'); [N,wn]=cheb2ord(wp/pi,ws/pi,rp,rs); [b,a]=cheby2(N,rp,wn,'stop'); freqz(b,a);

Page 37: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 37 JAFERKHAN.P

FIGURE:-

SAMPLE INPUT:-

Enter the pass band attenuation:2 Enter the stop band attenuation:20 Enter the pass band frequency:[0.1*pi,0.5*pi] Enter the stop band frequency:[0.3*pi,0.4*pi] RESULTS:- Thus the Amplitude response and phase response of chebyshev type 2 band stop pass filter was verified

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-200

-100

0

100

200

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-40

-30

-20

-10

0

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 38: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 38 JAFERKHAN.P

FIR LOW PASS FILTER USING HANNING WINDOW

Experiment No: - 09(a)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR LP filter using Hanning window

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the order of the filter Get the cut off frequency use ‘ fir1 ’& ‘hanning’ function to compute the filter coefficient Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N:'); wc=input('Enter cutoff frequency:'); h=fir1(N,wc/pi,hanning(N+1)); freqz(h); FIGURE:-

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-2000

-1500

-1000

-500

0

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-150

-100

-50

0

50

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 39: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 39 JAFERKHAN.P

SAMPLE INPUT:-

Enter the value of N:28 Enter cutoff frequency:0.5*pi RESULTS:- Thus the magnitude response and phase response of fir Low pass filter using hanning window was verified.

FIR HIGHPASS FILTER USING HANNING WINDOW

Experiment No: - 09(b)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR HP filter using Hanning window

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the order of the filter Get the cut off frequency use ‘ fir1 ’& ‘hanning’ function to compute the filter coefficient Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N:'); wc=input('Enter cutoff frequency:'); h=fir1(N,wc/pi,'high',hanning(N+1)); freqz(h);

Page 40: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 40 JAFERKHAN.P

FIGURE:-

SAMPLE INPUT:-

Enter the value of N:28 Enter cutoff frequency:0.5*pi RESULTS:- Thus the magnitude response and phase response of fir High pass filter using hanning window was verified.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1500

-1000

-500

0

500

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-150

-100

-50

0

50

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 41: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 41 JAFERKHAN.P

FIR BAND PASS FILTER USING HANNING WINDOW

Experiment No: - 09(c)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR BP filter using Hanning window

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the order of the filter Get the cut off frequency use ‘ fir1 ’& ‘hanning’ function to compute the filter coefficient Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N:'); wc=input('Enter cutoff frequency:'); h=fir1(N,wc/pi,hanning(N+1)); freqz(h); FIGURE:-

SAMPLE INPUT:-

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1500

-1000

-500

0

500

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-100

-50

0

50

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 42: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 42 JAFERKHAN.P

Enter the value of N:28 Enter cutoff frequency:[0.3*pi,0.7*pi] RESULTS:- Thus the magnitude response and phase response of fir band pass filter using hanning window was verified.

FIR BAND STOP FILTER USING HANNING WINDOW

Experiment No: - 09(d)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR BS filter using Hanning window

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the order of the filter Get the cut off frequency use ‘ fir1 ’& ‘hanning’ function to compute the filter coefficient Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N:'); wc=input('Enter cutoff frequency:'); h=fir1(N,wc/pi,’stop’,hanning(N+1)); freqz(h);

Page 43: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 43 JAFERKHAN.P

FIGURE:-

SAMPLE INPUT:-

Enter the value of N:28 Enter cutoff frequency:[0.2*pi,0.7*pi] RESULTS:- Thus the magnitude response and phase response of fir band stop filter using hanning window was verified.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1500

-1000

-500

0

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-150

-100

-50

0

50

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 44: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 44 JAFERKHAN.P

FIR LOW PASS FILTER USING HAMMING WINDOW

Experiment No: - 10(a)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR LP filter using Hamming window

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the order of the filter Get the cut off frequency use ‘ fir1 ’& ‘hamming’ function to compute the filter coefficient Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N:'); wc=input('Enter cutoff frequency:'); h=fir1(N,wc/pi,hamming(N+1)); freqz(h); FIGURE:-

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-2000

-1500

-1000

-500

0

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-150

-100

-50

0

50

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 45: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 45 JAFERKHAN.P

SAMPLE INPUT:-

Enter the value of N:28 Enter cutoff frequency:0.5*pi RESULTS:- Thus the magnitude response and phase response of fir Low pass filter using hamming window was verified.

FIR HIGHPASS FILTER USING HAMMING WINDOW

Experiment No: - 10(b)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR HP filter using Hanning window

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the order of the filter Get the cut off frequency use ‘ fir1 ’& ‘hamming’ function to compute the filter coefficient Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N:'); wc=input('Enter cutoff frequency:'); h=fir1(N,wc/pi,'high',hamming(N+1)); freqz(h);

Page 46: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 46 JAFERKHAN.P

FIGURE:-

SAMPLE INPUT:-

Enter the value of N:28 Enter cutoff frequency:0.5*pi RESULTS:- Thus the magnitude response and phase response of fir High pass filter using hamming window was verified.

FIR BAND PASS FILTER USING HAMMING WINDOW

Experiment No: - 10(c)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR BP filter using Hamming window

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the order of the filter Get the cut off frequency use ‘ fir1 ’& ‘hamming’ function to compute the filter coefficient Draw the magnitude and phase response

MATLAB CODE:-

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1500

-1000

-500

0

500

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-150

-100

-50

0

50

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 47: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 47 JAFERKHAN.P

clc; clear all; close all; N=input('Enter the value of N:'); wc=input('Enter cutoff frequency:'); h=fir1(N,wc/pi,hamming(N+1)); freqz(h); FIGURE:-

SAMPLE INPUT:-

Enter the value of N:28 Enter cutoff frequency:[0.3*pi,0.7*pi] RESULTS:- Thus the magnitude response and phase response of fir band pass filter using hamming window was verified.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1500

-1000

-500

0

500

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-100

-50

0

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 48: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 48 JAFERKHAN.P

FIR BAND STOP FILTER USING HAMMING WINDOW

Experiment No: - 10(d)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR BS filter using Hamming window

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the order of the filter Get the cut off frequency use ‘ fir1 ’& ‘hamming’ function to compute the filter coefficient Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N:'); wc=input('Enter cutoff frequency:'); h=fir1(N,wc/pi,’stop’,hamming(N+1)); freqz(h); FIGURE:-

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-2000

-1500

-1000

-500

0

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-100

-50

0

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 49: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 49 JAFERKHAN.P

SAMPLE INPUT:-

Enter the value of N:28 Enter cutoff frequency:[0.2*pi,0.7*pi] RESULTS:- Thus the magnitude response and phase response of fir band stop filter using hamming window was verified.

FIR LOW PASS FILTER USING BLACKMAN WINDOW

Experiment No: - 11(a)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR LP filter using blackman window

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the order of the filter Get the cut off frequency use ‘ fir1 ’& ‘blackman’ function to compute the filter coefficient Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N:'); wc=input('Enter cutoff frequency:'); h=fir1(N,wc/pi,blackman(N+1)); freqz(h);

Page 50: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 50 JAFERKHAN.P

FIGURE:-

SAMPLE INPUT:-

Enter the value of N:28 Enter cutoff frequency:0.5*pi RESULTS:- Thus the magnitude response and phase response of fir Low pass filter using blackman window was verified.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-2000

-1500

-1000

-500

0

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-150

-100

-50

0

50

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 51: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 51 JAFERKHAN.P

FIR HIGHPASS FILTER USING BLACKMAN WINDOW

Experiment No: - 11(b)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR HP filter using blackman window

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the order of the filter Get the cut off frequency use ‘ fir1 ’& ‘blackman’ function to compute the filter coefficient Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N:'); wc=input('Enter cutoff frequency:'); h=fir1(N,wc/pi,'high',blackman(N+1)); freqz(h); FIGURE:-

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-2000

-1000

0

1000

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-150

-100

-50

0

50

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 52: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 52 JAFERKHAN.P

SAMPLE INPUT:-

Enter the value of N:28 Enter cutoff frequency:0.5*pi RESULTS:- Thus the magnitude response and phase response of fir High pass filter using blackman window was verified.

FIR BAND PASS FILTER USING BLACKMAN WINDOW

Experiment No: - 11(c)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR BP filter using blackman window

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the order of the filter Get the cut off frequency use ‘ fir1 ’& ‘blackman’ function to compute the filter coefficient Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N:'); wc=input('Enter cutoff frequency:'); h=fir1(N,wc/pi,blackman(N+1)); freqz(h);

Page 53: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 53 JAFERKHAN.P

FIGURE:-

SAMPLE INPUT:-

Enter the value of N:28 Enter cutoff frequency:[0.3*pi,0.7*pi] RESULTS:- Thus the magnitude response and phase response of fir band pass filter using blackman window was verified.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-3000

-2000

-1000

0

1000

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-150

-100

-50

0

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 54: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 54 JAFERKHAN.P

FIR BAND STOP FILTER USING BLACKMAN WINDOW

Experiment No: - 11(d)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR BS filter using blackman window

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the order of the filter Get the cut off frequency use ‘ fir1 ’& ‘blackman’ function to compute the filter coefficient Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N:'); wc=input('Enter cutoff frequency:'); h=fir1(N,wc/pi,’stop’,blackman(N+1)); freqz(h); FIGURE:-

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-3000

-2000

-1000

0

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-150

-100

-50

0

50

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 55: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 55 JAFERKHAN.P

SAMPLE INPUT:-

Enter the value of N:28 Enter cutoff frequency:[0.2*pi,0.7*pi] RESULTS:- Thus the magnitude response and phase response of fir band stop filter using blackman window was verified.

FIR LOW PASS FILTER USING RECTANGULAR WINDOW

Experiment No: - 12(a)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR LP filter using rectangular window

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the order of the filter Get the cut off frequency use ‘ fir1 ’& ‘rectwin’ function to compute the filter coefficient Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N:'); wc=input('Enter cutoff frequency:'); h=fir1(N,wc/pi,rectwin(N+1)); freqz(h);

Page 56: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 56 JAFERKHAN.P

FIGURE:-

SAMPLE INPUT:-

Enter the value of N:28 Enter cutoff frequency:0.5*pi RESULTS:- Thus the magnitude response and phase response of fir Low pass filter using rectangular window was verified.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1500

-1000

-500

0

Normalized Frequency ( rad/sample)

Phas

e (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-100

-50

0

50

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 57: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 57 JAFERKHAN.P

FIR HIGHPASS FILTER USING RECTANGULAR WINDOW

Experiment No: - 12(b)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR HP filter using rectangular window

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the order of the filter Get the cut off frequency use ‘ fir1 ’& ‘rectwin’ function to compute the filter coefficient Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N:'); wc=input('Enter cutoff frequency:'); h=fir1(N,wc/pi,'high',rectwin(N+1)); freqz(h); FIGURE:-

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-1500

-1000

-500

0

500

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-100

-50

0

50

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 58: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 58 JAFERKHAN.P

SAMPLE INPUT:-

Enter the value of N:28 Enter cutoff frequency:0.5*pi RESULTS:- Thus the magnitude response and phase response of fir High pass filter using rectangular window was verified.

FIR BAND PASS FILTER USING RECTWIN WINDOW

Experiment No: - 12(c)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR BP filter using rectangular window

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the order of the filter Get the cut off frequency use ‘ fir1 ’& ‘rectwin’ function to compute the filter coefficient Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N:'); wc=input('Enter cutoff frequency:'); h=fir1(N,wc/pi,rectwin(N+1)); freqz(h);

Page 59: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 59 JAFERKHAN.P

FIGURE:

SAMPLE INPUT:-

Enter the value of N:28 Enter cutoff frequency:[0.3*pi,0.7*pi] RESULTS:- Thus the magnitude response and phase response of fir band pass filter using rectangular window was verified.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1500

-1000

-500

0

500

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-100

-50

0

50

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 60: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 60 JAFERKHAN.P

FIR BAND STOP FILTER USING RECTANGULAR WINDOW

Experiment No: - 12(d)

AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR BS filter using rectangular window

PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Get the order of the filter Get the cut off frequency use ‘ fir1 ’& ‘rectwin’ function to compute the filter coefficient Draw the magnitude and phase response

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N:'); wc=input('Enter cutoff frequency:'); h=fir1(N,wc/pi,’stop’,rectwin(N+1)); freqz(h); FIGURE:

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1500

-1000

-500

0

Normalized Frequency ( rad/sample)

Pha

se (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-100

-50

0

50

Normalized Frequency ( rad/sample)

Mag

nitu

de (d

B)

Page 61: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 61 JAFERKHAN.P

SAMPLE INPUT:-

Enter the value of N:28 Enter cutoff frequency:[0.2*pi,0.7*pi] RESULTS:- Thus the magnitude response and phase response of fir band stop filter using rectangular window was verified.

DISCRETE FOURIER TRANSFORM

Experiment No: - 13

AIM: - TO write a MATLAB program to find the DFT of a sequence PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Enter the input sequence x[n] Enter the length of sequence,N Use the matlab function ‘fft’ Plot the input and output sequence

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N'); x=input('Enter the input sequence X(n):'); t=0:N-1; subplot(2,1,1); stem(t,x); xlabel('TIME'); ylabel('AMPLITUDE'); title('INPUT SIGNAL'); grid on; y=fft(x,N)

Page 62: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 62 JAFERKHAN.P

subplot(2,1,2); stem(t,y); xlabel('TIME'); ylabel('AMPLITUDE'); title('OUTPUT SIGNAL'); grid on;

FIGURE:-

SAMPLE INPUT:-

Enter the value of N 4 Enter the input sequence X(n):[1 2 3 4] y = 10.0000 -2.0000 + 2.0000i -2.0000 -2.0000 - 2.0000i RESULTS:- Thus the program for dft is written using MATLAB and verified.

0 0.5 1 1.5 2 2.5 30

1

2

3

4

TIME

AM

PLI

TUD

E

INPUT SIGNAL

0 0.5 1 1.5 2 2.5 3-5

0

5

10

TIME

AM

PLIT

UDE

OUTPUT SIGNAL

Page 63: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 63 JAFERKHAN.P

INVERSE DISCRETE FOURIER TRANSFORM

Experiment No: - 14

AIM: - TO write a MATLAB program to find the IDFT of a sequence PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Enter the output sequence y[n] Enter the length of sequence,N Use the matlab function ‘ifft’ Plot the input and output sequence

MATLAB CODE:-

clc; clear all; close all; N=input('Enter the value of N='); y=input('Enter the sequence y[n]='); t=0:N-1; subplot(2,1,1); stem(t,y); xlabel('TIME'); ylabel('AMPLITUDE'); title('INPUT SIGNAL'); grid on; x=ifft(y,N) subplot(2,1,2); stem(t,x); xlabel('TIME'); ylabel('AMPLITUDE'); title('OUTPUT SIGNAL'); grid on;;

Page 64: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 64 JAFERKHAN.P

FIGURE:-

SAMPLE INPUT:-

Enter the value of N=4 Enter the sequence y[n]=[10 -2+2i -2 -2-2i] x = 1 2 3 4 RESULTS:- Thus the program for idft is written using MATLAB and verified.

0 0.5 1 1.5 2 2.5 3-5

0

5

10

TIME

AM

PLI

TUD

E

INPUT SIGNAL

0 0.5 1 1.5 2 2.5 30

1

2

3

4

TIME

AM

PLI

TUD

E

OUTPUT SIGNAL

Page 65: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 65 JAFERKHAN.P

LINEAR CONVOLUTION USING DFT

Experiment No: - 15

AIM: - TO write a MATLAB program to find the linear convolution of two sequence using PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Find the length of first sequence x[n] Find the length of second sequence h[n] Estimate the number of samples in the result of linear convolution If l1 <l2 pad enough no: of zeros to x[n] If l2 <l1 pad enough no: of zeros to h[n] Take the dft for modified x[n]and h[n] Compute Y[K]=X[k].*H[k] Compute y[n]=idft(Y[k]) Plot input and output sequences

MATLAB CODE:-

clc; clear all; close all; x=input('Enter the sequence x(n):'); h=input('Enter the sequence h(n):'); l1=length(x); l2=length(h); x=[x,zeros(1,l2-1)]; h=[h,zeros(1,l1-1)]; l3=length(x); c=0:l3-1; subplot(3,1,1); stem(c,x); grid on; xlabel('TIME'); ylabel('AMPLITUDE'); title('X(n)'); subplot(3,1,2);

Page 66: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 66 JAFERKHAN.P

stem(c,h); xlabel('TIME'); ylabel('AMPLITUDE'); grid on; title('h(n)'); q=fft(x,l3); r=fft(h,l3); s=(r).*q; y=ifft(s,l3) subplot(3,1,3); stem(c,y); xlabel('TIME'); ylabel('AMPLITUDE'); grid on; title('y(n)');

FIGURE:-

SAMPLE INPUT:-

Enter the sequence x(n):[1 2 3] Enter the sequence h(n):[1 1 1] t = 1.0000 3.0000 6.0000 5.0000 3.0000 RESULTS:- Thus the program for linear convolution using dft is written using MATLAB and verified.

0 0.5 1 1.5 2 2.5 3 3.5 40

1

2

3

TIME

AM

PLIT

UDE

X(n)

0 0.5 1 1.5 2 2.5 3 3.5 40

0.5

1

TIME

AM

PLI

TUD

E

h(n)

0 0.5 1 1.5 2 2.5 3 3.5 40

2

4

6

TIME

AM

PLIT

UDE

y(n)

Page 67: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 67 JAFERKHAN.P

CIRCULAR CONVOLUTION USING DFT

Experiment No: - 16

AIM: - TO write a MATLAB program to find the circular convolution of two sequence using dft method PROCEDURE:-

Open MATLAB Open new M-file Type the program Save in current directory Compile and Run the program For the output see command window\ Figure window

ALGORITHM:-

Find the length of first sequence x[n] Find the length of second sequence h[n] Estimate the number of samples in the result of circular convolution Take the dft for x[n]and h[n] Compute Y[K]=X[k].*H[k] Compute y[n]=idft(Y[k])

Plot input and output sequences

MATLAB CODE:-

clc; clear all; close all; x=input('Enter the sequence x(n):'); h=input('Enter the sequence h(n):'); l1=length(x); l2=length(h); a=0:l1-1; b=0:l2-1; l3=max(l1,l2); c=0:l3-1; subplot(3,1,1); stem(a,x); grid on; xlabel('TIME'); ylabel('AMPLITUDE'); title('X(n)'); subplot(3,1,2); stem(b,h); xlabel('TIME'); ylabel('AMPLITUDE');

Page 68: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 68 JAFERKHAN.P

grid on; title('h(n)'); q=fft(x,l3); r=fft(h,l3); s=(r).*q; t=ifft(s,l3) subplot(3,1,3); stem(c,t); xlabel('TIME'); ylabel('AMPLITUDE'); grid on; title('y(n)');

FIGURE:

SAMPLE INPUT:-

Enter the sequence x(n):[1 2 3] Enter the sequence h(n):[1 2 1 2] t = 8 10 8 10

RESULTS:- Thus the program for circular convolution using dft is written using MATLAB and verified.

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 20

1

2

3

TIME

AM

PLIT

UDE

X(n)

0 0.5 1 1.5 2 2.5 30

1

2

TIME

AM

PLI

TUD

E

h(n)

0 0.5 1 1.5 2 2.5 30

5

10

TIME

AM

PLIT

UDE

y(n)

Page 69: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 69 JAFERKHAN.P

INTRODUCTION TO THE TMS 320C6713

Page 70: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 70 JAFERKHAN.P

Page 71: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 71 JAFERKHAN.P

FUNCTIONAL OVERVIEW OF THE TMS 320C6713 DSK

Page 72: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 72 JAFERKHAN.P

CODE COMPOSER STUDIO The Code Composer Studio (CCS) provides an integrated development environment(IDE) to incorporate the software tools. CCS includes tools for code generation,such as a C compiler, an assembler, and a linker. It has graphical capabilitiesand supports real-time debugging. It provides an easy-to-use software tool to buildand debug programs. The C compiler compiles a C source program with extension .c to produce an assembly source file with extension.asm.The assembler assembles an.asm source file to produce a machine language object file with extension.obj.The linker combinesobject files and object libraries as input to produce an executable file with extension.out. This executable file represents a linked common object file format (COFF), popular in Unix-based systems and adopted by several makers of digital signal processors . This executable file can be loaded and run directly on the C6713 processor. To create an application project, one can “add” the appropriate files to the project. Compiler/linker options can readily be specified. A number of debugging features are available, including setting breakpoints and watching variables, viewing memory, registers, and mixed C and assembly code, graphing results, and monitoringexecution time. One can step through a program in different ways (step into, orover, or out).

Page 73: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 73 JAFERKHAN.P

Real-time analysis can be performed using real-time data exchange (RTDX) associated with DSP/BIOS .RTDX allows for data exchange between the host and the target and analysis in real time without stopping the target. Key statistics and performance can be monitored in real time. Through the Joint Team Action Group (JTAG), communication with on-chip emulation support occurs to control and monitor program execution. The C6713 DSK board includes a JTAG emulator interface.

BASIC OPERATION

Page 74: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 74 JAFERKHAN.P

LINEAR CONVOLUTION

Experiment No: - 01 AIM: - TO write a C- program to find linear convolution of given two sequences Procedure to Work on Code Composer Studio To create the New Project Project→ New (File Name. pjt, Eg: jafer.pjt) To create a Source file File →New→ Type the code (Save & give file name, Eg: jafer.c). To Add Source files to Project Project→ Add files to Project→ jafer.c To Add rts.lib file & Hello.cmd: Project→ Add files to Project→ rts6700.lib Library files: rts6700.lib (Path: c:\ti\c6000\cgtools\lib\ rts6700.lib) Note: Select Object& Library in (*.o,*.l) in Type of files Project→ Add files to Project→hello.cmd CMD file- Which is common for all non real time programs. (Path: c:\ti \ tutorial\dsk6713\hello1\hello.cmd) Note: Select Linker Command file (*.cmd) in Type of files Compile:- To Compile: Project→ Compile To Rebuild: project → rebuild, Which will create the final .out executable file. (Eg.jafer.out). Procedure to Lode and Run program: Load the Program to DSK: File→ Load program →jafer.out To Execute project: Debug → Run

Page 75: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 75 JAFERKHAN.P

PROGRAM:- #include<stdio.h> int m=6; int n=6; int i=0,j; int x[15]={1,2,3,4,5,6,0,0,0,0,0,0}; int h[15]={1,2,3,4,5,6,0,0,0,0,0,0}; int y[20]; main() { for(i=0;i<m+n-1;i++) { y[i]=0; for(j=0;j<=i;j++) y[i]+=x[j]*h[i-j]; } for(i=0;i<m+n-1;i++) printf("%d \n",y[i]); }

RESULTS:- Thus the C- Program for Linear convolution was written and the output was verified

OUTPUT:-

4 10 20 35 56 70 76 73 60 36

Page 76: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 76 JAFERKHAN.P

GRAPH PROPERTY

OUTPUT PLOT

Page 77: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 77 JAFERKHAN.P

Page 78: dspman

DSP LAB MANUAL COLLEGE OF ENGINEERING ,KOTTARAKKARA

DEPT:ECE 78 JAFERKHAN.P