DSP IPCC _ 21EC42 and AEC_21EC483
DSP IPCC _ 21EC42 and AEC_21EC483
* Demonstrate the DSP concepts on signal generation and sampling using Scilab/Octave
* Design and verify the computation of discrete signals using Scilab/Octave.
* Demonstrate and verify the application of FFT/DFT algorithm for a given signal using
Scilab/Octave.
* Design and demonstrate programs to evaluate different types of low and high pass FIR
filters using Scilab/Octave.
* Design, demonstrate and visualize different real world signals using Scilab/Octave
programs.
Digital Signal Processing Integrated Professional Core Course (IPCC)
Output:
Output:
Output:
Output:
// Generation of Sine waveform
clc;
clear;
close();
sig_freq=input("enter the frequency of the signal");
//or sig_freq=5
t=0:0.001:1;
y=sin(2*%pi*sig_freq*t);
//subplot(211);
plot2d(t,y);// Continuous plot, [plot2d3(t,y) for discrete plot];
xlabel("time");
ylabel("Amplitude");
title("Input Signal");
Output:
enter the frequency of the signal 3
Output:
enter the frequency of the signal 4
Statement:
clc;
clear;
close();
t=0:0.001:1;
y=sin(2*%pi*sig_freq*t);
subplot(411);
plot2d(t,y);
xlabel("time");
ylabel("Amplitude");
title("Input Signal");
samp_instant=1/samp_freq;
n=0:samp_instant:1;
yn=sin(2*%pi*sig_freq*n);
subplot(412);
plot2d3(n,yn);
xlabel("time");
ylabel("Amplitude");
title("Sampled Signal");
ni=0:samp_instant/L:1;
yni=interp1(n,yn,ni,'linear');
subplot(413);
plot2d3(ni,yni);
xlabel("time");
ylabel("Amplitude");
title("Interpolated Signal");
subplot(414);
plot2d(ni,yni);
xlabel("time");
ylabel("Amplitude");
title("Reconstructed Signal");
Output:
enter the frequency of the signal 5
fs > 2 fm
fs = 2fm
enter the frequency of the signal 15
fs < 2fm
2. Determine linear convolution, Circular convolution and Correlation
of two given sequences. Verify the result using theoretical
computations.
// Program to compute the Linear convolution of two sequences
without using the built-in function conv()
clc;
clear;
close();
length_x=length(x);
length_h=length(h);
length_y=length_x+length_h-1;
a=[x,zeros(1,length_h)];
b=[h,zeros(1,length_x)];
y=zeros(1,length_y);
for i=1:length_y
y(i)=0;
for j=1:i
y(i)=y(i)+a(j)*b(i-j+1)
end
end
clc;
clear;
close();
length_x=length(x);
length_h=length(h);
for i=1:N
y(i)=0;
for j=1:N
y(i)=y(i)+a(j)*b(pmodulo(i-j,N)+1);
end
end
disp('The circular convolution using formula');
disp(y);
Output:
Enter the first sequence [1 2 3]
Enter the second sequence [1 2 3]
"The circular convolution using formula"
13.
13.
10.
//To perform cross correlation and auto correlation
clc;
clear;
close();
length_x1=length(x1);
length_x2=length(x2);
length_y=length_x1+length_x2-1;
x2_inv=x2(length_x2:-1:1);
a=[x1,zeros(1,length_x2)];
b=[x2_inv,zeros(1,length_x1)];
y=zeros(1,length_y);
for i=1:length_y
y(i)=0;
for j=1:i
y(i)=y(i)+a(j)*b(i-j+1)
end
end
Output:
6. + 0.i -0.809017 - 3.6654688i 0.309017 + 1.677599i 0.309017 - 1.677599i -
0.809017 + 3.6654688i
15. + 0.i 0.690983 - 8.2819941i 1.809017 + 2.7674128i 1.809017 - 2.7674128
0.690983 + 8.2819941i
90. + 0.i -30.916408 + 4.1674973i -4.0835921 + 3.8899828i -4.0835921 -
3.8899828i -30.916408 - 4.1674973i
4. 13. 28. 27. 18.
4. 13. 28. 27. 18.
4. Determine the correlation using FFT algorithm. Verify the result
using theoretical computations
clc;
clear all;
close;
x1=[1 2 3];//x=input('enter the ist sequence');
h1=[4 5 6];//h=input('enter the 2nd sequence');
h1i=[6 5 4];
m=length(x1);
n=length(h1);
N=n+m-1;
x=[x1 zeros(1,N-m)];
h=[h1i zeros(1,N-n)];
f1=fft(x); disp(f1);
f2=fft(h); disp(f2);
f3=f1.*f2; disp(f3); // freq domain main multiplication
f4=ifft(f3); disp(f4);
f5=xcorr(x1,h1); //using buitin function for verification
disp(f5);
Output:
6. + 0.i -0.809017 - 3.6654688i 0.309017 + 1.677599i 0.309017 - 1.677599i
-0.809017 + 3.6654688i
t=-2:0.1:2;
y=[zeros(1,length(t)/4),ones(1,length(t)/4),ones(1,length(t)/4),zeros(1,len
gth(t)/4+1)]
subplot(2,1,1);
plot2d(t,y,2);
title('Rectangular Pulse');
//a=gca(); a.x_location="origin"; a.y_location="origin";
a.children.children(1).thickness=2;
y=[y,zeros(1,512-length(y))];
N=length(y);
Y=abs(fft(y));
f=-N/2:N/2-1;
subplot(2,1,2);
plot2d(f,fftshift(Y),2);
title('DFt of Rectangular Pulse');
//a=gca(); a.x_location="origin"; a.y_location="origin";
a.children.children(1).thickness=2;
Output:
6. Design and test FIR filter using Windowing method (Hamming,
Hanning and Rectangular window) for the given order and cut-off
frequency.
//Design a lowpass FIR filter for the following specifications:
//Pass band edge frequency = 1850 Hz
//Stop band edge frequency = 2150 Hz
//Stopband attenuation = 20 db
//Sampling rate= 8000Hz
clc;
clear;
close();
fp=1850;
fs=2150;
fsamp=8000;
hn=wfir('lp',N,fp/fsamp,'re',[0,0]);
M=1024;
hn=[hn,zeros(1,M-length(hn))]; //Zero padding for computing 1024
point DFT
H= fft(hn);
H_mag =20*log10(abs(H));
H_ang = atan(imag(H),real(H));
H_phase = (unwrap(H_ang))*180/%pi;
f =(0:M/2-1).*( fsamp/M);
subplot(2,1,1);
plot2d(f,H_mag (1:M/2),5);
xtitle('Magnitude response' ,'w(Hz)','Magnitude (dB)');
a=gca();
a.children.children(1).thickness=2;
subplot(2,1,2);
plot2d(f,H_phase(1:M/2),2);
xtitle ('Phase response' , 'w(Hz)' , 'Phase(Deg)');
a=gca();
a.children.children(1).thickness=2;
Output:
//Design a high pass FIR filter for the following specifications:
clc;
clear;
close();
fp=2500;
fs=1500;
fsamp=8000;
hn=wfir('hp',N,fp/fsamp,'hn',[0,0]);
M=1024;
hn=[hn,zeros(1,M-length(hn))]; //Zero padding for computing 1024
point DFT
H= fft(hn);
H_mag =20*log10(abs(H));
H_ang = atan(imag(H),real(H));
H_phase = (unwrap(H_ang))*180/%pi;
f =(0:M/2-1).*( fsamp/M);
subplot(2,1,1);
plot2d(f,H_mag (1:M/2));
xtitle('Magnitude response' ,'w(Hz)','Magnitude (dB)');
a=gca();
a.children.children(1).thickness=2;
subplot(2,1,2);
plot2d(f,H_phase(1:M/2));xtitle ('Phase response' , 'w(Hz)' ,
'Phase(Deg)');
a=gca();
a.children.children(1).thickness=2;
Output:
7. Design and test IIR Butterworth 1st and 2nd order low & high
pass filter.
//Design a digital low pass butterworth filter with the following
specifications:
// 3-db attenuation at the pass band frequency of 1.5KHz
//10-db stopband attenuation at the frequency of 3KHz
// Sampling frequency at 8000Hz
clc;
clear;
close();
// Order calculation
num1= 10.^(-kp/10)-1;
den1= 10.^(-ks/10)-1;
num=log10(num1/den1);
den=2*log10(1/ohms);
n=round(num/den);
disp('The order of the filter is--->');
disp(n);
hs=analpf(n,"butt",[0 0],1);
disp('The transfer function of the normalized filter is')
disp(hs);
clc;
clear;
close();
// Order calculation
num1= 10.^(-kp/10)-1;
den1= 10.^(-ks/10)-1;
num=log10(num1/den1);
den=2*log10(1/ohms);
n=round(num/den);
disp('The order of the filter is--->');
disp(n);
hs=analpf(n,"butt",[0 0],1);
disp('The transfer function of the normalized filter is')
disp(hs);
z=poly(0,'z');
Hz=horner(Hds,2*fsamp*(z-1)/(z+1));
disp('The transfer function of the filter after bilinear transformation is')
disp(Hz);
Output:
enter the pass band ripple: -0.5
2.
1
-----------------
1 +1.4142136s +s²
s²
-------------------------
1.492D+09 +54627.417s +s²
"The transfer function of the filter after bilinear transformation is"
Output:
Digital Signal Processing Integrated Professional Core Course (IPCC)
wn=exp(-%i*2*%pi/N);
kn=k'*n;
wnkn =wn.^kn;
X=x*wnkn;
subplot(2,1,1);
plot2d(k,abs(X));
title('Magnitude Plot');
X_fft=fft(x);
disp('The DFT of the sequence by using the builtin function is');
disp(X_fft);
wn=exp(%i*2*%pi/N);
kn=k'*n;
wnkn =wn.^kn;
x_r=(X*wnkn)/N;
disp('The IDFT of the sequence by using the formula is');
disp(abs(x_r));
//x_r1=fft(X_fft,1);
x_r1=ifft(X_fft);
disp('The IDFT of the sequence by using the builtin function is');
disp(x_r1);
Output:
Enter the input sequence [1 2 3 4]
1. 2. 3. 4.
1. 2. 3. 4.
14. Computation of circular convolution of two given sequences and
verification of commutative, distributive and associative property of
convolution.
clc;
clear;
close();
length_x=length(x);
length_h=length(h);
for i=1:N
y(i)=0;
for j=1:N
y(i)=y(i)+a(j)*b(pmodulo(i-j,N)+1);
end
end
Output:
Enter the first sequence [1 2 3]
Enter the second sequence [1 2 3]
"The circular convolution using formula"
13.
13.
10.
// Program to verify the following convolution properties
// 1 Commutative Property :a[n]*b[n]=b[n]*a[n]
// 2 Associative Property :a[n]*(b[n]*c[n])=(a[n]*b[n])*c[n]
// 3 Distributive Propery :a[n]*b[n]+a[n]*c[n]=a[n]*(b[n]+c[n])
// Note: The sequence lengths should be same
clc;
clear;
close();
function y=cconv(x, h, N)
for i=1:N
y(i)=0;
for j=1:N
y(i)=y(i)+x(j)*h(pmodulo(i-j,N)+1);
end
end
endfunction
length_x1=length(x1);
length_x2=length(x2);
length_x3=length(x3);
lhs_C=cconv(a,b,N);
rhs_C=cconv(b,a,N);
disp(lhs_C);
disp(rhs_C);
if(lhs_C==rhs_C)
disp('Commutative property is proved');
else
disp('Commutative property fails');
end
disp(lhs_A);
disp(rhs_A);
if(lhs_A==rhs_A)
disp('Associative property is proved');
else
disp('Associative property fails');
end
disp(lhs_D);
disp(rhs_D);
if(lhs_D==rhs_D)
disp('Distributive property is proved');
else
disp('Distributive property fails');
end
Output:
Enter the first sequence [1 2 3]
Enter the second sequence [1 2 3]
Enter the third sequence [1 2 3]
13.
13.
10.
13.
13.
10.
"Commutative property is proved"
72.
69.
75.
72.
69.
75.
"Associative property is proved"
26.
26.
20.
26.
26.
20.
"Distributive property is proved"
Output:
6. + 0.i -0.809017 - 3.6654688i 0.309017 + 1.677599i 0.309017 - 1.677599i -
0.809017 + 3.6654688i
15. + 0.i 0.690983 - 8.2819941i 1.809017 + 2.7674128i 1.809017 - 2.7674128
0.690983 + 8.2819941i
90. + 0.i -30.916408 + 4.1674973i -4.0835921 + 3.8899828i -4.0835921 -
3.8899828i -30.916408 - 4.1674973i
4. 13. 28. 27. 18.
4. 13. 28. 27. 18.
length_x=length(x);
length_h=length(h);
X=fft(a);
H=fft(b);
y=fft(X.*H,1);
disp('The circular convolution using DFT/IDFT is-->');
disp(y);
Output:
Enter the first sequence [1 2 3]
Enter the second sequence [4 5 6]
"The circular convolution using DFT/IDFT is-->"
a1=0.4;
a2=0.5;
x1=[1 2 3];
x2=[4 5 6 7];
N=4;
k=0:N-1;
n=0:N-1;
x1=[x1,zeros(1,N-length(x1))];
x2=[x2,zeros(1,N-length(x2))];
X1=fft(x1);
X2=fft(x2);
a1X1=a1*X1;
a2X2=a2*X2;
LHS_L=abs(fft(a1*x1+a2*x2));
RHS_L=abs(a1X1+a2X2);
disp(LHS_L);
disp(RHS_L);
if(round(LHS_L)==round(RHS_L))
disp('Linearity property is proved');
else
disp('Linearity property fails');
end
Output:
// x((n-m))<---->WN^mk X(k)
// To prove IDFT[WN^mk X(k)] =x((n-m)) or
DFT[x(n-m)]= WN^mk X(k)
clc;
clear;
close();
x=[1 2 3 4];
N=4;
k=0:N-1;
n=0:N-1;
x=[x,zeros(1,N-length(x))];
X=fft(x);
disp(RHS_TS);
disp(LHS_TS);
if(round(LHS_TS)==round(RHS_TS))
disp('Circular time shift property is proved');
else
disp('Circular time shift property fails');
end
RHS_FS=abs(X(pmodulo(k-m,N)+1));
wn=exp(%i*2*%pi/N);
wnmn=wn.^(n*m);
LHS_FS=abs(fft(wnmn.*x));
disp(RHS_FS);
disp(LHS_FS);
if(round(LHS_FS)==round(RHS_FS))
disp('Circular frequency shift property is proved');
else
disp('Circular frequency shift property fails');
end
Output:
Enter the shift 2
3. 4. 1. 2.
3. 4. 1. 2.
clc;
clear;
close();
x=[1 2 3];
N=4;
k=0:N-1;
n=0:N-1;
x=[x,zeros(1,N-length(x))];
X=fft(x);
E1=sum(x.^2);
E2=sum(abs(X).^2)/N;
if(round(E1)==round(E2))
disp('Parsevel Theorem is proved');
else
disp('Parsevel Theorem fails');
end
Output:
14.
14.
21. Design and implementation of low pass FIR filter to meet given
specifications.
Same as program 6
22. Design and implementation of high pass FIR filter to meet given
specifications.
Same as program 6
DSP Lab Hardware programs
1. Open Code Composer Studio [6713 DSK CCStudio V3.1], and make sure
that the DSP kit is turned on.
2. Use the Debug » Connect menu option to open a debug connection to the
DSK board
3. Start a new project using Project » New pull down menu, and save it in a
separate directory with some name Dummy.pjt
[Default path will be C:\CCStudio_v3.1\MyProjects\.......]
4. Open an editor window, going to, File » New » Source File and type the
program. Then save it with an extension .c [Let us save with some name
XXXX.c and default path for the saved file will be
C:\CCStudio_v3.1\MyProjects\Dummy\XXXX.c]
5. Add the source files XXXX.c to the project using Project » Add Files to
Project pull down menu.
6. Add the linker command file hello.cmd to the project using Project » Add
Files to Project pull down menu.
[Default path will be C:\CCStudio_v3.1\tutorial\dsk6713\hello1\hello.cmd
and by chance if you are using TMS320C6416DSK then add
C:\CCStudio_v3.1\tutorial\dsk6416\hello1\hello.cmd]
7. Add the run time support library file rts6700.lib to the project using Project
» Add Files to Project pull down menu.
[Default path will be C:\CCStudio_v3.1\C6000\cgtools\lib\rts6700.lib and
by chance if you are using TMS320C6416DSK then add
C:\CCStudio_v3.1\C6000\cgtools\lib \rts6400.lib]
8. Compile the program using the Project » Compile pull down menu or by
clicking the shortcut icon on the left side of the program window. If there
exists any error in program, then correct it and compile it.
9. Build the program using the Project » Build pull down menu or by clicking
the shortcut icon on the left side of the program window. If there exists any
error in program, then correct it and compile it.
10. Load the program in program memory of DSP Chip using the File » Load
Program pull down menu. [After compiling and building, CCStudio will
generate executable file format .out along with many other supporting files.
And .out file default path will be usually
C:\CCStudio_v3.1\MyProjects\Dummy\Debug\Dummy.out]
11. Then run the program using Debug » Run pull down menu. And result will
be displayed on the screen.
23. To compute N- Point DFT of a given sequence using DSK 6713
simulator.
#include<stdio.h>
#include<math.h>
void main ()
int x[10],n=0,M,N,k,i;
float sumre,diffim,cs=0,sn=0,pi=3.1416;
scanf("%d",&M);
scanf("%d",&N);
for(i=0;i<N;i++)
scanf("%d",&x[i]);
if(M-N!=0)
if(M>N)
for(i=N;i<M;i++)
x[i]=0;
N=M;
}
}
for(k=0;k<N;k++)
sumre=0;
diffim=0;
for(n=0;n<N;n++)
cs=cos(2*pi*(k)*n/N);
sn=sin(2*pi*(k)*n/N);
sumre+=x[n]*cs;
diffim-=x[n]*sn;
printf("X[%d]=%7.3f %7.3fj\n",k,sumre,diffim);
}
Output:
#include<math.h>
int y[20];
main()
int m,n,i,j;
int x[15];
int h[15];
scanf("%d",&m);
scanf("%d",&n);
scanf("%d",&x[i]);
scanf("%d",&h[i]);
x[i]=0;
y[i]=0;
y[i]+=x[j]*h[i-j];
printf("%d\n",y[i]);
}
Output:
#include<math.h>
int y[20];
main()
int N,m,n,k=0,i,j;
int x[10];
int h[10];
scanf("%d",&m);
scanf("%d",&n);
scanf("%d",&x[i]);
scanf("%d",&h[i]);
x[i]=0;
h[i]=0;
if(m>n)
N=m;
else
N=n;
for(i=0; i<N; i++)
y[i]=0;
k=i-j;
if(k<0)
k=k+N;
y[i]+=x[j]*h[k];
printf("%d\t",y[i]);
Output: