0% found this document useful (0 votes)
9 views58 pages

SP Lab Final

The BM3401 Signal Processing Laboratory manual outlines a series of experiments for Biomedical Engineering students, focusing on signal construction, system stability analysis, signal reconstruction, spectrum analysis, filter design, and DSP processor implementation using MATLAB. Each experiment includes aims, requirements, algorithms, and sample MATLAB code to guide students in executing the tasks. The manual is prepared for the academic year 2022-2023 at Mahendra College of Engineering, Salem Campus.

Uploaded by

BME'25
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)
9 views58 pages

SP Lab Final

The BM3401 Signal Processing Laboratory manual outlines a series of experiments for Biomedical Engineering students, focusing on signal construction, system stability analysis, signal reconstruction, spectrum analysis, filter design, and DSP processor implementation using MATLAB. Each experiment includes aims, requirements, algorithms, and sample MATLAB code to guide students in executing the tasks. The manual is prepared for the academic year 2022-2023 at Mahendra College of Engineering, Salem Campus.

Uploaded by

BME'25
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/ 58

BM3401 SIGNAL PROCESSING LABORATORY

LAB MANUAL

(Regulation 2021)

BE –BIOMECICAL ENGINEERING
IVSEMESTER

MAHENDRA COLLEGE OF ENGINEERING


SALEM CAMPUS, ATTUR MAIN ROAD, MINNAMPALLI, SALEM – 636 106

Academic Year: 2022 -2023

DEPARTMENT OF BIOMEDICAL ENGINEERING


Prepared By
Mrs.S.K.Deepa
Assistant Professor
BM3401 SIGNAL PROCESSING LABORATORY

LIST OF EXPERIMENTS

1. Construction Of Signals With Different Frequencies.


2. Analyse The Stability Of A CT System With Various Inputs.
3. Analyse The Stability Of A DT System With Various Inputs.
4. Reconstruct A Signal From Samples And Study The Effect Of Aliasing.
5. Spectrum Analysis Using FFT
6. Filter Design & Analysis.
7. Finite Word Length Effect.
8. Multirate Signal Processing.
9. DSP Processor Implementation. (Linear and Convolution, FFT Implementation, IIR and
FIR Filters Implementation)
1. Construction Of Signals With Different Frequencies.

2. Analyse The Stability Of A CT System With Various Inputs.


3. Analyse The Stability Of A DT System With Various Inputs.
4. Reconstruct A Signal From Samples And Study The Effect Of Aliasing.
5. Spectrum Analysis Using FFT
6. Filter Design & Analysis.
7. Finite Word Length Effect.
8. Multirate Signal Processing.
9. DSP Processor Implementation. (Linear and Convolution, FFT Implementation, IIR and
FIR Filters Implementation)

Ex No: Date:

CONSTRUCTION OF SIGNALS WITH DIFFERENT FREQUENCIES.


Aim:
To write a MATLAB program to construct signals with different frequencies.

Requirements:

PC with MATLAB

Algorithm:

1. Start the program.


2. Generate the sequence with various input frequencies to get the output
3. Execute the program.
4. Plot the output for each sequence.
5. Stop the program.
%Program to generate 0.2*n*cos(2*∏*n+(∏/4))
clc; % Clear the window
close all; ` % Close all files
clear all; % Clear the screen
n=0:1:100; % Range of n
y=cos(.05*((2*pi*n)+(pi/4)));
x=.5.*n.*y
stem(n,x);
grid on;
title('Cosine signal (.5ncos(2npi+(pi/4)))');
xlabel('n -->');
ylabel('x -->');

%Program to generate cos((2*∏*n)/256) x2=cos((4*∏*n)/256)


clc; % Clear the window
close all; ` % Close all files
clear all; % Clear the screen
n=0:1:256 % Range of n
x1=cos(2*pi*n/256);
subplot(3,1,1);
stem(n,x1);
grid on;
title ('Cosine signal (cos(2npi/256))');
xlabel('n -->');
ylabel('x1 -->');
x2=cos(6*pi*n/256);
subplot(3,1,2);
stem(n,x2);
grid on;
title ('Cosine signal (cos(6npi/256))');
xlabel('n -->');
ylabel('x2 -->');
RESULT:

Thus a MATLAB program to construct signals with different frequencies was


executed.

Ex No: Date:

ANALYSE THE STABILITY OF A CT SYSTEM WITH VARIOUS INPUTS

Aim:

To write a MATLAB program to analyse the stability of a system

Requirements

PC with MATLAB

Algorithm:

1. Start the program.


2. Find the transfer function to get the system stability
3. Execute the program
4. Plot the output sequence to analyze the stability of the system
5. Stop the program.
Program:

clear all;

close all;

clc;
numG = [1.5 1]; % Create G(s) as a ratio of numerator & denumerator

denG = [1 2 2.5 0.5];

roots(denG) % find poles of G(s)

pzmap(numG,denG) % plot the poles and zeros

impulse(numG,denG) % simulate impulse response

Result:

Thus a MATLAB program was written to analyse the stability of the system

EXP.NO: DATE:

RECONSTRUCT A SIGNAL FROM SAMPLES AND STUDY THE EFFECT OF ALIASING

Aim:
To write a MATLAB program to reconstruct signal from the samples and study the effect of aliasing

Requirement:

PC with MATLAB

Algorithm:
Program:

% PROGRAM FOR SAMPLING AND EFFECT OF ALIASING

clc;
clear all;
close all;
Ts1=0.04;
Ts2=0.005;
t=[0:0.0001:0.5];
w=100;
x=sin(w*t);
% Sampling with aliasing
figure(1);
subplot(3,1,1);
plot(t,x);
xlabel('Time (s)');
ylabel('Amplitude');
title('Continuous-Time Signal');
t1=[0:Ts1:0.5];
xs1=sin(w*t1);
subplot(3,1,2)
stem(t1,xs1);
xlabel('Time (s)');

ylabel('Amplitude');
title('Sampled Version of Ts1=0.04');

subplot(3,1,3)
plot(t,x,'LineWidth',3);
hold on; plot(t1,xs1,'r');
hold off;
xlabel('Time (s)');
ylabel('Amplitude');
title('Sampled Version of Ts1=0.04 - Effect of aliasing');
legend('Original Signal','Aliased Signal with Ts1');

% Sampling without aliasing


figure(2);
t2=[0:Ts2:0.5];
xs2=sin(w*t2);
subplot(3,1,1);
plot(t,x);
xlabel('Time (s)');
ylabel('Amplitude');
title('Continuous-Time Signal');

subplot(3,1,2)
stem(t2,xs2);
xlabel('Time (s)');
ylabel('Amplitude');
title('Sampled Version of Ts2=0.005');

subplot(3,1,3)
plot(t,x,'LineWidth',3);
hold on ;
plot(t2,xs2,'ro');
hold off;
xlabel('Time (s)');
ylabel('Amplitude');
title('Sampled Version of Ts2=0.005 - Effect of without aliasing');
legend('Original Signal','Without Aliasing Signal with Ts2');
EXP.N O: DATE:

SPECTRUM ANALYSIS USING FFT

Aim:

To write a MATLAB program to find the spectrum of a sinusoidal signal using FFT

Requirements:

PC wiyh MATLAB

Alogrithm:

Program:

Fs = 150

% Sampling frequency t = 0:1/Fs:1;


% Time vector of 1 second f = 5;

% Create a sine wave of f Hz. x = cos(2*pi*t*f);

nfft = 1024; % Length of FFT % Take fft,

padding with zeros so that length(X) is equal to nfft

X = fft(x,nfft);

% FFT is s ymmetric, throw awa y second half

X = X(1:nfft/2);

% Take the magnitude of fft of x mx = abs(X);

% Frequency vector f = (0:nfft/2-1)*Fs/nfft;

% Generate the plot,

title and labels. figure(1);

plot(t,x); title('Sine Wave Signal');

xlabel('Time (s)'); ylabel('Amplitude');

Power ylabel( Amplitude );

figure(2);

plot(f,mx);

title('Power Spectrum of a Sine Wave');

xlabel('Frequency (Hz)');

ylabel('Power');
Result:

Thus a MATLAB program was written to analyze the spectrum sinusoidal of the FFT

EXP.NO: DATE:

FILTER DESIGN & ANALYSIS

Aim:

To write a program to design the FIR low pass, high pass, band pass and band stop filters and obtain thefrequency
response of the filter using MATLAB
Requirements:
PC with MATLAB
Algorithm:
1. Start the program.
2. Get the cutoff frequency and order of the filter as input.
. 3. Find the ideal impulse response of the filter hd (n).
4. Select a window function w (n).
5. Find out the filter coefficients h (n) by multiplying hd (n) and w (n).
6. Compute the frequency response of the filter.
7. Repeat the process for high pass, band pass and band stop filters.
8. Execute the program, display the result and verify it.
9. Plot the output graph for hd(n),w(n),h(n)and frequency response of LPF,HPF,BPF and BSF
. 10.Stop the process
Output:
Filter coefficients for LPF= hd= -0.0470 0.1075 0.2967 0.3820 0.2967 0.1075 -0.0470
w= 0.0800 0.3100 0.7700 1.0000 0.7700 0.3100 0.0800
h= -0.0038 0.0333 0.2284 0.3820 0.2284 0.0333 -0.0038
disp(hd);

subplot(2,2,2);
stem(n,w);
xlabel('n--->');
ylabel('w(n)--->');
title('Hamming Window');
disp('w=');
disp(w);

subplot(2,2,3);
stem(n,h);
xlabel('n--->');
ylabel('h(n)--->');
title('Actual Impulse Response');
disp('h=');
disp(h);

subplot(2,2,4);
plot(P/pi, mag);
grid on;
xlabel('Normalized frequency--->');
ylabel('Magnitude in db--->');
title('Frequency Response ');

%PROGRAM FOR HIGH PASS FILTER


clc; clear
all;close
all;
M=11;
wc=1.2;
n=0:1:M-1;
hd=ideal_lp(pi,M)-ideal_lp(wc,M);
w=hann(M);
h=hd.*w';
disp('Filter coefficients for HPF=');

[M1,P]=freqz(h,1,2000);
mag=20*log10(abs(M1));
Output:
Filter coefficients for BPF=
hd=-0.0168 0.1580 0.0173 -0.2280 -0.0072 0.2546 -0.0072 -0.2280 0.0173 0.1580 -0.0168
w=0 0.0955 0.3455 0.6545 0.9045 1.0000 0.9045 0.6545 0.3455 0.0955 0
h=0 0.0151 0.0060 -0.1492 -0.0065 0.2546 -0.0065 -0.1492 0.0060 0.0151 0
subplot(2,2,1);
stem(n,hd);
xlabel('n--->');
ylabel('hd(n)--->');
title('Ideal Impulse Response');
disp('hd=');
disp(hd);

subplot(2,2,2);
stem(n,w);
xlabel('n--->');
ylabel('w(n)--->');
title('Hanning Window');
disp('w=');
disp(w);

subplot(2,2,3);
stem(n,h);
xlabel('n--->');
ylabel('h(n)--->');
title('Actual Impulse Response');
disp('h=');
disp(h);

subplot(2,2,4);
plot(P/pi, mag);
grid on;
xlabel('Normalized frequency--->');
ylabel('Magnitude in db--->');
title('Frequency Response ');

%PROGRAM FOR BAND PASS FILTER


clc; clear
all;close
all;
M=11;
wc1=1.2;
wc2=2;
n=0:1:M-1;

Output:

Filter coefficients for BSF

hd= -0.0173 0.2280 0.0072 0.7454 0.0072 0.2280 -0.0173

w= 1 1 1 1 1 1 1

h= -0.0173 0.2280 0.0072 0.7454 0.0072 0.2280 -0.0173


hd=ideal_lp(wc2,M)-ideal_lp(wc1,M);
w=hann(M);
h=hd.*w';
disp('Filter coefficients for BPF=');

[M1,P]=freqz(h,1,2000);
mag=20*log10(abs(M1));

subplot(2,2,1);
stem(n,hd);
xlabel('n--->');
ylabel('hd(n)--->');
title('Ideal Impulse Response');
disp('hd=');
disp(hd);

subplot(2,2,2);
stem(n,w);
xlabel('n--->');
ylabel('w(n)--->');
title('Hanning Window');
disp('w=');
disp(w);

subplot(2,2,3);
stem(n,h);
xlabel('n--->');
ylabel('h(n)--->');
title('Actual Impulse Response');
disp('h=');
disp(h);

subplot(2,2,4);
plot(P/pi, mag);
grid on;
xlabel('Normalized frequency--->');
ylabel('Magnitude in db--->');
title('Frequency Response ');
%PROGRAM FOR BAND STOP FILTER
clc; clear
all;close
all;M=7;
wc1=1.2;
wc2=2;
n=0:1:M-1;
hd=ideal_lp(pi,M)-ideal_lp(wc2,M)+ideal_lp(wc1,M);
w=rectwin(M);
h=hd.*w';
disp('Filter coefficients for BSF=');

[M1,P]=freqz(h,1,2000);
mag=20*log10(abs(M1));

subplot(2,2,1);
stem(n,hd);
xlabel('n--->');
ylabel('hd(n)--->');
title('Ideal Impulse Response');
disp('hd=');
disp(hd);

subplot(2,2,2);
stem(n,w);
xlabel('n--->');
ylabel('w(n)--->');
title('Rectangular Window');
disp('w=');
disp(w);

subplot(2,2,3);
stem(n,h);
xlabel('n--->');
ylabel('h(n)--->');
title('Actual Impulse Response');
disp('h=');
disp(h);
Ex : No: Date:

BUTTERWORTH INFINITE IMPULSE RESPONSE FILTERS


Aim:
To write a program to design the Butterworth low pass, high pass filters and find out
the response of the filter using MATLAB.

Algorithm:

1. Start the program.


2. Get the input sequences for pass band ripple, stop band ripple, pass
bandfrequency, stop band frequency and sampling frequency.
3. Convert the frequency into radians/sec.
4. Compute the order and cutoff frequency of the filter and display it.
5. Design the analog filter and find the coefficient.
6. Convert the analog filter into digital using bilinear or impulse
invarianttransform.
7. functioFind out the frequency response of the filter.
8. Compute the magnitude and phase response of the filter.
9. Execute the program, display the result and verify it.
10.Plot the output graph for each sequence for low pass and high pass filters.
11.Stop the process.

Output:
Enter the Passband frequency w1=[0.2*pi]
Enter the Stopband frequency w2=[0.6*pi]
Enter the Passband ripple a1=[0.8]
Enter the Stopband ripple a2=[0.2]

l = 4.8990 , e = 0.7500

num = 0.8150 , den = 0.4771

N=2, Wc = 0.7255

LPF ANALOG FILTER TRANSFER


FUNCTIONnum = 0 0 0.5264
den = 1.0000 1.0260 0.5264

LPF DIGITAL FILTER TRANSFER


FUNCTIONb = 0 0.3015 0
a = 1.0000 -1.0432 0.3584
T = 1, wp1 = 0.6498
ws1 = 2.7528, lam = 4.8990
ep = 0.7500
num1 = 0.8150, den1 = 0.6270
N1 = 2
Wc1 = 0.7504

HPF ANALOG FILTER TRANSFER FUNCTION


num1 = 1 0 0
den1 = 1.0000 1.0612 0.5631

HPF DIGITAL FILTER TRANSFER


FUNCTIONb1 = 0.5983 -1.1966
0.5983
a1 = 1.0000 -1.0282 0.3651
Program:

% Program for Butterworth Low Pass Filter

clc;

clear all;

close all;

%w1=0.2*pi;w2=0.6*pi;a1=0.8;a2=0.2;

w1=input('Enter the Passband frequency w1=');

w2=input('Enter the Stopband frequency w2=');

a1= input('Enter the Passband ripple a1=');

a2=input('Enter the Stopband ripple a2='); [N,Wc]=butt_impord(w1,w2,a1,a2);

disp('LPF ANALOG FILTER TRANSFER FUNCTION');

[num,den]=butter(N,Wc,'s')

disp('LPF DIGITAL FILTER TRANSFER FUNCTION');

[b,a]=impinvar(num,den)

[mag,angle]=freqz(b,a,512);

magnitude=20*log10(abs(mag));

figure(1);

plot(angle/pi,magnitude);

grid on;

title('Low Pass Butterworth Filter');

xlabel('frequency --->');

ylabel('magnitude --->');

%Program for Butterworth High Pass Filter[N1,Wc1]=butt_biord(w2,w1,a1,a2);

disp(' HPF ANALOG FILTER TRANSFER FUNCTION');

[num1,den1]=butter(N1,Wc1,'high','s')
disp('HPF DIGITAL FILTER TRANSFER FUNCTION');

[b1,a1]=bilinear(num1,den1,1);

[mag1,angle1]=freqz(b1,a1,512);

magnitude=20*log10(abs(mag1));

figure(2);

plot(angle1/pi,magnitude);

grid on;

title('High Pass Butterworth Filter');xlabel('frequency --->');

ylabel('magnitude --->');

subplot(2,2,4);

plot(P/pi, mag);grid on;

xlabel('Normalized frequency--->');

ylabel('Magnitude in db--->');

title('Frequency Response ');

Result:
Thus a program to design the Butterworth low pass and high pass
filter using Matlabwas written and response of the filter was executed.
EXP.NO DATE:

FINITE WORD LENGTH EFFECT

% P1520: Binary representation conversion


clc;
close all;
xd = [0.12345;-0.54321;0.90645;0.45388623;-0.237649];
L = 10;
N = length(xd);
xd_sign = sign(xd);
%% Part a: Sign-Magnitude Representation
xb_sm = zeros(N,L);
ind = (xd < 0); xb_sm(ind,1) = 1;
xd_abs = abs(xd);
for ii = 1:L-1
xb_sm(:,ii+1) = floor(2*xd_abs);
xd_abs = 2*xd_abs - xb_sm(:,ii+1);
end disp(’Sign-Magnitude Representation is:’)
xb_sm
%% Part b: Two’s-Complement Representation
xb_tc = zeros(N,L);
ind = (xd < 0);
xd_temp = xd;
xd_temp(ind) = 2 + xd_temp(ind);
xb_tc(:,1) = floor(xd_temp);
xd_temp = xd_temp - xb_tc(:,1);
for ii = 1:L-1 xb_tc(:,ii+1) = floor(xd_temp*2);
xd_temp = xd_temp*2 - xb_tc(:,ii+1);
end disp(’Two’’s-Complement Representation is:’) xb_tc

EXP.NO DATE
MULTIRATE SIGNAL PROCESSING

Aim:
Requirements:
Algorithm:
Program:
AIM: program to verify the decimation of given sequence.
SOFTWARE: MATLAB
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
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');

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.03
EXP.NO DATE:

DSP PROCESSOR IMPLEMENTATION. (LINEAR AND CONVOLUTION, FFT


IMPLEMENTATION, IIR AND FIR FILTERS IMPLEMENTATION)

Aim:
AIM: To verify the linear convolution operation Using DSK Code composer studio

Linear Convolution involves the following operations.


1. Folding 2. Multiplication 3. Addition 4. Shifting
These operations can be represented by a Mathematical Expression as follows:
x[ ]= Input signal Samples
h[ ]= Impulse response co-efficient. y[ ]= Convolution output.
n = No. of Input samples
h = No. of Impulse response co-efficient.
ALGORITHM TO IMPLEMENT ‘C’ OR ASSEMBLY PROGRAM FOR CONVOLUTION:
Eg: x[n] = {1, 2, 3, 4}
h[k] = {1, 2, 3, 4}
Where: n=4, k=4. ;Values of n & k should be a multiple of 4.
If n & k are not multiples of 4, pad with zero’s to make multiples of 4 r= n+k-1 ; Size of output
sequence.
= 4+4-1
= 7.
r= 0 1 2 3 4 5 6
n= 0 x[0]h[0] x[0]h[1] x[0]h[2] x[0]h[3]
1 x[1]h[0] x[1]h[1] x[1]h[2] x[1]h[3]
2 x[2]h[0] x[2]h[1] x[2]h[2] x[2]h[3]
3 x[3]h[0] x[3]h[1] x[3]h[2] x[3]h[3]
Output: y[r] = { 1, 4, 10, 20, 25, 24, 16}.
NOTE: At the end of input sequences pad ‘n’ and ‘k’ no. of zero’s
ASSEMBLY PROGRAM TO IMPLEMENT LINEAR CONVOLUTION
conv.asm:
.global _main
X .half 1,2,3,4,0,0,0,0 ;input1, M=4
H .half 1,2,3,4,0,0,0,0 ;input2, N=4
.bss Y,14,2 ;OUTPUT, R=M+N-1
;At the end of input sequences pad ‘M’ and ‘N’ no. of zero’s
_main:
MVKL .S1 X,A4
MVKH.S1 X,A4 ;POINTER TO X MVKL .S2 H,B4
MVKH.S2 H,B4 ;POINTER TO H MVKL .S1 Y,A5
MVKH.S1 Y,A5 ;POINTER TO Y MVK .S2 7,B2 ;R=M+N-1
;MOVE THE VALUE OF ‘R’TO B2 FOR DIFFERENT LENGTH OF I/P SEQUENCES
ZERO .L1 A7
ZERO .L1 A3 ;I=0 LL2:
ZERO .L1 A2
ZERO .L1 A8 ;J=0, for(i=0;i<m+n-1;i++) LL1:
LDH .D1 *A4[A8],A6 ; for(j=0;j<=i;j++) MV .S2X A8,B5 ; y[i]+=x[j]*h[i-j];
SUB .L2 A3,B5,B7 LDH .D2 *B4[B7],B6 NOP 4
MPY .M1X A6,B6,A7 ADD .L1 A8,1,A8 ADD .L1 A2,A7,A2
CMPLT .L2X B5,A3,B0 [B0] B .S2 LL1
NOP 5
STH .D1 A2,*A5[A3] ADD .L1 A3,1,A3 CMPLT .L1X A3,B2,A2 [A2] B .S1 LL2
NOP 5 B B3 NOP 5
‘C’ PROGRAM TO IMPLEMENT LINEAR CONVOLUTION
#include<stdio.h> main()
{ int m=4; /*Lenght of i/p samples sequence*/
int n=4; /*Lenght of impulse response Co-efficients */ int i=0,j;
int x[10]={1,2,3,4,0,0,0,0}; /*Input Signal Samples*/
int h[10]={1,2,3,4,0,0,0,0}; /*Impulse Response Co-efficients*/
/*At the end of input sequences pad ‘M’ and ‘N’ no. of zero’s*/ int y[10];
for(i=0;i<m+n-1;i++)
{ y[i]=0;
for(j=0;j<=i;j++) y[i]+=x[j]*h[i-j];
}
for(i=0;i<m+n-1;i++) printf("%d\n",y[i]);
}
PROCEDURE:
• • Open Code Composer Studio, make sure the DSP kit is turned on.
• • Start a new project using ‘Project-new ‘ pull down menu, save it in a separate
directory(c:\ti\myprojects) with name lconv.pjt.
• • Add the source files conv.asm.
• • to the project using ‘Project add files to project’ pull down menu.
• • Add the linker command file hello.cmd.
• • (Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd)
• • Add the run time support library file rts6700.lib.
• • (Path: c:\ti\c6000\cgtools\lib\rts6700.lib)
• • Compile the program using the ‘Project-compile’ pull down menu or by clicking the
shortcut icon on the left side of program window.
• • Build the program using the ‘Project-Build’ pull down menu or by
• • clicking the shortcut icon on the left side of program window.
• • Load the program (lconv.out) in program memory of DSP chip using the
• • ‘File-load program’ pull down menu.
• • To View output graphically
• • Select view graph time and frequency.
RESULT:
Configure the graphical window as shown below
INPUT
x[n] = {1, 2, 3, 4,0,0,0,0}
h[k] = {1, 2, 3, 4,0,0,0,0}
OUTPUT:

Note:
1. To execute the above program follow “ procedure to work on code composer studio”
2. To view graphical output follow the above procedure.
AIM: To verify the circular convolution operation Using DSK Code composer studio
C Program to Implement Circular Convolution
#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30]; void main()
{
printf(" enter the length of the first sequence\n"); scanf("%d",&m);
printf(" enter the length of the second sequence\n"); scanf("%d",&n);
printf(" enter the first sequence\n"); for(i=0;i<m;i++) scanf("%d",&x[i]);
printf(" enter the second sequence\n"); for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0) /*If length of both sequences are not equal*/
{
if(m>n) /* Pad the smaller sequence with zero*/
{
for(i=n;i<m;i++) h[i]=0;
n=m;
}
for(i=m;i<n;i++) x[i]=0;
m=n;
} y[0]=0;
a[0]=h[0];
➢Open Code Composer Studio; make sure the DSP kit is turned on.
➢Start a new project using ‘Project-new ‘ pull down menu, save it in a separate
directory(c:\ti\myprojects) with name cir conv.pjt.
➢Add the source files Circular Convolution.C.
➢to the project using ‘Project add files to project’ pull down menu.
➢Add the linker command file hello.cmd .
➢(Path: c:\ti\tutorial\dsk6713\hello1\hello.cmd)
➢Add the run time support library file rts6700.lib
➢(Path: c:\ti\c6000\cgtools\lib\rts6700.lib)

for(j=1;j<n;j++) /*folding h(n) to h(-n)*/ a[j]=h[n-j];


/*Circular convolution*/ for(i=0;i<n;i++) y[0]+=x[i]*a[i]; for(k=1;k<n;k++)
{ y[k]=0;
/*circular shift*/ for(j=1;j<n;j++) x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{ a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
/*displaying the result*/
printf(" the circular convolution is\n"); for(i=0;i<n;i++)
printf("%d \t",y[i]);
} PROCEDURE:
➢Compile the program using the ‘Project-compile’ pull down menu or by clicking the
shortcut icon on the left side of program window.
➢Build the program using the ‘Project-Build’ pull down menu or by clicking the shortcut icon
on the left side of program window.
➢Load the program(lconv.out) in program memory of DSP chip using the ‘File-load program’
pull down menu.

INPUT:
Eg: x[4]={3, 2, 1,0}
h[4]={1, 1, 0,0}
OUTPUT: y[4]={3, 5, 3,0}
RESULT:
The C program was written and verified successfully for linear & circular convolution operation Using
DSK Code composer studio.
AIM: To find the DFT of a sequence using FFT algorithm
C PROGRAM TO IMPLEMENT 4 POINT FFT :
Main.c (fft 256.c):
#include <math.h>
#define PTS 64 //# of points for FFT #define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX; void FFT(COMPLEX *Y, int n); //FFT prototype
float iobuffer[PTS]; //as input and output buffer float x1[PTS]; //intermediate buffer
short i; //general purpose index variable
short buffercount = 0; //number of new samples in iobuffer short flag = 0; //set to 1 by ISR when
iobuffer full COMPLEX w[PTS]; //twiddle constants stored in w COMPLEX samples[PTS];
//primary working buffer main()
{
for (i = 0 ; i<PTS ; i++) // set up twiddle constants in w
{
w[i].real = cos(2*PI*i/(PTS*2.0)); //Re component of twiddle constants w[i].imag =-
sin(2*PI*i/(PTS*2.0)); //Im component of twiddle constants
}
for (i = 0 ; i < PTS ; i++) //swap buffers
{
iobuffer[i] = sin(2*PI*10*i/64.0);/*10- > freq, 64 -> sampling freq*/
samples[i].real=0.0; samples[i].imag=0.0;
}
for (i = 0 ; i < PTS ; i++) //swap buffers
{
samples[i].real=iobuffer[i]; //buffer with new data
}
for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0; //imag components = 0 FFT(samples,PTS); //call function FFT.c
for (i = 0 ; i < PTS ; i++) //compute magnitude
{
x1[i] = sqrt(samples[i].real*samples[i].real
+ samples[i].imag*samples[i].imag);
}
} //end of main
C PROGRAM TO IMPLEMENT 8 POINT FFT :
#define PTS 64 //# of points for FFT
typedef struct {float real,imag;} COMPLEX;
extern COMPLEX w[PTS]; //twiddle constants stored in w
void FFT(COMPLEX *Y, int N) //input sample array, # of points
{
COMPLEX temp1,temp2; //temporary storage variables int i,j,k; //loop counter variables
int upper_leg, lower_leg; //index of upper/lower butterfly leg int leg_diff; //difference between
upper/lower leg
int num_stages = 0; //number of FFT stages (iterations) int index, step; //index/step through
twiddle constant i = 1; //log(base2) of N points= # of stages
do
{
num_stages +=1; i = i*2;
}while (i!=N);
leg_diff = N/2; //difference between upper&lower legs step
= (PTS*2)/N; //step between values in twiddle.h for (i = 0;i
< num_stages; i++) //for N-point FFT
{
index = 0;
for (j = 0; j < leg_diff; j++)
{
for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff))
{
lower_leg = upper_leg+leg_diff;
temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real; temp1.imag = (Y[upper_leg]).imag +
(Y[lower_leg]).imag; temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real; temp2.imag =
(Y[upper_leg]).imag - (Y[lower_leg]).imag; (Y[lower_leg]).real = temp2.real*(w[index]).real
-temp2.imag*(w[index]).imag; (Y[lower_leg]).imag = temp2.real*(w[index]).imag
+temp2.imag*(w[index]).real; (Y[upper_leg]).real = temp1.real; (Y[upper_leg]).imag =
temp1.imag;
}
index += step;
}
leg_diff = leg_diff/2; step *= 2;
}
j = 0;
for (i = 1; i < (N-1); i++) //bit reversal for resequencing data
{
k = N/2;
while (k <= j)
{
j = j - k; k = k/2;
}
j = j + k; if (i<j)
{
temp1.real = (Y[j]).real;
temp1.imag = (Y[j]).imag; (Y[j]).real = (Y[i]).real;
(Y[j]).imag = (Y[i]).imag; (Y[i]).real = temp1.real;
(Y[i]).imag = temp1.imag;
}
}
return;
}
C PROGRAM TO IMPLEMENT N POINT FFT :
#define PTS 64 //# of points for FFT
typedef struct {float real,imag;} COMPLEX;
extern COMPLEX w[PTS]; //twiddle constants stored in w
void FFT(COMPLEX *Y, int N) //input sample array, # of points
{
COMPLEX temp1,temp2; //temporary storage variables int i,j,k; //loop counter variables
int upper_leg, lower_leg; //index of upper/lower butterfly leg int leg_diff; //difference between
upper/lower leg
int num_stages = 0; //number of FFT stages (iterations) int index, step; //index/step through
twiddle constant i = 1; //log(base2) of N points= # of stages
do
{
num_stages +=1; i = i*2;
}while (i!=N);
leg_diff = N/2; //difference between upper&lower legs step
= (PTS*2)/N; //step between values in twiddle.h for (i = 0;i
< num_stages; i++) //for N-point FFT
{
index = 0;
for (j = 0; j < leg_diff; j++)
{
for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff))
{
lower_leg = upper_leg+leg_diff;
temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real;
temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag; temp2.real = (Y[upper_leg]).real -
(Y[lower_leg]).real; temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag; (Y[lower_leg]).real
= temp2.real*(w[index]).real
-temp2.imag*(w[index]).imag; (Y[lower_leg]).imag = temp2.real*(w[index]).imag
+temp2.imag*(w[index]).real; (Y[upper_leg]).real = temp1.real; (Y[upper_leg]).imag =
temp1.imag;
}
index += step;
}
leg_diff = leg_diff/2; step *= 2;
}
j = 0;
for (i = 1; i < (N-1); i++) //bit reversal for resequencing data
{
k = N/2; while (k <= j)
{
j = j - k; k = k/2;
}
j = j + k; if (i<j)
{
temp1.real = (Y[j]).real;
temp1.imag = (Y[j]).imag; (Y[j]).real = (Y[i]).real;
(Y[j]).imag = (Y[i]).imag; (Y[i]).real = temp1.real;
(Y[i]).imag = temp1.imag;
}
}
return;
}
RESULT:

You might also like