0% found this document useful (0 votes)
23 views50 pages

DSP IPCC _ 21EC42 and AEC_21EC483

Uploaded by

akhileshsugowda
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)
23 views50 pages

DSP IPCC _ 21EC42 and AEC_21EC483

Uploaded by

akhileshsugowda
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
You are on page 1/ 50

Ability Enhancement Course – IV

Octave / Scilab for Signals Course Code 21EC483


Experiments:

1. Verify the Sampling theorem.


2. Determine linear convolution, Circular convolution and Correlation of two given
sequences. Verify the result using theoretical computations.
3. Determine the linear convolution of two given point sequences using FFT algorithm.
Verify the result using theoretical computations.
4. Determine the correlation using FFT algorithm. Verify the result using theoretical
computations.
5. Determine the spectrum of the given sequence using FFT. Verify the result using
theoretical computations.
6. Design and test FIR filter using Windowing method (Hamming, Hanning and
Rectangular window) for the given order and cut-off frequency.
7. Design and test IIR Butterworth 1st and 2nd order low & high pass filter.
8. Design and test IIR Chebyshev 1st and 2nd order low & high pass filter.
9. Generation of an AM – Suppressed Carrier Wave & visualization of the time domain
and frequency domain plots.
10. Generation and visualization of standard test signals (both continuous and discrete
time).
11. Generation and visualization of audio signal (pre-recorded) and generation of echo.
12. Generation and visualization of the STFT of a chirp (and other related) signal.

Course outcomes (Course Skill Set):

At the end of the course the student will be able to:

* 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)

PRACTICAL COMPONENT OF IPCC Course Code 21EC42

List of Programs to be implemented & executed using any programming


languages like
C++/Python/Java/Scilab / MATLAB/CC Studio (but not limited to.

13. Computation of N point DFT of a given sequence and to plot magnitude


and phase spectrum.
14. Computation of circular convolution of two given sequences and
verification of commutative, distributive and associative property of
convolution.
15. Computation of linear convolution of two sequences using DFT and IDFT.
16. Computation of circular convolution of two given sequences using DFT
and IDFT
17. Verification of Linearity property, circular time shift property & circular
frequency shift property of DFT.
18.Verification of Parseval’s theorem
19. Design and implementation of IIR (Butterworth) low pass filter to meet
given specifications.
20. Design and implementation of IIR (Butterworth) high pass filter to meet
given specifications.
21. Design and implementation of low pass FIR filter to meet given
specifications.
22. Design and implementation of high pass FIR filter to meet given
specifications.
23. To compute N- Point DFT of a given sequence using DSK 6713 simulator.
24. To compute linear convolution of two given sequences using DSK 6713
simulator.
25. To compute circular convolution of two given sequences using DSK 6713
simulator.
10. Generation and visualization of standard test signals (both continuous and
discrete time).

//UNIT IMPULSE SIGNAL


clc;
clear;
close();
L=5; //input('Enter the Length=');
n=-L:L;
x=[zeros(1,L),ones(1,1),zeros(1,L)];
///subplot(2,2,1);
a=gca();//get the current axes
a.y_location ="Origin";
a.foreground=3;
a.font_color=2;
a.font_style=5;
plot2d3(n,x); //discrete plot
xlabel("time");
ylabel("Amplitude");
title("Impulse Signal");

Output:

//UNIT STEP SIGNAL


clc;
clear;
close();
L=5; //input('Enter the Length=');
n=-L:L;
y=[zeros(1,L),ones(1,L+1)];
a=gca();
a.y_location="middle";
a.foreground=5;
a.font_color=5;
a.font_style=5;
plot2d3(n,y)
title('Unit Step Signal');
xlabel('Samples n');
ylabel('Amplitude');

Output:

//UNIT RAMP SIGNAL


clc;
clear;
close();
L=5; //input('Enter the Length=');
n=-L:L;
y=[zeros(1,L),0:L];
a=gca();
a.y_location="middle";
a.foreground=5;
a.font_color=5;
a.font_style=5;
plot2d3(n,y)
title('Unit Ramp Signal');
xlabel('Samples n');
ylabel('Amplitude');
Output:

//EXPONENTIALLY INCREASING FUNCTION SEQUENCE


clc;
clear;
close();
n=-2:0.1:2;
x=exp(n);// exp is the (element-wise) exponential of the entries of n.
a=gca();
//a.y_location="middle";
a.foreground=5;
a.font_color=5;
a.font_style=5;
plot2d(n,x);
title('Exponentially Increasing Sequence');
xlabel('Samples n');
ylabel('Amplitude');

Output:

//EXPONENTIALLY DECREASING FUNCTION SEQUENCE


clc;
clear;
close();
n=-2:0.1:2;
x=exp(-n);// exp is the (element-wise) exponential of the entries of n.
a=gca();
//a.y_location="middle";
a.foreground=5;
a.font_color=5;
a.font_style=5;
plot2d(n,x)
title('Exponentially Decreasing Sequence');
xlabel('Samples n');
ylabel('Amplitude');

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

// Generation of Cosine waveform


clc;
clear;
close();
sig_freq=input("enter the frequency of the signal");
//or sig_freq=5
t=0:0.001:1;
y=cos(2*%pi*sig_freq*t);
//subplot(212);
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 4

1. Verify the Sampling theorem.

Statement:

A continuous time signal can be represented in its samples and can be


recovered back when sampling frequency f s is greater than or equal to the
twice the highest frequency component of message signal. i.e. fs ≥ 2fm .

clc;
clear;
close();

sig_freq=input("enter the frequency of the signal");


samp_freq=input("enter the sampling frequency");
L=input("enter the interpolation factor");

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

enter the sampling frequency 50

enter the interpolation factor 5

fs > 2 fm

enter the frequency of the signal 2

enter the sampling frequency 4

enter the interpolation factor 2

fs = 2fm
enter the frequency of the signal 15

enter the sampling frequency 5

enter the interpolation factor 2

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();

x=input('Enter the first sequence');


h=input('Enter the second sequence');

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

disp('Convolution using the formula is given by');


disp(y);

disp('Convolution using the builtin function is given by');


disp(conv(x,h));
Output:
Enter the first sequence [1 2 3]
Enter the second sequence [4 5 6]
"Convolution using the formula is given by"
4. 13. 28. 27. 18.
"Convolution using the builtin function is given by"
4. 13. 28. 27. 18.
//To compute the circular convolution of two sequences

clc;
clear;
close();

x=input('Enter the first sequence');


h=input('Enter the second sequence');

length_x=length(x);
length_h=length(h);

// Making both sequences of equal length


N=max(length_x,length_h);
a=[x zeros(1,N-length_x)];
b=[h zeros(1,N-length_h)];

// Using the circular convolution formula

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();

x1=input('Enter the first sequence');


x2=input('Enter the second sequence');

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

disp('Correlation using the formula is given by');


disp(y);

disp('Correlation using the builtin function is given by');


disp(xcorr(x1,x2));

Output: Auto Correlation


Enter the first sequence [1 2 3]
Enter the second sequence [1 2 3]
"Correlation using the formula is given by"
3. 8. 14. 8. 3.
"Correlation using the builtin function is given by"
3. 8. 14. 8. 3.

Output: Cross Correlation


Enter the first sequence [1 2 3]
Enter the second sequence [4 5 6]
"Correlation using the formula is given by"
6. 17. 32. 23. 12.
"Correlation using the builtin function is given by"
6. 17. 32. 23. 12.
3. Determine the linear convolution of two given point sequences
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');
m=length(x1);
n=length(h1);
N=n+m-1;
x=[x1 zeros(1,N-m)];
h=[h1 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=conv(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
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

15. + 0.i 4.309017 - 7.1064236i 3.190983 + 0.8652998i 3.190983 -


0.8652998i
4.309017 + 7.1064236i

90. + 0.i -29.534442 - 10.04535i -0.4655581 + 5.6205824i -0.4655581 -


5.6205824i
-29.534442 + 10.04535i

6. 17. 32. 23. 12.

6. 17. 32. 23. 12.


5. Determine the spectrum of the given sequence using FFT. Verify
the result using theoretical computations.
//To Plot the DFT of rectangular pulse
clc;
clear;
close();

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;

// To find the order of the filter N .


k=1;
trans_width=(fs-fp)/fsamp;
N=ceil(k/trans_width);

// To make even order to odd order


remainder = N-fix(N./2) .*2;
if remainder ==0
N=N+1;
end

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:

//Pass band edge frequency = 2500 Hz


//Stop band edge frequency = 1500 Hz
//Stopband attenuation = 40 db
//Sampling rate= 8000Hz

clc;
clear;
close();

fp=2500;
fs=1500;
fsamp=8000;

// To find the order of the filter N .


k=3;
trans_width=(fp-fs)/fsamp;
N=ceil(k/trans_width);

// To make even order to odd order


remainder = N-fix(N./2) .*2;
if remainder ==0
N=N+1;
end

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();

kp=input('enter the pass band ripple: ');


ks=input('enter the stop band attenuation: ');
fp=input('enter the pass band edge frequency: ');
fs=input('enter the stop band edge frequency: ');
fsamp=input('enter the sampling frequency: ');

// Conversion to angular frequency


wp=2*%pi*fp*1/fsamp;
ws=2*%pi*fs*1/fsamp;

// Performing pre warpping


ohmp_prewarp = 2*fsamp*tan(wp/2);
ohms_prewarp = 2*fsamp*tan(ws/2);

// Using the backward design equation


ohms=ohms_prewarp/ohmp_prewarp;

// 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);

// Perform low pass prototype to low pass tansformation


s=poly(0,'s');
Hds=horner(hs,s/ohmp_prewarp);
disp('The transfer function after lowpass to lowpass transformation is')
disp(Hds);
Output:

enter the pass band ripple: -3


enter the stop band attenuation: -10
enter the pass band edge frequency: 1500
enter the stop band edge frequency: 3000
enter the sampling frequency: 8000
"The order of the filter is--->"
1.
"The transfer function of the normalized filter is"
1
----
1 +s
"The transfer function after lowpass to lowpass transformation is"
1
-------------
1 +0.0000935s

//Design a digital high pass butterworth filter with the following


specifications:

//0.5-db attenuation at the pass band frequency of 3KHz


//25-db stopband attenuation at the frequency of 1KHz
//Sampling frequency at 8000Hz

clc;
clear;
close();

kp=input('enter the pass band ripple: ');


ks=input('enter the stop band attenuation: ');
fp=input('enter the pass band edge frequency: ');
fs=input('enter the stop band edge frequency: ');
fsamp=input('enter the sampling frequency: ');

// Conversion to angular frequency


wp=2*%pi*fp*1/fsamp;
ws=2*%pi*fs*1/fsamp;

// Performing pre warpping


ohmp_prewarp = 2*fsamp*tan(wp/2);
ohms_prewarp = 2*fsamp*tan(ws/2);

// Using the backward design equation


ohms=ohmp_prewarp/ohms_prewarp;

// 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);

// Perform lowpass to high pass tansformation


s=poly(0,'s');
Hds=horner(hs,ohmp_prewarp/s);
disp('The transfer function after lowpass to highpass transformation is')
disp(Hds);

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);

[hzm ,fr ]= frmag (Hz ,512) ;


magz =20* log10(hzm);

plot2d (fr*fsamp ,magz);


xtitle ( 'Magnitude response' , 'w(Hz)' , 'Magnitude (dB)');

Output:
enter the pass band ripple: -0.5

enter the stop band attenuation: -25

enter the pass band edge frequency: 3000

enter the stop band edge frequency: 1000

enter the sampling frequency: 8000

"The order of the filter is--->"

2.

"The transfer function of the normalized filter is"

1
-----------------
1 +1.4142136s +s²

"The transfer function after lowpass to highpass transformation is"


-------------------------
1.492D+09 +54627.417s +s²
"The transfer function of the filter after bilinear transformation is"

0.0976311 -0.1952621z +0.0976311z²


----------------------------------
0.3333333 +0.942809z +z²

11. Generation and visualization of audio signal (pre-recorded) and


generation of echo.
clc;
clear;
close ;
//Reading a speech signal
[x,Fs,bits]=wavread("D:\2022-23 Even sem\DSP Lab\Programs\preamble.wav");
order = 40; // Adaptive filter order
x=x';
N=length(x); //length of speech signal
//Delay introduced in echo path
delay = 20;
//Echo at same speaker
xdelayed = zeros(1,N+delay);
for i = delay+1:N+delay
xdelayed(i)=x(i-delay);
end
figure(1)
subplot(3,1,1)
plot([1:N],x)
title('Speech Signal Generated by some Speaker A')
//sound(x,Fs,16)
subplot(3,1,2)
plot([1:length(xdelayed)],xdelayed)
title('Echo signal of speaker A received by speaker A')

Output:
Digital Signal Processing Integrated Professional Core Course (IPCC)

13. Computation of N point DFT of a given sequence and to plot


magnitude and phase spectrum
clc;
clear;
close();

x=input('Enter the input sequence');


N=input('Enter the vaue of N');
x=[x,zeros(1,N-length(x))];
n=0:N-1;
k=0:N-1;

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_ang = atan(imag (X),real (X));


subplot(2,1,2);
plot2d(k,X_ang*180/%pi);
title('Phase Plot');
disp('The DFT of the sequence by using the formula is');
disp(X);

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]

Enter the vaue of N 4

"The DFT of the sequence by using the formula is"

10. + 0.i -2. + 2.i -2. - 9.797D-16i -2. - 2.i

"The DFT of the sequence by using the builtin function is"

10. + 0.i -2. + 2.i -2. + 0.i -2. - 2.i

"The IDFT of the sequence by using the formula is"

1. 2. 3. 4.

"The IDFT of the sequence by using the builtin function is"

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();

x=input('Enter the first sequence');


h=input('Enter the second sequence');

length_x=length(x);
length_h=length(h);

// Making both sequences of equal length


N=max(length_x,length_h);
a=[x zeros(1,N-length_x)];
b=[h zeros(1,N-length_h)];

// Using the circular convolution formula

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.
// 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

x1=input('Enter the first sequence');


x2=input('Enter the second sequence');
x3=input('Enter the third sequence');

length_x1=length(x1);
length_x2=length(x2);
length_x3=length(x3);

// Making both sequences of equal length


N=max(length_x1,length_x2,length_x3);
a=[x1 zeros(1,N-length_x1)];
b=[x2 zeros(1,N-length_x2)];
c=[x3 zeros(1,N-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

// To prove Associative property


lhs_A=cconv(a,cconv(b,c));
rhs_A=cconv(cconv(a,b),c);

disp(lhs_A);
disp(rhs_A);

if(lhs_A==rhs_A)
disp('Associative property is proved');
else
disp('Associative property fails');
end

// To prove Distributive property


lhs_D=cconv(a,b)+cconv(a,c);
rhs_D=cconv(a,b+c);

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"

15. Computation of linear convolution of two sequences using DFT


and IDFT.
clc;
clear all;
close;
x1=[1 2 3];//x=input('enter the ist sequence');
h1=[4 5 6];//h=input('enter the 2nd sequence');
m=length(x1);
n=length(h1);
N=n+m-1;
x=[x1 zeros(1,N-m)];
h=[h1 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=conv(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
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.

16. Computation of circular convolution of two given sequences


using DFT and IDFT.
clc;
clear;
close();

x=input('Enter the first sequence');


h=input('Enter the second sequence');

length_x=length(x);
length_h=length(h);

// Making both sequences of equal length


N=max(length_x,length_h);
a=[x zeros(1,N-length_x)];
b=[h zeros(1,N-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-->"

31. 31. 28.

17. Verification of Linearity property, circular time shift


property & circular frequency shift property of DFT.
// Linearity property
clc;
clear;
close();

// a1 x1(n) + a2 x2(n) <----> a1 X1(k) + a2 X2(k)

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:

13.4 1.811077 0.2 1.811077

13.4 1.811077 0.2 1.811077

"Linearity property is proved"

//To prove circular time shift

// 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);

m=input('Enter the shift');


wn=exp(-%i*2*%pi/N);
wnkm=wn.^(k*m);
wnkmX=wnkm.*X;
RHS_TS=abs(fft(wnkmX,1));
LHS_TS=x(pmodulo(n-m,N)+1)

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

// To prove circular frequency shift

// WN^-mn x(n)<----> X((k-m))


// To prove DFT[WN^-mn . x(n)] = X((k-m)) or
WN^-mn . x(n) = IDFT[X(k-m)]

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.

"Circular time shift property is proved"

2. 2.8284271 10. 2.8284271

2. 2.8284271 10. 2.8284271

"Circular frequency shift property is proved"

18.Verification of Parseval’s theorem

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.

"Parseval’s Theorem is proved"

19. Design and implementation of IIR (Butterworth) low pass filter to


meet given specifications.
Same as program 7

20. Design and implementation of IIR (Butterworth) high pass filter to


meet given specifications.
Same as program 7

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

Steps to use CC studio and Hardware kit

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;

printf("enter the length of the dft req\n");

scanf("%d",&M);

printf("enter the length of the seq given");

scanf("%d",&N);

printf("enter the seq x(n)\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;

}
}

printf("the dft is\n");

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:

enter the length of the dft req 4

enter the length of the seq given 4

enter the seq x(n) 1 2 3 4

X(k) = 10 -2+2j -2 -2-2j


24. To compute linear convolution of two given sequences using
DSK 6713 simulator.
#include<stdio.h>

#include<math.h>

int y[20];

main()

int m,n,i,j;

int x[15];

int h[15];

printf("\n enter length of x(n)\n");

scanf("%d",&m);

printf("enter length h(n)\n");

scanf("%d",&n);

printf("enter the sequence x(n):\n");

for(i=0; i<m; i++)

scanf("%d",&x[i]);

printf("enter the sequence h(n):\n");

for(i=0; i<n; i++)

scanf("%d",&h[i]);

for(i=m; i<m+n-1; i++)

x[i]=0;

for(i=n; i<m+n-1; i++)


h[i]=0;

for(i=0; i<m+n-1; i++)

y[i]=0;

for(j=0; j<=i; j++)

y[i]+=x[j]*h[i-j];

printf("The convolved sequence is:\n");

for(i=0; i<m+n-1; i++)

printf("%d\n",y[i]);

}
Output:

enter length of x(n) 3

enter length of h(n) 3

enter the sequence x(n): 1 2 3

enter the sequence h(n): 1 2 3

The convolved sequence is: 1 4 10 12 9

25. To compute circular convolution of two given sequences using


DSK 6713 simulator.
#include<stdio.h>

#include<math.h>

int y[20];
main()

int N,m,n,k=0,i,j;

int x[10];

int h[10];

printf("enter length of x(n)\n");

scanf("%d",&m);

printf("enter length h(n)\n");

scanf("%d",&n);

printf("enter the sequence x(n):\n");

for(i=0; i<m; i++)

scanf("%d",&x[i]);

printf("enter the sequence h(n):\n");

for(i=0; i<n; i++)

scanf("%d",&h[i]);

for(i=m; i<m+n; i++)

x[i]=0;

for(i=n; i<m+n; i++)

h[i]=0;

if(m>n)

N=m;

else

N=n;
for(i=0; i<N; i++)

y[i]=0;

for(j=0; j<N; j++)

k=i-j;

if(k<0)

k=k+N;

y[i]+=x[j]*h[k];

printf("The convolved sequence is:\n");

for(i=0; i<N; i++)

printf("%d\t",y[i]);

Output:

enter length of x(n) 3

enter length of h(n) 3

enter the sequence x(n): 1 2 3

enter the sequence h(n): 1 2 3

The convolved sequence is: 13 13 10

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy