Professional Documents
Culture Documents
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);
RESULT
input x1 30 20 10 0 0 1 2 3 4 n1 input x2 5 6 7 8
x1 x2
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);
RESULT
input x1 30 20 10 0 0 1 2 3 4 n1 input x2 5 6 7 8
x1 x2
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');
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
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');
amplitude
0 -0.5 -1 -20
20
40
80
100
120
0.2 0.1
amplitude
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
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
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);
amplitude
10
12
14
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';
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(:))';
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]
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
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 */
RESULT
LED start blinking on DSP KIT.