Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

DSP LAB RECORD

By Abhishek kumar Jain Under guidance of Dr. Neetesh Purohit


Roll No : IEC2008030
30/04/2011

DSP LAB RECORD CONTENTS Experiments using MATLAB 1. 2. 3. 4. 5. 6. 7. 8. 9. Addition of two signals Multiplication of two signals Shifting of a signal Differentiation of a signal DFT of a signal IDFT of a signal Circular shifting of a signal Circular convolution of two signals Linear convolution using DFT (overlap-save method)

Experiments using DSP Kit 1. Linear convolution 2. LED blinking on DSP Kit

DSP LAB RECORD EXPERIMENT 1 ADDITION OF TWO SIGNALS AIM To write a program in MATLAB for addition of two signals. PROGRAM
function [y,n]=sigadd(x1,n1,x2,n2) n=min(min(n1),min(n2)):max(max(n1),max(n2)); y1=zeros(1,length(n)); y2=y1; y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; y=y1+y2;

This function sigadd can now be used to add two signals. Now make a script as follow:
n1=0:5; x1=2*n1; n2=3:8; x2=3*n2; [y,n]=sigadd(x1,n1,x2,n2) subplot(3,1,1) stem(n1,x1); axis([0 8 0 30]); title('input x1'); xlabel('n1'); ylabel('x1'); subplot(3,1,2); stem(n2,x2); axis([0 8 0 30]); title('input x2'); xlabel('n2'); ylabel('x2'); subplot(3,1,3);

DSP LAB RECORD


stem(n,y); axis([0 8 0 30]); title('output sum of x1 and x2 = y'); xlabel('n'); ylabel('y');

RESULT
input x1 30 20 10 0 0 1 2 3 4 n1 input x2 5 6 7 8

x1 x2

30 20 10 0 0 1 2 4 5 n2 output sum of x1 and x2 = y 3 6 7 8

30 20

y
10 0 0 1 2 3 4 n 5 6 7 8

DSP LAB RECORD EXPERIMENT 2 MULTIPLICATION OF TWO SIGNALS AIM To write a program in MATLAB for multiplication of two signals. PROGRAM
function [y,n]=sigmult(x1,n1,x2,n2) n=min(min(n1),min(n2)):max(max(n1),max(n2)); y1=zeros(1,length(n)); y2=y1; y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; y=y1.*y2;

This function sigmult can now be used to multiply two signals. Now make a script as follow:
n1=0:5; x1=2*n1; n2=3:8; x2=3*n2; [y,n]=sigmult(x1,n1,x2,n2) subplot(3,1,1) stem(n1,x1); axis([0 8 0 30]); title('input x1'); xlabel('n1'); ylabel('x1'); subplot(3,1,2); stem(n2,x2); axis([0 8 0 30]); title('input x2'); xlabel('n2'); ylabel('x2'); subplot(3,1,3);

DSP LAB RECORD


stem(n,y); axis([0 8 0 150]); title('output sum of x1 and x2 = y'); xlabel('n'); ylabel('y');

RESULT
input x1 30 20 10 0 0 1 2 3 4 n1 input x2 5 6 7 8

x1 x2

30 20 10 0 0 1 2 4 5 6 n2 output multiplication of x1 and x2 = y 3 7 8

150 100

y
50 0 0 1 2 3 4 n 5 6 7 8

DSP LAB RECORD EXPERIMENT 3 SHIFTING OF A SIGNAL AIM To write a program in MATLAB for shifting of a signal. PROGRAM
function[y,n]=sigshift(x,m,n0) n=m+n0; y=x;

This function sigshift can now be used to shift a signal. Now make a script as follow:
x=input('enter sequence'); m= input('enter index'); n0= input('enter the amount to be shifted'); [y,n]=sigshift(x,m,n0); subplot(2,1,1) stem(m,x); axis([0 (max(m)+n0) 0 max(x)]); title('input x'); xlabel('m'); ylabel('x'); subplot(2,1,2); stem(n,y); axis([0 (max(m)+n0) 0 max(x)]); title('output shifted version of x = y'); xlabel('n'); ylabel('y');

DSP LAB RECORD

RESULT
enter sequence [1 2 3 4 5 6 5 4 3 2] enter index [0 1 2 3 4 5 6 7 8 9] enter the amount to be shifted 4

input x 6

x
2 0 0

8 m output shifted version of x = y

10

12

y
2 0 0

6 n

10

12

DSP LAB RECORD EXPERIMENT 4 DIFFERENTIATION OF A SIGNAL AIM To write a program in MATLAB for Differentiation of a signal. PROGRAM
clf n=-10:110; z=(stepseq(0,-10,110)-stepseq(100,-10,110)); x=sin(pi*n/25).*z; subplot(2,1,1); stem(n,x); title('input signal'); xlabel('time'); ylabel('amplitude'); [y1,ny1]=sigshift(x,n,1); [y,ny]=sigadd(-y1,ny1,x,n); subplot(2,1,2); stem(ny,y) title('output signal'); xlabel('time'); ylabel('amplitude');

DSP LAB RECORD RESULT

input signal 1 0.5

amplitude

0 -0.5 -1 -20

20

40

60 time output signal

80

100

120

0.2 0.1

amplitude

0 -0.1 -0.2 -20

20

40 time

60

80

100

120

DSP LAB RECORD EXPERIMENT 5 DFT OF A SIGNAL AIM To write a program in MATLAB for computing dft of a signal. PROGRAM
function [Xk]=dft(xn,N) n=0:1:N-1; k=0:1:N-1; wn=exp(-j*2*pi/N); %Wn factor nk=n'*k; %Creats a N by N matrix nk wnnk=wn.^nk; %DFT Matrix Xk=xn*wnnk; %row vector for DFT coefficients

Now make a script as follow:


x=input('enter sequence'); N= input('enter the value of N'); xk=dft(x,N)

RESULT
enter sequence [1 2 3 4] enter the value of N 4 xk= 10 -2+2i -2 -2-2i

DSP LAB RECORD EXPERIMENT 6 IDFT OF A SIGNAL AIM To write a program in MATLAB for computing idft of a signal. PROGRAM
function [Xk]=idft(xn,N) n=0:1:N-1; k=0:1:N-1; wn=exp(j*2*pi/N); %Wn factor nk=n'*k; %Creats a N by N matrix nk wnnk=wn.^nk; %IDFT Matrix Xk=(xn*wnnk)/N; %row vector for IDFT coefficients

Now make a script as follow:


xk=input('enter sequence'); N= input('enter the value of N'); x=idft(x,N)

RESULT
enter sequence [10 -2+2i -2 -2-2i] enter the value of N 4 x= 1 2 3 4

DSP LAB RECORD EXPERIMENT 7 CIRCULAR SHIFTING OF A SIGNAL AIM To write a program in MATLAB for Circular shifting of a signal. PROGRAM
function y=cirshftt(x,m,N) x=[x zeros(1,N-length(x))]; n=[0:N-1]; n=mod(n-m,N); y=x(n+1);

Now make a script as follow:


n=0:10; x=10*(0.8).^n; y=cirshftt(x,6,15) n=0:14; x=[x zeros(1,4)]; subplot(2,1,1); stem(n,x); title('input signal'); xlabel('time'); ylabel('amplitude'); subplot(2,1,2); stem(n,y); title('output shifted version of input signal'); xlabel('time'); ylabel('amplitude');

DSP LAB RECORD RESULT


input signal 10

amplitude

10

12

14

time output shifted version of input signal 10

amplitude

6 time

10

12

14

DSP LAB RECORD EXPERIMENT 8 CIRCULAR CONVOLUTION OF TWO SIGNALS AIM To write a program in MATLAB for Circular convolution of two signals. PROGRAM
function y=circonvt(x1,x2,N) x1=[x1 zeros(1,N-length(x1))]; x2=[x2 zeros(1,N-length(x2))]; m=0:N-1; x2=x2(mod(-m,N)+1) H=zeros(N,N); for n=1:N H(n,:)=cirshftt(x2,n-1,N); end H y=x1*H';

Now make a script as follow:


x1=input('enter sequence1'); x2=input('enter sequence2'); y=circonvt(x1,x2,max(length(x1),length(x2)))

RESULT
enter sequence1 [1 2 2] enter sequence2 [1 2 3 4] output y=[15 12 9 14]

DSP LAB RECORD EXPERIMENT 9 LINEAR CONVOLUTION USING DFT (OVERLAP-SAVE METHOD) AIM To write a program in MATLAB for computing linear convolution using DFT. PROGRAM
function y=ovrlpsav(x,h,N) lenx=length(x); M=length(h); M1=M-1; L=N-M1; h=[h zeros(1,N-M)]; x=[zeros(1,M1),x,zeros(1,N-1)]; K=floor((lenx+M1-1)/L); Y=zeros(K+1,N); for k=0:K xk=x(k*L+1:k*L+N); Y(k+1,:)= idft((dft(xk,N).*dft(h,N)),N); end Y=Y(:,M:N)'; y=(Y(:))';

Now make a script as follow:


x=input('enter sequence1'); h=input('enter sequence2'); N=input('enter the value of N'); y=ovrlpsav(x,h,N)

RESULT
enter sequence1 [1 2 2] enter sequence2 [1 2 3 4] enter the value of N 4 output y=[1 4 9 14 14 8]

DSP LAB RECORD

EXPERIMENT 1 LINEAR CONVOLUTION USING CODE COMPOSER STUDIO AIM To implement linear convolution using Code Composer Studio. PROGRAM
#include<stdio.h> #define LEN1 3 #define LEN2 4 int x[LEN1+LEN2-1]={1,2,2,0,0,0}; int h[LEN1+LEN2-1]={1,2,3,4,0,0}; int y[LEN1+LEN2-1]; main() { int i=0,j; for(i=0;i<LEN1 + LEN2-1;i++) { y[i]=0; for(j=0;j<=i;j++) { y[i]+=x[j]*h[i-j]; } } for(i=0;i<LEN1 + LEN2-1;i++) { printf("%d\n",y[i]); } }

RESULT
The convoluted sequence is obtained as 1 4 9 14 14 8

DSP LAB RECORD

EXPERIMENT 2 LED BLINKING USING CODE COMPOSER STUDIO AIM To run the code of LED blinking using Code Composer Studio and DSP Kit. PROGRAM
#include "ledcfg.h" #include "dsk6713.h" #include "dsk6713_led.h" #include "dsk6713_dip.h" void main() { DSK6713_init(); /* Initialize the LED and DIP switch modules of the BSL */ DSK6713_LED_init(); DSK6713_DIP_init(); while(1) {

/* Toggle LED #0 */ DSK6713_LED_toggle(0); /* Check DIP switch #3 and light LED #3 accordingly, 0 = switch pressed */

DSP LAB RECORD


if (DSK6713_DIP_get(3) == 0) /* Switch pressed, turn LED #3 on */ DSK6713_LED_on(3); else /* Switch not pressed, turn LED #3 off */ DSK6713_LED_off(3);

/* Spin in a software delay loop for about 200ms */ DSK6713_waitusec(200000); } }

RESULT
LED start blinking on DSP KIT.

You might also like