0% found this document useful (0 votes)
41 views32 pages

DSP 5th Sem File

Uploaded by

ielaishane1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views32 pages

DSP 5th Sem File

Uploaded by

ielaishane1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DIGITAL SIGNAL PROCESSING LAB (LCECE325-G)

DIGITAL SIGNAL PROCESSING LAB

FILE (LCECE325-G)

ECE Vth SEMESTER

SUBMITTED BY: ……………………….. SUBMITTED TO:………………………………….

ROLL NO:……………………………… ………………………………..

Department Of Electronics & Communication Engg


SAT KABIR INSTITUTE OF TECH & MGMT
LADRAWAN,BAHADURGARH
1
DIGITAL SIGNAL PROCESSING LAB (LCECE325-G)

INDEX

S.NO NAME OF EXPERIMENT SIGNATURE

1. To present basic signals(unit step, unit impulse, ramp, exponent, sine and
cosine)

2. To develop a program for discrete convolution.

3. To develop a program for discrete correlation

4. To design Infinite Impulse Response (low pass filter) filter with cut of
frequency of 4000 HZ .

5. To Design Finite Impulse Response.(FIR filter)

6. To develop program for interpolation and decimation of sequences.

7. Implementation of FFT of given sequence

8. To find DFT / IDFT of given DT signal

9. To find the z-transform & inverse z-transform of a expression

10. To develop program for Circular Convolution

2
DIGITAL SIGNAL PROCESSING LAB (LCECE325-G)

EXPERIMENT NO. 1

AIM:-To present basic signals(unit step, unit impulse, ramp, exponent, sine and cosine)

PROGRAM:-
** for unit step, unit impulse, ramp and exponent
clc;
clear all; close
all;
n=[0:0.5:20];
x=input('enter value of x');
y=exp(x*n); subplot(2,2,1);
stem(n,y);
xlabel ('x');
ylabel ('exponent');
title('expo1');
%clc;
%clear all;
%close all;
n=[0:0.5:20];
a=input('enter value of a');
y=(a).^n;
subplot(2,2,2);
stem(n,y);
xlabel('a');
ylabel('exponent');
title('expo2');
%clc;
%clear all;
3
%close all;
n=[0:0.5:20];
subplot(2,2,3);
stem(n,n);
xlabel('x');
ylabel('y');
title('unit ramp');
%clc;
%clearall;
%close all;
t=[-3:1:2];
n1=[zeros(1,3),ones(1,1),zeros(1,2)];
subplot(2,2,4);
stem(t,n1);
xlabel('x');
ylabel('y'); title('unit
impulse');

**for sine and cosine


clc;
clear all;
close all;
t=[0:0.1:pi];
y=cos(2*pi*t);
subplot(2,2,1);
stem(t,y);
xlabel('t');
ylabel('coz');
title('cos(2pit)');
%clc;
%clear all;
%close all;
t=[0:0.1:pi];
y=sin(2*pi*t);
subplot(2,2,2);

4
stem(t,y);
xlabel('t');
ylabel('sin');
title('sin(2pit)');

OUTPUT:-

5
6
EXPERIMENT NO. 2

AIM:-To develop a program for discrete convolution.

PROGRAM:-
clc, clear
all;
closeall;
x=[1 2 35];
h=[2 3 56];
y=conv(x,h);
subplot(3,1,1);
stem(x); xlabel('x');
ylabel('amplitude');
title('x sequence');
subplot(3,1,2);
stem(h); xlabel('h');
ylabel('amplitude');
title('h sequence');
subplot(3,1,3);
stem(y); xlabel('y');
ylabel('amplitude');
title('ysequence');

7
OUTPUT:-

8
DIGITAL SIGNAL PROCESSING LAB (LCECE325-G)

EXPERIMENT NO. 3

AIM:-To develop a program for discrete correlation

PROGRAM:-
clc, clear
all;
closeall;
x=[1 2 35];
h=[2 3 56];
y=xcorr(x,h);
subplot(3,1,1);
stem(x); xlabel('x');
ylabel('amplitude');
title('x sequence');
subplot(3,1,2);
stem(h); xlabel('h');
ylabel('amplitude');
title('h sequence');
subplot(3,1,3);
stem(y); xlabel('y');
ylabel('amplitude');
title('ysequence');

9
DIGITAL SIGNAL PROCESSING LAB (LCECE325-G)

OUTPUT:-

10
DIGITAL SIGNAL PROCESSING LAB (LCECE325-G)

EXPERIMENT NO. 4
AIM :To design Infinite Impulse Response (low pass filter) filter with cut of frequency of 4000hz .

PROGRAM :
#include"dsk6713.h" //this file is added to initialize the DSK6713
#include"dsk6713_aic23.h"
Uint32 fs = DSK6713_AIC23_FREQ_8KHZ; // set the sampling frequency, Different sampling frequencies
supported by AIC23 codec are 8, 16, 24, 32,
44.1, 48, and
96 kHz.

// FILTER COFFICIENTS IS CALCULATED BY MATLAB

float fc []={
2.338110787e-019,6.936318823e-005,-0.0003181171778,0.0008399875951,
- 0.001779771759,0.003340889933,-0.005792469252,0.00948059652,-
0.01485389285,
0.02252536267,-0.03342207149, 0.04916161299, -0.07310581207,
0.1139752045,
- 0.2039434612, 0.6338219047, 0.6338219047, -0.2039434612,0.1139752045,
- 0.07310581207, 0.04916161299, -0.03342207149, 0.02252536267, -
0.01485389285,
0.00948059652, -0.005792469252, 0.003340889933,-
0.001779771759,0.0008399875951,
- 0.0003181171778, 6.936318823e-005,2.338110787e-019
};

static short in_buffer[18] ;


void main( )
11
{

comm_intr(); // ISR function is called, using the givencommand


while(1); // program execution halts and it starts listening for the
interrupt which occur at everysampling
period Ts.
}
interrupt voidc_int11() // ISR call, At each Interrupt, program execution goes to
the interrupt service routine
{
Uint32indata; //variable declaration
inti=0;
signedint output=0;

indata= input_sample(); //newest input @ top ofbuffer


in_buffer[0]=indata; //new input at buffer[0]

for(i=17;i>=0;i--)
in_buffer[i] =in_buffer[i-1]; //shuffle thebuffer

for(i=0;i<18;i++)
output = output + fc[i] * in_buffer[i];

output_sample(output); //output filter,the value in the buffer yn indexedby


the variable loop is written on to the codec.
}

12
DIGITAL SIGNAL PROCESSING LAB (LCECE325-G)

OUTPUT :

13
DIGITAL SIGNAL PROCESSING LAB (LCECE325-G)

EXPERIMENT NO. 5
AIM :To Design Finite Impulse Response.

FIR filter:

lowpass 1500 Hz, High pass,2200hz, Bandpass 1750 Hz, Band stops 790 Hz.

PROGRAM :

#include"DSK6713_AIC23.h" //this file is added to initialize the DSK6713

#include"lowp1500.cof" // coefficient of low-pass filter file calculatedfrom

MATLAB

#include"highp2200.cof" // coefficient of high-pass filter file calculated from

MATLAB

#include"bpass1750.cof" // coefficient of band-pass filter file calculatedfrom

MATLAB

#include"bstop790.cof" // coefficient of band-stop filter file calculated from

MATLAB

Uint32fs=DSK6713_AIC23_FREQ_8KHZ; // set the sampling frequency, Differentsampling

Frequencies supported by AIC23 codec are 8, 16,

24, 32, 44.1, 48, and 96 kHz.

14
shortFIR_number=0; //filter number

intyn = 0; //variable declaration

shortdly[N]; //declare delay buffer of n values


shorth[4][N]; //co-efficients of 4 different filters

interruptvoidc_int11() // ISR call, At each Interrupt, program execution goes to

the interrupt serviceroutine

shorti; //variable declaration

dly[0]= input_sample(); //newest input @ top of buffer

yn = 0; //initialize filteroutput

for (i = 0; i<N;i++) //for loop takes in the value of i from 0 to N yn

+=(h[FIR_number][i]*dly[i]); //y(n) +=h(LP#,i)*x(n-i)

for (i = N-1; i>0;i--) //starting @ bottom ofbuffer

dly[i] = dly[i-1]; //update delays with datamove

output_sample(yn>>15); //output filter,the value in the buffer yn indexedby

the variable loop is written on to the codec.

15
return; // program execution goes back to while(1) and then

again starts listening for next interrupt and this

process goes on

}
void main()

shorti; //variabledeclaration

for (i=0;i<N;i++) //for loop which takes in the value of i from 0 toN=4

and switches to corresponding filter co-efficients

dly[i] = 0; //init buffer

h[0][i] = hlp[i]; //start addr of lp1500 coeff

h[1][i] = hhp[i]; //start addr of hp2200 coeff

h[2][i] = hbp[i]; //start addr of bp1750 coeff

h[3][i] = hbs[i]; //start addr of bs790 coeff

comm_intr(); // ISR function is called, using thegiven

command

while(1); //program execution halts and it starts listening for

the interrupt which occur at every sampling

period Ts.

16
17
DIGITAL SIGNAL PROCESSING LAB (LCECE325-G)

OUTPUT :

18
DIGITAL SIGNAL PROCESSING LAB (LCECE325-G)

EXPERIMENT NO. 6
AIM :program to verify the decimation and interpolation of given sequence.

PROGRAM for Decimation:


PROGRAM:
Clc;
Clear all;
Close all;
D=input('enter the downsampling factor');
L=input('enter the length of the input signal');
f1=input('enter the frequency of first sinusodal');
f2=input('enter the frequency of second sinusodal');
n=0:L-1;
x=sin(2*pi*f1*n)+sin(2*pi*f2*n);
y=decimate(x,D,'fir');
subplot(2,1,1);
stem(n,x(1:L));
title('input sequence');
xlabel('time(n)');
ylabel('amplitude');
subplot(2,1,2)
m=0:(L/D)-1;
stem(m,y(1:L/D));
title('Decimated sequence');
xlabel('time(n)');
ylabel('amplitude'DIGITAL SIGNAL PROCESSING LAB (LCECE325-G)

19
INPUT :

enter the downsampling factor = 5


enter the length of the input signal = 100
enter the frequency of first sinusoidal = 0.01
enter the frequency of second sinusoidal = 0.0

OUTPUT :

20
PROGRAM for Interpolation:

Clc;
Clear all;
Close all;
L=input('enter the upsampling factor');
N=input('enter the length of the input signal'); % Length should be greater than 8
f1=input('enter the frequency of first sinusodal');
f2=input('enter the frequency of second sinusodal');
n=0:N-1;
x=sin(2*pi*f1*n)+sin(2*pi*f2*n);
y=interp(x,L);
subplot(2,1,1)
stem(n,x(1:N))
title('input sequence');
xlabel('time(n)');
ylabel('amplitude');
subplot(2,1,2)
m=0:N*L-1;
stem(m,y(1:N*L))
title('output sequence ');
xlabel('time(n)');
ylabel('amplitude');

INPUT:

enter the upsampling factor = 5


enter the length of the input signal = 9
enter the frequency of first sinusoidal = 0.1
enter the frequency of second sinusoidal = 0.3

Output Waveforms:

21
22
EXPERIMENT NO. 7
AIM :Implementation of FFT of a given sequence.

PROGRAM:
%MATLAB program to plot the frequency response (magnitude and phase response)of
agiven difference equation.
clc;
clear all;
b=input('Enter the numerator coefficients:');
a=input('Enter the denominator coefficients:');
[h,w]=freqz(b,a);
subplot(2,1,1);
plot(w/pi,abs(h));
grid;
xlabel('Normalised Frequency');
ylabel('Magnitude in dB');
title('Magnitude Response');
subplot(2,1,2);
plot(w/pi,angle(h));
grid;
xlabel('Normalised Frequency');
ylabel('phase in radians');
title('Phase Response');

Output:
Enter the numerator coefficients: [1]
Enter the denominator coefficients: [1 -1/6 -1/6]

23
Output Waveforms:

24
EXPERIMENT NO. 8
AIM :To find DFT / IDFT of given DT signal.
PROGRAM:

clc;
close all;
clear all;
xn=input('Enter the sequence x(n)'); %Get the sequence from user
ln=length(xn); %find the length of the sequence
xk=zeros(1,ln); %initialize an array of same size as that of input sequence
ixk=zeros(1,ln); %initialize an array of same size as that of input sequence
%DFT of the sequence
%-----------------------------------------------------
for k=0:ln-1
for n=0:ln-1
xk(k+1)=xk(k+1)+(xn(n+1)*exp((i)*2*pi*k*n/ln));
end
end
%------------------------------------------------------
%Plotting input sequence
%-----------------------------------------------------
t=0:ln-1;
subplot(221);
stem(t,xn);
ylabel ('Amplitude');
xlabel ('Time Index');
title('Input Sequence');
%---------------------------------------------------------------

magnitude=abs(xk); % Find the magnitudes of individual DFT points


% plot the magnitude response
%------------------------------------------------------------
t=0:ln-1;
subplot(222);
stem(t,magnitude);
ylabel ('Amplitude');
xlabel ('K');
title('Magnitude Response');
%------------------------------------------------------------
phase=angle(xk); % Find the phases of individual DFT points % plot the magnitude

25
sequence
%------------------------------------------------------------
t=0:ln-1;
subplot(223);
stem(t,phase);
ylabel ('Phase');
xlabel ('K');
title ('Phase Response');

%------------------------------------------------------------
%IDFT of the sequence
%------------------------------------------------------------
for n=0:ln-1
for k=0:ln-1
ixk(n+1)=ixk(n+1)+(xk(k+1)*exp(i*2*pi*k*n/ln));
end
end
ixk=ixk./ln;
%------------------------------------------------------------
%code block to plot the input sequence
%------------------------------------------------------------
t=0:ln-1;
subplot(224);
stem(t,ixk);
ylabel ('Amplitude');
xlabel ('Time Index');
title ('IDFT sequence');
%------------------------------------------------------

Output:
Xn=[1 2 3 4 5]
Xk = 15,-2.50+3.44i,-2.50+0.81i,-2.49-0.81i,-2.49-3.44i

26
Output Waveforms:

27
EXPERIMENT NO. 9

AIM :TO FIND THE Z-TRANSFORM & INVERSE Z-TRANSFORM OF A


EXPRESSION

Program:

%X(n) = [1/16n ]u(n)

syms z n

a=ztrans(1/16^n)

% X(Z) = 3*Z / (Z+1)

syms Z n

y=iztrans(3*Z/(Z+1))

Result:

a = 16*z/(16*z-1)

y= 3*(-1)^n

28
EXPERIMENT NO. 10

AIM: To develop program for Circular Convolution


ALGORITHM:
Step 1: Start
Step 2: Read the first sequence
Step 3: Read the second sequence
Step 4: Find the length of the first sequence
Step 5: Find the length of the second sequence
Step 6: Perform circular convolution MatLab for both the sequences using inbuilt function
Step 7: Plot the axis graph for sequence
Step 8: Display the output sequence
Step 9: Stop

clc;

close all;

clear all;

x1=input('Enter the first sequence :

');

x2=input('Enter the second sequence

: ');

N1=length(x1);

N2=length(x2);

N=max(N1,N2);

29
if(N2>N1)

x4=[x1,zeros(1,N-N1)];

x5=x2;

elseif(N2==N1)

x4=x1;

x5=x2;

else

x4=x1;

x5=[x2,zeros(1,N-N2)];

end

x3=zeros(1,N);

for m=0:N-1

x3(m+1)=0;

for n=0:N-1

j=mod(m-n,N);

x3(m+1)=x3(m+1)+x4(n+1).*x5(j+1);

end

end

subplot(4,1,1)

30
stem(x1);

title('First Input Sequence');

xlabel('Samples');

ylabel('Amplitude');

subplot(4,1,2)

stem(x2);

title('Second Input Sequence');

xlabel('Samples');

ylabel('Amplitude');

subplot(4,1,3)

stem(x3);

title('Circular Convolution Using

Modulo Operator');

xlabel('Samples');

ylabel('Amplitude');

%In built function

y=cconv(x1,x2,N);

subplot(4,1,4)

stem(y);

title('Circular Convolution using

31
Inbuilt Function');

xlabel('Samples');

ylabel('Amplitude');

32

You might also like