0% found this document useful (0 votes)
139 views134 pages

DSP Lab Manual Align

The document describes MATLAB scripts to design low pass FIR filters using different window and frequency sampling methods. It includes algorithms to: 1. Design low pass FIR filters using various window functions like rectangular, triangular, Hamming, Hanning, and Blackman windows. 2. Plot the frequency responses of the designed filters and compare their Gibbs phenomenon. 3. Design a low pass FIR filter using frequency sampling method. The scripts take user input for the filter order and cutoff frequency. They output the filter coefficients and plot the frequency responses to verify the designs.
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)
139 views134 pages

DSP Lab Manual Align

The document describes MATLAB scripts to design low pass FIR filters using different window and frequency sampling methods. It includes algorithms to: 1. Design low pass FIR filters using various window functions like rectangular, triangular, Hamming, Hanning, and Blackman windows. 2. Plot the frequency responses of the designed filters and compare their Gibbs phenomenon. 3. Design a low pass FIR filter using frequency sampling method. The scripts take user input for the filter order and cutoff frequency. They output the filter coefficients and plot the frequency responses to verify the designs.
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/ 134

AIM:

To write a MATLAB Script to perform discrete convolution (Linear and Circular) for
the given two sequences.

COMPONENTS REQUIRED:
PC, MATLAB software

ALGORITHM/PROCEDURE:

LINEAR CONVOLUTION:
1. Enter the sequences (Input x[n] and the Impulse response h[n])
2. Perform the linear convolution between x[k] and h[k] and obtain y[n].
3. Find the FFT of x[n] & h[n].Obtain X and H
4. Multiply X and H to obtain Y
5. Find the IFFT of Y to obtain y’[n]
6. Compute error in time domain e=y[n]-y’[n]
7. Plot the Results

CIRCULAR CONVOLUTION
1. Enter the sequences (input x[n] and the impulse response h[n])
2. Make the length of the sequences equal by padding zeros to the smaller length
sequence.
3. Perform the circular convolution between x[k] and h[k]and obtain y[n].
4. Find the FFT of x[n] & h[n].Obtain X and H
5. Multiply X and H to obtain Y
6. Find the IFFT of Y to obtain y’[n]
7. Compute error in time domain e=y[n]-y’[n]
8. Plot the Results
SOURCE CODE 1 – LINEAR CONVOLUTION
clc;
clear all;
close all;
%Program to perform Linear Convolution

x1=input('Enter the first sequence to be convoluted:');


subplot(3,1,1);
stem(x1);
xlabel('Time');
ylabel('Amplitude');
title('First sequence');

x2=input('Enter the second sequence to be convoluted:');


subplot(3,1,2);
stem(x2);
xlabel('Time');
ylabel('Amplitude');
title('Second sequence');

f=conv(x1,x2);
disp('The Linear convoluted sequence is');
disp(f);
subplot(3,1,3);
stem(f);
xlabel('Time');
ylabel('Amplitude');
title('Linear Convoluted sequence');
SOURCE CODE 2 – CIRCULAR CONVOLUTION
clc;
clear all;
close all;
%Program to perform Circular Convolution

x1=input('Enter the first sequence to be convoluted:');


subplot(3,1,1);
l1=length(x1);
stem(x1);
xlabel('Time');
ylabel('Amplitude');
title('First sequence');

x2=input('Enter the second sequence to be convoluted:');


subplot(3,1,2);
l2=length(x2);
stem(x2);
xlabel('Time');
ylabel('Amplitude');
title('Second sequence');

if l1>l2
l3=l1-l2;
x2=[x2,zeros(1,l3)];
elseif l2>l1
l3=l2-l1;
x1=[x1,zeros(1,l3)];
end

f=cconv(x1,x2);

disp('The Circular convoluted sequence is');


disp(f);
subplot(3,1,3);
stem(f);
xlabel('Time');
ylabel('Amplitude');
title('Circular Convoluted sequence');

OUTPUT WAVEFORMS:

LINEAR CONVOLUTION

Input: Enter the first sequence to be convoluted:[1,2,3,4]


Enter the second sequence to be convoluted:[2,3,4]
Output
The Linear convoluted sequence is
2 7 16 25 24 16

Output Waveforms
CIRCULAR CONVOLUTION

Input: Enter the first sequence to be convoluted:[1,2,3,4]


Enter the second sequence to be convoluted:[2,3,4]
Output
The Circular convoluted sequence is
Columns 1 through 5

2.0000 7.0000 16.0000 25.0000 24.0000

Columns 6 through 7
16.0000 0.0000

Output Waveforms

RESULT:
The linear and circular convolutions are performed by using MATLAB script and the
program results are verified by manual calculation.
AIM:
To write a MATLAB program to perform the Discrete Fourier Transform/Fast Fourier
Transform for the given sequences.
COMPONENTS REQUIRED:
PC, MATLAB software

ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop (or go to Start - All Programs and click on
MATLAB) to get into the Command Window
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it as ‘m-file’
4. Run the program
5. Enter the input in the command window
6. The result is displayed in the Command window and the graphical output is displayed
in the Figure Window

Source Code :1
clc;
clear all;
close all;
%Get the sequence from user
disp('The sequence from the user:');
xn=input('Enter the input sequence x(n):');

% To find the length of the sequence


N=length(xn);

%To initilise an array of same size as that of input sequence


Xk=zeros(1,N);
iXk=zeros(1,N);

%code block to find the DFT of the sequence


for k=0:N-1
for n=0:N-1
Xk(k+1)=Xk(k+1)+(xn(n+1)*exp((-i)*2*pi*k*n/N));
end
end

%code block to plot the input sequence


t=0:N-1;
subplot(3,2,1);
stem(t,xn);
ylabel('Amplitude');
xlabel('Time Index');
title('Input Sequence');

%code block to plot the X(k)


disp('The discrete fourier transform of x(n):');
disp(Xk);
t=0:N-1;
subplot(3,2,2);
stem(t,Xk);
ylabel('Amplitude');

xlabel('Time Index');
title('X(k)');

% To find the magnitudes of individual DFT points


magnitude=abs(Xk);

%code block to plot the magnitude response


disp('The magnitude response of X(k):');
disp(magnitude);
t=0:N-1;
subplot(3,2,3);
stem(t,magnitude);
ylabel('Amplitude');
xlabel('K');
title('Magnitude Response');

%To find the phases of individual DFT points


phase=angle(Xk);

%code block to plot the phase response


disp('The phase response of X(k):');
disp(phase);
t=0:N-1;
subplot(3,2,4);
stem(t,phase);
ylabel('Phase');
xlabel('K');
title('Phase Response');

% Code block to find the IDFT of the sequence


for n=0:N-1
for k=0:N-1
iXk(n+1)=iXk(n+1)+(Xk(k+1)*exp(i*2*pi*k*n/N));
end
end

iXk=iXk./N;

%code block to plot the output sequence


t=0:N-1;
subplot(3,2,5);
stem(t,xn);
ylabel ('Amplitude');
xlabel ('Time Index');
title ('IDFT sequence');

%code block to plot the FFT of input sequence using inbuilt function
x2=fft(xn);
subplot(3,2,6);
stem(t,x2);
ylabel ('Amplitude');

xlabel ('Time Index');


title ('FFT of input sequence');

% Spectrum Analysis with the FFT


n = [0:149];
x1 = cos(2*pi*n/10);
N = 2048;
X = abs(fft(x1,N));
X = fftshift(X);
F = [-N/2:N/2-1]/N;
figure(2):
plot(F,X),
xlabel('frequency / f s')
ylabel('Magnitude')
Input:

The sequence from the user:


Enter the input sequence x(n) :[1,2,3,4]
The discrete fourier transform of x(n) :
10.0000 -2.0000 + 2.000i -2.0000 – 0.0000i -2.0000 – 2.0000i

The magnitude response of X(k) :


10.0000 2.8284 2.0000 2.8284

The phase response of X(k) :


0 2.3562 -3.1416 -2.3562

OUTPUT 1:
Output of Spectrum Analysis with the FFT

Source Code :2
% Spectrum Analysis with the FFT with noise

clc;
clear all;
close all;
fs = 100; % sample frequency (Hz)
t = 0:1/fs:10-1/fs; % 10 second span time vector
x = (1.3)*sin(2*pi*15*t) ... % 15 Hz component
+ (1.7)*sin(2*pi*40*(t-2)) ... % 40 Hz component
+ 2.5*gallery('normaldata',size(t),4); % Gaussian noise;
y = fft(x);
n = length(x); % number of samples
f = (0:n-1)*(fs/n); % frequency range
power = abs(y).^2/n; % power of the DFT

plot(f,power)
xlabel('Frequency')
ylabel('Power')
y0 = fftshift(y); % shift y values
f0 = (-n/2:n/2-1)*(fs/n); % 0-centered frequency range
power0 = abs(y0).^2/n; % 0-centered power
plot(f0,power0)
xlabel('Frequency')
ylabel('Power')

OUTPUT 2:

RESULT:
The program for DFT/FFT calculation was performed. The results were verified by
manual calculation.
AIM:
To write a MATLAB Script to design a low pass FIR filter using Window Method for
the given specifications.
COMPONENTS REQUIRED:
PC, MATLAB software

ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop (or go to Start – All Programs and
click on MATLAB) to get into the Command Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it in ‘M-file’.
4. Run the program.
5. Enter the input in the Command Window.
6. The result is displayed in the Command window and the graphical output is displayed
in the Figure Window.
SOURCE CODE :1
clc;
clear all;
close all;

N=input('Order of the filter:');


wc=input('Cut off frequency:');

h=fir1(N,wc/pi,rectwin(N+1));
freqz(h);
title('FIR Filter - Rectangular Window');

h=fir1(N,wc/pi,triang(N+1));
figure(2)
freqz(h);
title('FIR Filter - Triangular Window');

h=fir1(N,wc/pi,hamming(N+1));
figure(3)
freqz(h);
title('FIR Filter - Hamming Window');

h=fir1(N,wc/pi,hanning(N+1));
figure(4)
freqz(h);
title('FIR Filter - Hanning Window');

h=fir1(N,wc/pi,blackman(N+1));
figure(5)
freqz(h);
title('FIR Filter - Blackman Window');

SOURCE CODE :2
clc;
clear all;
close all;

N=input('Order of the filter:');


wc=input('Cut off frequency:');

b=fir1(N,wc/pi,rectwin(N+1));
[H,w]=freqz(b,1,512); %frequency response

plot(w/pi,abs(H),'k');
hold on

b=fir1(N,wc/pi,triang(N+1));
[H,w]=freqz(b,1,512); %frequency response

plot(w/pi,abs(H),'--k');
hold on

b=fir1(N,wc/pi,hamming(N+1));
[H,w]=freqz(b,1,512); %frequency response

plot(w/pi,abs(H),':k');
hold on

b=fir1(N,wc/pi,hanning(N+1));
[H,w]=freqz(b,1,512); %frequency response
plot(w/pi,abs(H),'-.k');
hold on

b=fir1(N,wc/pi,blackman(N+1));
[H,w]=freqz(b,1,512); %frequency response

plot(w/pi,abs(H),'.b');
hold on

xlabel('Normalized Frequency');
ylabel('Magnitude');
legend('Rectangular','Triangular(Barlett)','Hamming','Hanning','Blackman','Location','Best');

title('Gibbs Phenomenon');

a=findobj(gcf); % get the handles associated with the current figure

allaxes=findall(a,'Type','axes');
alllines=findall(a,'Type','line');
alltext=findall(a,'Type','text');

set(allaxes,'FontName','Times New Roaman','FontWeight','Bold','LineWidth',1,...


'FontSize',12);
set(alllines,'Linewidth',1);
set(alltext,'FontName','Times New Roaman','FontWeight','Bold','FontSize',12);
OUTPUT: 1

Order of the filter:51


Cut off frequency:0.4
OUTPUT: 2
Order of the filter:51
Cut off frequency:0.4
RESULT:
The given low pass filter was designed using Window method and manually verified

filter co-efficient of the filters.


AIM:
To write a MATLAB Script to design a low pass FIR filter using Frequency Sampling
Method for the given specifications.
COMPONENTS REQUIRED:
PC, MATLAB software

SOURCE CODE:
%30th order LPF using Frequency Sampling method
clc;
clear all;
close all;
Fs=1000; %sampling frequency
Fn=Fs/2; %Nyquist frequency
f=[ 0 400 400 500]/Fn;
m=[1 1 0 0];
h=fir2(30,f,m);
[H,w]=freqz(h,1,256);
plot(f*Fn,m,'-o')
hold on
plot (Fn*w/pi, abs(H),'k');grid
hold on
legend('Ideal', 'Designed')
xlabel('Frequency (Hz)')
ylabel('Magnitude')
title('FIR filter')

%optional code
M=63; Wp=0.5*pi;%the number of samples and the passband cutoff frequency
m=0:(M+1)/2; Wm=2*pi*m./(M+1);%the sampling points and the stopband cutoff frequency
mtr=floor(Wp*(M+1)/(2*pi))+2;%round to negative part,i.e.floor(3.5)=3;floor(-3.2)=-4
Ad=[Wm<=Wp];Ad(mtr)=0.38;
Hd=Ad.*exp(-j*0.5*M*Wm);%define frequency-domain sampling vector H(k)
Hd=[Hd conj(fliplr(Hd(2:(M+1)/2)))];
%fliplr is to realize the fliplr of matrix and conj
h=real(ifft(Hd));% h(n)=IDFT[H(k)
w=linspace(0,pi,1000);%get 1000 row vectors between 0 and pi
H=freqz(h,[1],w);%the amplitude -frequency characteristic diagram of the filter
figure(1)
plot(w/pi,20*log10(abs(H)));%parameters are respectively the normalized frequency and
amplitude
xlabel('the normailzed frequency');
ylabel('gian/dB');
title('The gain response of lowpass filter');
axis([0 1 -50 0.5]);
f1=100;f2=300;f3=700;
fs=2000;%the frequencies of sines signal that needs filtered and the sample frequency
figure(2);
subplot(211)
t=0:1/fs:0.25;%define the time domain and steplength
s=sin(2*pi*f1*t)+sin(2*pi*f2*t)+sin(2*pi*f3*t);%signal before filtering
plot(t,s);%plot the diagram before filtering
xlabel('time/s');
ylabel('amplitude');
title('Time-domain diagram before filtering');
subplot(212)
Fs=fft(s,512); AFs=abs(Fs);%transform to the frequency domain
f=(0:255)*fs/512;%frequency sampling
plot(f,AFs(1:256));%plot the frequency domain diagram before filtering
xlabel('frequency/Hz');
ylabel('amplitude');
title('Frequency-domain diagram before filtering');
figure(3)
sf=filter(h,1,s);%use function filter
subplot(211)
plot(t,sf)%plot the diagram after filtering
xlabel('time/s');
ylabel('amplitude');
title('Time-domain diagram after filtering');
axis([0.2 0.25 -2 2]);%set the range of image coordinates
subplot(212)
Fsf=fft(sf,512); AFsf=abs(Fsf);%frequency-domain and the amplitude diagram
f=(0:255)*fs/512;%frequency sampling
plot(f,AFsf(1:256))%plot the frequency domain diagram before filtering
xlabel('frequency/Hz');
ylabel('amplitude');
title('Frequency-domain diagram after filtering');
OUTPUT 1:

OUTPUT 2:
RESULT:

For the given specifications low pass filter was designed using Frequency Sampling

Method and manually verified filter co-efficient of the filters.


AIM:

To write a MATLAB Script to design Butterworth and Chebyshev low pass filters
using Bilinear Transformation, Impulse Invariant Transformation
COMPONENTS REQUIRED:
PC, MATLAB software
BILINEAR TRANSFORMATION:
DESIGN STEPS:
1. From the given specifications, Find pre-warped analog frequencies using
2  
= tan  
T 2
2. Using the analog frequencies, find H(s) of the analog filter

2 1 − Z −1
3. Substitute S =  in the H(s) of Step:2
T 1 + Z −1

IMPULSE INVARIANT TRANSFORMATION:


DESIGN STEPS:
1. Find the analog frequency using =  /T
2. Find the transfer function of analog filter Ha(s)
3. Express the analog filter transfer function as a sum of single pole filters
4. Compute H(Z) of digital filter using the formula
N
Ck
H (Z ) =  −TPk Z −1
k =1 1 − e
ALGORITHM/PROCEDURE:
1. Calculate the attenuation in dB for the given design parameters
2. Design the analog counterpart
3. Using Impulse Invariant /Bilinear transformation design the digital filter
4. Display the transfer function. Plot the magnitude response and phase response
SOURCE CODE:
/ Butterworth Lowpass Impulse invariant method
clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Butterworth Lowpass filter using Impulse invariant method ');

T=input('Enter the Sampling Frequency in rad/sec: ');


Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in rad/sec: ');

% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));

ohmp=Wp/T;
ohms=Ws/T;
% Butterworth Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc]=buttord(ohmp,ohms,Ap,As,'s');

% Low Pass Filtering


[b,a]=butter(n,Wc,'low','s');
[bz,az] = impinvar(b,a,T);
tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);

% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Impulse Invariant Method');

% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Impulse Invariant Method');

/ Butterworth Lowpass Bilinear Transformation Method

clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,both the ripple gains should have band width( .1 to .3)
disp(' Butterworth Lowpass filter using Bilnear transformation method ');

T=input('Enter the Sampling Frequency in rad/sec: ');


Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in rad/sec: ');

% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Butterworth Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc]=buttord(ohmp,ohms,Ap,As,'s');

% Low Pass Filtering


[b,a]=butter(n,Wc,'low','s');
[bz,az] = bilinear(b,a,1/T);
tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);

% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Bilinear Transformation Method');

% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Bilinear Transformation Method');

/ Chebyshev Lowpass Impulse invariant method

clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Chebyshev Lowpass filter using Impulse invariant method ');

T=input('Enter the Sampling Frequency in rad/sec: ');


Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in rad/sec: ');

% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Chebyshev Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc2]=cheb1ord(ohmp,ohms,Ap,As,'s')

% Low Pass Filtering


[b,a]=cheby1(n,Ap,Wc2,'low','s');
[bz,az] = impinvar(b,a,T);
tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);

% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Impulse Invariant Method');

% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Impulse Invariant Method');

/Chebyshev Lowpass Bilinear Transformation Method

clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Chebyshev Lowpass filter using Bilnear transformation method ');

T=input('Enter the Sampling Frequency in rad/sec: ');


Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in rad/sec: ');
% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Chebyshev Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc2]=cheb1ord(ohmp,ohms,Ap,As,'s')

% Low Pass Filtering


[b,a]=cheby1(n,Ap,Wc2,'low','s');
[bz,az] = bilinear(b,a,1/T);
tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);

% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Bilinear Transformation Method');

% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Bilinear Transformation Method');

/ Butterworth Lowpass Impulse invariant method

Command window:
OUTPUT:
Butterworth Lowpass Bilinear Transformation Method

Command Window :

OUTPUT:
Chebyshev Lowpass Impulse invariant method
Command Window:

OUTPUT:
Chebyshev Lowpass Bilinear Transformation Method
Command Window:

Output:
RESULT:
Butterworth and Chebyshev Lowpass filters were designed using Bilinear and Impulse

Invariant transformations, and manually verified the order, cut off frequency and filter co-

efficient of the filters.


AIM:

To write a MATLAB Script to design multirate LPF filters

COMPONENTS REQUIRED:

PC, MATLAB software

A Simple Decimation Sytem

A Simple Interpolation System

SOURCE CODE:

%To design a lowpass filter FIR filter having 128 coefficients and a cut of frequency of

C = ,
3

clc;clear all;close all;


h = fir1(128-1,1/3); % Input cutoff as 2*fc, where fc = wc/(2pi)
freqz(h,1,512,1)
print -tiff -depsc multi3.eps
OUTPUT

%Downsample the spectrum signal by a factor of 2


n = 0:1024;
x = 1/4*sinc(1/4*(n-512)).^2;
y = downsample(x,2);
f = -1:1/512:1;
X = freqz(x,1,2*pi*f);
Y = freqz(y,1,2*pi*f);
plot(f,abs(X))
subplot(211)
plot(f,abs(X))
subplot(212)
plot(f,abs(Y))
print -tiff -depsc multi4.eps
OUTPUT

% use the same signal except with M=3. First without the prefilter, and then include it to
avoid aliasing.
n = 0:1024;
x = 1/4*sinc(1/4*(n-512)).^2;
xf = filter(h,1,x);
yf = downsample(xf,3);
ynf = downsample(x,3);
X = freqz(x,1,2*pi*f);
Xf = freqz(xf,1,2*pi*f);
Yf = freqz(yf,1,2*pi*f);
Ynf = freqz(ynf,1,2*pi*f);
subplot(411)
plot(f,abs(X))
subplot(412)
plot(f,abs(Ynf))
subplot(413)
plot(f,abs(Xf))
subplot(414)
plot(f,abs(Yf))
print -tiff -depsc multi5.eps
OUTPUT

%Upsample the spectrum signal by a factor of 3

clear all, close all;clc;


n = 0:1024;
f = -1:1/512:1;
x = 1/4*sinc(1/4*(n-512)).^2;
y = upsample(x,3);
X = freqz(x,1,2*pi*f);
Y = freqz(y,1,2*pi*f);
h = fir1(128-1, 1/3);
yf = filter(h,1,y);
Yf = freqz(yf,1,2*pi*f);
subplot(311)
plot(f,abs(X))
subplot(312)
plot(f,abs(Y))
subplot(313)
plot(f,abs(Yf))
print -tiff -depsc multi6.eps

OUTPUT

RESULT:
The multirate LPF filters (Interpolator and Decimator) are performed by using
MATLAB script and the program results are verified by manual calculation.
AIM:
To write a MATLAB Script to estimate the spectrum using the following non
parametric methods.
a. Periodogram
b. Modified Periodogram
c. Bartlett Method
d. Welch Method

COMPONENTS REQUIRED:
PC, MATLAB software

Periodogram
The periodogram spectral estimator stems from the PSD already defined in equation

Removing the expectation operator and using only a finite data size, the periodogram spectral
estimator is defined as,

which of course is the DTFT squared and averaged.

Averaged Periodogram
The variance in the periodogram estimator of equation (not decreasing with increasing data
record length) may be due to the removal of the expectation operator, that is, a lack of
averaging. To improve the statistical properties of the the periodogram, the expectation
operator can be approximated by averaging a set of periodograms. Assume that K independent
records of the random process are available for the interval 0 ≤ n ≤ L − 1. Then the averaged
periodogram estimator is defined as,
Bartlett’s Method
Averages several periodograms (rectangular window applied to each) and leads to consistent
estimate of the PSD

Welch method
The Wlech method provides a variation of the averaged periodogram. Recall that the
periodogram is just the average, magnitude squared of the DFT of the signal. The Welch
method differs from the averaged periodogram in two ways. First, the data is windowed and
secondly, data blocks are overlapped. The data window reduces spectral leakage (we see this
later) and by overlapping blocks of data, typically by 50 or 75%, some extra variance
reduction is achieved. The Welch PSD estimator uses the DFT. However, it does it in a clever
way (overlapping samples) such that the PSD estimates, depending on the data set, are often
better than those obtained with the DFT

Multitaper Method
The MTM method uses a bank of optimal bandpass filters to compute the estimate. These
optimal FIRfilters are derived from a set of sequences known as discrete prolate spheroidal
sequences (DPSSs, also known as Slepian sequences). In addition, the MTM method provides
a time-bandwidth parameter with which to balance the variance and resolution. This parameter
is given by the time-bandwidth product, NW and it is directly related to the number of tapers
used to compute the spectrum.

Source Code:

clc;
clear all;
close all;

randn('state',0);
fs = 1000; % Sampling frequency
t = (0:fs/10)./fs; % One-tenth of a second worth of samples
xn = sin(2*pi*150*t) + 2*sin(2*pi*140*t) + 0.1*randn(size(t));

%Periodogram
figure(1)
periodogram(xn,[],1024,fs);

%Modified Periodogram
figure(2)
periodogram(xn,hamming(length(xn)),1024,fs);

%Welch Method
figure(3)
pwelch(xn,hamming(length(xn)),75,512,fs)

%Multitaper Method
figure(4)
pmtm(xn,3/2,1024,fs);
OUTPUT:
RESULT:
Different non-parametric spectral estimation techniques were studied and compared
through matlab script programs
AIM:
To write a MATLAB Script to equalize the digital audio signals
COMPONENTS REQUIRED:
PC, MATLAB software

THEORY:
For an audio application such as the CD player, the digital audio equalizer is used to make the
sound as one desires by changing filter gains for different audio frequency bands. Other
applications include adjusting the sound source to take room acoustics into account, removing
undesired noise, and boosting the desired signal in the specified passband. The simulation is
based on the consumer digital audio processor—such as a CD player—handling the 16-bit
digital samples with a sampling rate of 44.1 kHz and an audio signal bandwidth at 22.05 kHz.
A block diagram of the digital audio equalizer is depicted in this Figure

A seven-band audio equalizer is adopted. The center frequencies are listed in this Table
The 3 dB bandwidth for each bandpass filter is chosen to be 50% of the center frequency. As
shown in Figure, g0 through g6 are the digital gains for each bandpass filter output and can be
adjusted to make sound effects, while y0(n) through y6(n) are the digital amplified bandpass
filter outputs. Finally, the equalized signal is the sum of the amplified bandpass filter outputs
and itself. By changing the digital gains of the equalizer, many sound effects can be produced.
To complete the design and simulation, second-order IIR bandpass Butterworth filters are
chosen for the audio equalizer. The coefficients are achieved using the BLT method, and are
given in this Table

The audio test signal having frequency components of 100 Hz, 200 Hz, 400 Hz, 1,000 Hz,
2,500 Hz, 6,000 Hz, and 15,000 Hz is generated from Equation

After simulation, we notice that the frequency components at 100 Hz, 200 Hz, 6,000 Hz, and
15,000 Hz will be boosted by 20 log10 10 ¼ 20dB.
SOURCE CODE

close all; clear all


% Filter coefficients (Butterworth type designed using the BLT)
B0 = [0.0031954934 0 -0.0031954934];
A0 = [1.0000000000 -1.9934066716 0.9936090132];
B1 = [0.0063708102 0 -0.0063708102];
A1 = [1.0000000000 -1.9864516324 0.9872583796];
B2 = [0.0126623878 0 -0.0126623878];
A2 = [1.0000000000 -1.9714693192 0.9746752244];
B3 = [0.0310900413 0 -0.0310900413];
A3 = [ 1.0000000000 -1.9181849043 0.9378199174];
B4 = [ 0.0746111954 0.000000000 -0.0746111954];
A4 = [1.0000000000 -1.7346085867 0.8507776092];
B5 = [0.1663862883 0.0000000000 -0.1663862884];
A5 = [1.0000000000 -1.0942477187 0.6672274233];
B6 = [0.3354404899 0.0000000000 -0.3354404899];
A6 = [1.0000000000 0.7131366534 0.3291190202];
[h0,f] = freqz(B0,A0,2048,44100);
[h1,f] = freqz(B1,A1,2048,44100);
[h2,f] = freqz(B2,A2,2048,44100);
[h3,f] = freqz(B3,A3,2048,44100);
[h4,f] = freqz(B4,A4,2048,44100);
[h5,f] = freqz(B5,A5,2048,44100);
[h6,f] = freqz(B6,A6,2048,44100);
loglog(f,abs(h0),f,abs(h1), f,abs(h2), ...
f,abs(h3),f,abs(h4),f,abs(h5),f,abs(h6));
xlabel('Frequency (Hz)');
ylabel('Filter Gain');grid
axis([10 10^5 10 ^(-6) 1]);
figure(2)
g0 = 10;g1 = 10;g2 = 0;g3 = 0;g4 = 0;g5 = 10;g6 = 10;
p0 = 0;p1 = pi/14;p2 = 2*p1;p3 = 3*p1;p4 = 4*p1;p5 = 5*p1;p6 = 6*p1;
n = 0:1:20480; % Indices of samples
fs = 44100; % Sampling rate
x = sin(2*pi*100*n/fs)+sin(2*pi*200*n/fs+p1)+...
sin(2*pi*400*n/fs+p2)+sin(2*pi*1000*n/fs+p3)+...
sin(2*pi*2500*n/fs+p4)+sin(2*pi*6000*n/fs+p5)+...
sin(2*pi*15000*n/fs+p6); % Generate test audio signals
y0 = filter(B0,A0,x); % Bandpass filter 0
y1 = filter(B1,A1,x); % Bandpass filter 1
y2 = filter(B2,A2,x); % Bandpass filter 2
y3 = filter(B3,A3,x); % Bandpass filter 3
y4 = filter(B4,A4,x); % Bandpass filter 4
y5 = filter(B5,A5,x); % Bandpass filter 5
y6 = filter(B6,A6,x); % Bandpass filter 6
y = g0.*y0+g1.*y1+g2.*y2+g3.*y3+g4.*y4+g5.*y5+g6.*y6+x; %Equalizer output
N = length(x);
Axk = 2*abs(fft(x))/N;Axk(1) = Axk(1)/2; %One-sided amplitude spectrum of the input
f = [0:N/2]*fs/N;
subplot(211);loglog(f,Axk(1:N/2+1));
title('Audio spectrum');
axis([10 100000 0.00001 100]);grid;
Ayk = 2*abs(fft(y))/N;Ayk(1) = Ayk(1)/2; %One-sided amplitude spectrum of the output
subplot(2,1,2); loglog(f,Ayk(1:N/2+1));
xlabel('Frequency (Hz)');
title('Equalized audio spectrum');
axis([10 100000 0.00001 100]);grid;

OUTPUT:
The top plot in this Figure shows the spectrum for the audio test signal, while the bottom plot
depicts the spectrum for the equalized audio test signal. As shown in the plots, before audio
digital equalization, the spectral peaks at all bands are at the same level; after audio digital
equalization, the frequency components at bank 0, bank 1, bank 5, and bank 6 are amplified.
Therefore, as we expected, the operation of the digital equalizer boosts the low frequency
components and the high frequency components.

RESULT:

Thus the Digital audio signals generated were equalized by using MATLAB script program.
AIM
To generate a sinewave form using TMS320C6745 DSP KIT.

COMPONENTS REQUIREMENTS

CCS v4
TMS320C6745 KIT
USB Cable
5V Adapter

ALGORITHM

Sine wave generation


1. create a new project and initialize header file, input, output and variables to the
particular data type.
2. Set the memory address which is used to store the input and output values.
3. The output values (real time) are stored in the dac channel 1 memory address
(0xc0000000)
4. Then set the sampling frequency (sampf) and input frequency (inpf) to find the
number of samples (nsamp) and sampling time(sampt).
nsamp=sampf/inpf: sampt=1/sampf
5. Using trigonometry formulae find out the sine output. This output values come
across -1 t0 1.This gain is not enough to display the sine wave, so increase the
gain by multiplying with 2048.
6. Bitwise EX-OR operation is used to offset the sine values (+ve offset) and then
move the gain increased value to DAC memory address.
7. Simulation output is displayed in Graph window & Real time output in CRO or
DSO.
PROCEDURE
1. Open Code Composer Studio v4 .
2. In WorkSpace Launcher.
a. BROWSE → Select the project location and make one new folder,
MAKE NEW FOLDER →Type the Workspace name, OK → OK.
3. FILE → NEW → CCS PROJECT
a. Project name: Type your project name.
b. Tick use default location. →NEXT
c. Project type: C6000.
d. Tick Debug And Release. →NEXT → NEXT.
e. Output type: Executable.
f. Device Variant : generic C67XX Device.
g. Device Endianness : little
h. Code Generation Tools: TI v6.1.12.
i. Run time support library: automatic.
j. Target content: none. →FINISH
4. FILE → NEW → SOURCE FILE
a. Source file: Type your projectname.c( .c extension is must ).
b. Type the program.
c. FILE → SAVE.
5. Paste the following board library files in workspace location.
a. Common folder (contains header files)
b. Gel folder (contains gel file)
c. Library folder(contains library files)
6. Paste the Linker file in the project location.(linker file is available in cd)
Note: Those folders and linker file are availble at cd.

7. PROJECT → PROPERTIES → C/C++ BUILD → BASIC OPTION


a. Target processor version(--silicon version, -mv) : 6400+
➔ OK.
b. IN C/C++ BUILD, → INCLUDE OPTIONS (Add dir to #include

search path(--include_path,-I)) select this add icon and add the


following three path by indivdually
➔ "${Diag}../../common/header"
➔ "${XDAIS_CG_ROOT}/packages/ti/xdais"
➔ "${C6000_CSL_CG_ROOT}/include"
8. FILE → NEW → TARGET CONFIGURATION FILE
a. file name: projectname. ccxml (.ccxml extension is must)
b. Connection: Texas Instrument XDS100 v1 USB Emulator.
c. Device: TMS320C6745. → SAVE → TARTGET
CONFIGURATION →C674X_0 →BROWSE, browse the
workspace location, open the gel folder and select the GEL file. →
OPEN →SAVE.
9. In C/C++ Project window, Right click the project →REBUILD PROJECT.
10. Connections :
a. Connect the usb cable, PC to KIT.
b. Connect the 5v adapter.
c. Power on the kit.
11. TARGET → DEBUG ACTIVE PROJECT.
12. TARGET → RUN.(wait to generate samples)
13. TARGET → HALT.
14. TOOLS → GRAPH → SINGLE TIME
a.Acquirstion buffer size : 256
b.Index increment : 1
c.Start address : 0xC0000000.
d.Display data size : 256 → Ok.
SOURCE CODE:

#include<stdio.h>
#include<math.h>
#define PI 3.14

void main()
{
const float sampf = 1024000.0;// Sampling frquency is fixed
const int inpf = 4000; // change the input frquency from 1khz to
//8khz(1000 to 8000)
float sampt;
double teta;
short value,*sinout;
int i,count,nsamp,value1;

sinout = (short *)0xc0000000;


sampt = 1/sampf;
nsamp = sampf/inpf;

printf("\n Sampling Frequency is : %f",sampf);


printf("\n Sampling Time is :%f",sampt);
printf("\n Input Frequency is : %d",inpf);
printf("\n The number of Sample is : %d",nsamp);

for(i=0;i<400;i++)
*(sinout+i)=0;
for(count=0;count<nsamp;count++)
{
teta = (2 * PI * inpf * sampt * count);
printf("\nteta = %lf",teta);

value = sin(teta)*1024; //Set amplitude by varying the


value //0 to 1024
printf("\t sin %lf Value is : %d",teta,value);

value1 = value&0x0000FFFF;
*sinout++ = value1;
}
}
OUTPUT

RESULT

Thus, the Sine waveform generation was generated and the sine samples is stored at
memory location(0xc0000000).
AIM
To Generate a Square wave form using TMS320C6745 DSP KIT.

COMPONENTS REQUIREMENTS

CCS v4
TMS320C6745 KIT
USB Cable
5V Adapter

ALGORITHM

1. Create a new project and initialize header file, input, output and variables to the
particular data type.
2. Set the memory address which is used to store the input and output values.
3. The output values (real time) are stored in the DAC Channel 1 memory
address (0xc0000000).
4. The total size of the triangular wave is 4096.The increment order starts from
1024 up to 1024 and decrement order starts from 1024 up to -1024 (totally
4096).
5. The first “for” loop is used for increment order and second “for” loop is used
for decrement order. This is nused for simulation output. The while loop is used
to get real time output.
6. Simulation output is displayed in Graph window & Real time output in the
CRO.

PROCEDURE
The procedures are same as previous experiment.
12. TARGET → RUN.(wait few seconds generate samples)
13. TARGET → HALT.
14. TOOLS → GRAPH → SINGLE TIME
a.Acquirstion buffer size : 1000
b.Index increment : 1
c.Start address : 0xC0000000.
d.Display data size : 1000 → Ok.

SOURCE CODE:
#include <stdio.h>
#include <math.h>
void main()
{
int *Square;
int i;
Square = (int *)0xC0000000;
while(1)
{
for(i=0;i<50;i++)
{
*Square++ = 0x0000FFFF;
}
for(i=0;i<50;i++)
{
*Square++ = 0x0;
}
}

OUTPUT
RESULT
Thus, the Square waveform was generated and samples is stored at memory
location(0xC0000000).
AIM:
To Generate a Triangle wave form using TMS320C6745 DSP KIT.

COMPONENTS REQUIREMENTS

a. CCS v4
b. TMS320C6745 KIT
c. USB Cable
d. 5V Adapter

ALGORITHM

1. Create a new project and initialize header file,input,output and variables to the
particular data type.
2. Set the memory address which is used to store the input and output values.
3. The output values (real time) are stored in the DAC Channel 1 memory
address (0xc0000000).
4. The total size of the triangular wave is 4096.The increment order starts from
1024 up to 1024 and decrement order starts from 1024 up to -1024 (totally
4096).
5. The first “for” loop is used for increment order and second “for” loop is used
for decrement order.This is used for simulation output.The while loop is used to
get real time output.
6. Simulation output is displayed in Graph window & Real time output in the
CRO.
PROCEDURE

The procedure 1 to 11 steps are same as previous experiment.


12. TARGET → RUN.(wait few seconds generate samples)
13. TARGET → HALT.
14. TOOLS → GRAPH → SINGLE TIME
a.Acquirstion buffer size : 500
b.Index increment : 1
c.Start address : 0xC0000000.
d.Display data size : 500 → Ok.

SOURCE CODE:

#include <stdio.h>
#include <math.h>
void main()
{
int *Triangle;
int i=0,j=0;
Triangle = (int *)0xC0000000;

while(1)
{
for(i=0;i<50;i++) //set frequency value
{
j=j+1; //set amplitude value
*Triangle++ = j;
}
for(i=50;i>0;i--)
{
j=j-1;
*Triangle++ = j;
}
}
}
OUTPUT:

RESULT:

Thus, the Triangle waveform was generated and samples is stored at memory
location(0xC0000000).
AIM:
To Generate a Sawtooth wave form using TMS320C6745 DSP KIT.

COMPONENTS REQUIREMENTS

a. CCS v4
b. TMS320C6745 KIT
c. USB Cable
d. 5V Adapter

ALGORITHM

1. create a new project and initialize header file,input,output and variables to the
particular data type.
2. Set the memory address which is used to store the input and output values.
3. The output values (real time) are stored in the DAC channel 1 memory
address(0xc0000000).
4. The total size of the sawtooth wave is 4096.The increment order start from -
1024 up to 1024 and decrement order start from 1024 up to -1024 (totally
4096).
5. The first “for” loop is used for increment order and second for loop is used for
decrement order.This is used for simulation output.The while loop used to get
real time output.
6. Simulation output is displayed in Graph window & Real time output in CRO.

PROCEDURE

The procedure 1 to 11 steps are same as previous experiment.


12. TARGET → RUN.(wait few seconds generate samples)
13. TARGET → HALT.
14. TOOLS → GRAPH → SINGLE TIME
a.Acquirstion buffer size : 500
b.Index increment : 1
c.Start address : 0xC0000000.
d.Display data size : 500 → Ok.

SOURCE CODE:

#include <stdio.h>
#include <math.h>
void main()
{
int *Sawtooth;
int i=0,j=0;
Sawtooth = (int *)0xC0000000;

while(1)
{
for(i=0;i<100;i++) //set the frequency value
{
j=j+1; //set the amplitude value
*Sawtooth++ = j;
}

j=0;
i=0;
*Sawtooth++ = j;
}
}
OUTPUT:

RESULT:
Thus, the Sawtooth waveform was generated and samples is stored at memory
location(0xC0000000).
AIM:
To perform the Linear Convolution of two given discrete sequence in
TMS320C6745 KIT.

COMPONENTS REQUIREMENTS

a. CCS v4
b. TMS320C6745 KIT
c. USB Cable
d. 5V Adapter

ALGORITHM

1. First declare the two inputs (x&h) and one output memory (y),Declare the
variables (i,k,n,l,m) for loop operation.
2. Declare the two input sequences length(xnlength&hnlength).
3. Give the length of xnlength & hnlength value.
4. Move the input sequence length data into two variables(l,m).
5. Give the input of x& hnvalue.
6. Clear the input,output and sequence length memories.
7. Declare the outer for loop of variables n is initially zero to formulae (l+m-l).
8. Next declare the inner loop of variables k is initially zero to outer loop of
variable n.
9. Finally declare the linear convolution formulae into a loop operation and the
output is stored to the y[n] location.
PROCEDURE:

15. Open Code Composer Studio v4 .


16. In WorkSpace Launcher.
a. BROWSE → Select the project location and make one new folder,
MAKE NEW FOLDER →Type the Workspace name, OK → OK.
17. FILE → NEW → CCS PROJECT
a. Project name: Type your project name.
b. Tick use default location. →NEXT
c. Project type: C6000.
d. Tick Debug And Release. →NEXT → NEXT.
e. Output type: Executable.
f. Device Variant : generic C67XX Device.
g. Device Endianness : little
h. Code Generation Tools: TI v6.1.12.
i. Run time support library: automatic.
j. Target content: none. →FINISH
18. FILE → NEW → SOURCE FILE
a. Source file: Type your projectname.c( .c extension is must ).
b. Type the program.
c. FILE → SAVE.
19. Paste the following board library files in workspace location.
a. Common folder (contains header files)
b. Gel folder (contains gel file)
c. Library folder(contains library files)
20. Paste the Linker file in the project location.(linker file is available in cd)
Note: Those folders and linker file are availble at cd.
21. PROJECT → PROPERTIES → C/C++ BUILD → BASIC OPTION
a. Target processor version(--silicon version, -mv) : 6400+
➔ OK.
b. IN C/C++ BUILD, → INCLUDE OPTIONS (Add dir to #include

search path(--include_path,-I)) select this add icon and add the


following three path by indivdually
➔ "${Diag}../../common/header"
➔ "${XDAIS_CG_ROOT}/packages/ti/xdais"
➔ "${C6000_CSL_CG_ROOT}/include"
22. FILE → NEW → TARGET CONFIGURATION FILE
a. file name: projectname. ccxml (.ccxml extension is must)
b. Connection: Texas Instrument XDS100 v1 USB Emulator.
c. Device: TMS320C6745. → SAVE → TARTGET
CONFIGURATION →C674X_0 →BROWSE, browse the
workspace location, open the gel folder and select the GEL file. →
OPEN →SAVE.
23. In C/C++ Project window, Right click the project →REBUILD PROJECT.
24. Connections :
a. Connect the usb cable, PC to KIT.
b. Connect the 5v adapter.
c. Power on the kit.
25. TARGET → DEBUG ACTIVE PROJECT.
26. VIEW → MEMORY.
27. In right side, memory window will open. Type the adrress and give the input at
particular location.

Give the length as follow:


Xnlength hnlength
0xc0010000-4 0xc0100000-4
Give the input as follow:
X(n) h(n)
0xC0000000 – 00000001 0xC0000100 – 00000001
0xC0000004 – 00000001 0xC0000104 – 00000001
0xC0000008 – 00000001 0xC0000108 – 00000001
0xC000000C – 00000001 0xC000010C – 00000001

28. TARGET → RUN.


29. TARGET → HALT.
See the Output at Particular location:
Example :
0xC0001000 – 00000001
0xC0001004 – 00000002
0xC0001008 - 00000003
0xC000100C - 00000004
0xC0001010 - 00000003
0xC0001014 - 00000002
0xC0001018 – 00000001

SOURCE CODE

#include<stdio.h>

void main()
{
int *x,*h,*y,i,n,k,l,m,*xnlength,*hnlength;

xnlength=(int *)0xc0010000;
hnlength=(int *)0xc0100000;
l=*xnlength;
m=*hnlength;

x = (int *)0xc0000000;
h = (int *)0xc0000100;
y = (int *)0xc0001000;

for(i=0;i<(l+m-1);i++)
{
y[i]=0;
x[l+i]=0;
h[m+i]=0;
}
for(n=0;n<(l+m-1);n++)
{
for(k=0;k<=n;k++)
y[n] = (y[n]) + ((x[k])*(h[n-k]));
}
while(1);
}

RESULT
Thus, the Linear Convolution of two given discrete sequence has performed and the
result is stored at memory location(0xc0001000).
AIM

To perform the Circular Convolution of two given discrete sequence in


TMS320C6745 KIT.

COMPONENTS REQUIREMENTS

CCS v4
TMS320C6745 KIT
USB Cable
5V Adapter

ALGORITHM

1. First declare the two input variables (xn&hn) and one output variables
(y),Declare the variables (i,n,m,n,l,a,b,k) for loop operation.
2. Declare the two input sequences length(xnlength&hnlength).
3. Give the length of xnlength & hnlength value.
4. Give the input of xn & hn value.
5. Next check whether xn length greater or hn length is greater.Take the greater
number that is the length of the circular convolution length(n).
6. Then do memory clear operation.
7. .Next perform convolution operation to two input sequences.For hn[n-k] output
is lesser than 0 means add n (hn[n-k+n],this is perform shifting operation of
second sequences.
8. .The output is stored to the y[n] location.
PROCEDURE

The procedure 1 to 11 steps are same as previous experiment.


12. VIEW → MEMORY
13. In right side, memory window will open. Type the adrress and give the
input at particular location.

Give the length as follow:


Xnlength hnlength
0xc0010000-4 0xc0100000-4

Give the input as follow:


X(n) h(n)
0xC0000000 – 00000001 0xC0000100 – 00000001
0xC0000004 – 00000001 0xC0000104 – 00000001
0xC0000008 – 00000001 0xC0000108 – 00000001
0xC000000C – 00000001 0xC000010C – 00000001

14. TARGET → RUN.


15. TARGET → HALT.

See the Output at Particular location:


Example :
0xC0001000 – 00000004
0xC0001004 – 00000004
0xC0001008 - 00000004
0xC000100C - 00000004
SOURCE CODE

#include<stdio.h>
void main()
{
int *xn,*hn,*y,*xnlength,*hnlength;
int i,n,m,a,b,l,k;
xn = (int *)0xc0000000;
hn = (int *)0xc0000100;
y = (int *)0xc0001000;
xnlength=(int *)0xc0010000;
hnlength=(int *)0xc0100000;

a=*xnlength;
b=*hnlength;
if(a<b)
k=b;
else
k=a;
for(i=0;i<k;i++)
{
y[i]=0;
xn[a+i]=0;
hn[b+i]=0;
}
for(n=0;n<k;n++)
{
for(m=0;m<k;m++)
{
l=n-m;
if(l<0)
l=l+k;
y[n]=y[n]+(xn[m]*hn[l]);
}
}
}

RESULT
Thus, the Circular Convolution of two given discrete sequence has performed
and the result is stored at memory location(0xC0001000).
AIM:
To perform the 8 point FFT using DIT process from a given discrete sequence
in TMS320C6745 KIT.

COMPONENTS REQUIREMENTS

a. CCS v 4
b. TMS320C6745 KIT
c. USB Cable
d. 5V Adapter

ALGORITHM

1. First initialize all the inputs and ouputs arrays.


2. Delare the twiddle factor values.
3. Delare the address value of inputs and outputs.(Real value & imaginary).
4. Load the input values to the input array t[8].
5. Take the bit reversal process.
6. First stage computation with 2-point dft.
7. second stage computation with 4-point dft.
8. Third stage computation with 8-point dft.
PROCEDURE:

The procedure 1 to 11 steps are same as previous experiment.


12. VIEW → MEMORY
13. In right side, memory window will open. Type the adrress and give
the input at particular location.
Give the input as follow:
a. Enter An Address:0xC0001000 → Enter.(Input)
X(n)
0xC0001000 – 00000001
0xC0001004 – 00000002
0xC0001008 – 00000003
0xC000100C – 00000004
0xC0001010 – 00000004
0xC0001014 – 00000003
0xC0001018 – 00000002
0xC000101C – 00000001

14. View → Watch window → watch1.


b. Type the following array variable.
➔ Xr( real part output)
➔ Xi( imaginary part output)
15.TARGET → RUN.
16.TARGET → HALT.

See the Output at Particular location:


Example :
a.Enter An Address:0xC0001030 → Enter.(Real part output)

0xC0001030 – 00000014
0xC0001034 – FFFFFFFB
0xC0001038 – 00000000
0xC000103C – 00000000
0xC0001040 – 00000000
0xC0001044 – 00000000
0xC0001048 – 00000000
0xC000104C – FFFFFFFB

b.Enter An Address:0xC0001050 → Enter.(Imaginary part output)


0xC0001050 – 00000000
0xC0001054 – FFFFFFFFF
0xC0001058 – 0000000C
0xC000105C – 00000000
0xC0001060 – 00000000
0xC0001064 – 00000000
0xC0001068 – 00000000
0xC000106C - 00000002

17. Or see the ouput at watch window.

Note: watch window will show exact decimal values, processor memory
location will show a hexadecimal values.
SOURCE CODE

#include <math.h>
#define PI 3.14159
float x[8],t[8],s1[8],s2r[8],s2i[8],Xr[8],Xi[8],Yr[8],Yi[8];
const float W0r = 1,
W0i = 0,
W1r = 0.707,
W1i = -0.707,
W2r = 0,
W2i = -1,
W3r = -0.707,
W3i = -0.707;
void main()
{
int *Input,*Real_out,*Imag_out;
int i=0,j=0;
Input = (int *)0xC0001000;
Real_out = (int *)0xC0001030;
Imag_out = (int *)0xC0001050;

for(i=0;i<8;i++)
{
t[i] = 0;
t[i] = *(Input + i);
}

// Bit reversal process


x[0] = t[0];
x[1] = t[4];
x[2] = t[2];
x[3] = t[6];
x[4] = t[1];
x[5] = t[5];
x[6] = t[3];
x[7] = t[7];
// stage one process
s1[0] = (int)(x[0] + (x[1] * W0r));
s1[1] = (int)(x[0] - (x[1] * W0r));
s1[2] = (int)(x[2] + (x[3] * W0r));
s1[3] = (int)(x[2] - (x[3] * W0r));
s1[4] = (int)(x[4] + (x[5] * W0r));
s1[5] = (int)(x[4] - (x[5] * W0r));
s1[6] = (int)(x[6] + (x[7] * W0r));
s1[7] = (int)(x[6] - (x[7] * W0r));
// stage two process
s2r[0] = (s1[0] + (s1[2] * W0r));
s2i[0] = 0;

s2r[1] = s1[1];
s2i[1] = (s1[3] * W2i);

s2r[2] = (s1[0] - (s1[2] * W0r));


s2i[2] = 0;

s2r[3] = s1[1];
s2i[3] = - (s1[3] * W2i);

s2r[4] = (s1[4] + (s1[6] * W0r));


s2i[4] = 0;

s2r[5] = s1[5];
s2i[5] = (s1[7] * W2i);

s2r[6] = (s1[4] - (s1[6] * W0r));


s2i[6] = 0;

s2r[7] = s1[5];
s2i[7] = -(s1[7] * W2i);

// output
// complex multiplication for B * Wn

Yr[0] = (s2r[4] * W0r) - (s2i[4] * W0i);


Yi[0] = (s2r[4] * W0i) + (s2i[4] * W0r);

Yr[1] = (s2r[5] * W1r) - (s2i[5] * W1i);


Yi[1] = (s2r[5] * W1i) + (s2i[5] * W1r);

Yr[2] = (s2r[6] * W2r) - (s2i[6] * W2i);


Yi[2] = (s2r[6] * W2i) + (s2i[6] * W2r);

Yr[3] = (s2r[7] * W3r) - (s2i[7] * W3i);


Yi[3] = (s2r[7] * W3i) + (s2i[7] * W3r);
Yr[4] = (s2r[4] * W0r) - (s2i[4] * W0i);
Yi[4] = (s2r[4] * W0i) + (s2i[4] * W0r);
Yr[5] = (s2r[5] * W1r) - (s2i[5] * W1i);
Yi[5] = (s2r[5] * W1i) + (s2i[5] * W1r);
Yr[6] = (s2r[6] * W2r) - (s2i[6] * W2i);
Yi[6] = (s2r[6] * W2i) + (s2i[6] * W2r);

Yr[7] = (s2r[7] * W3r) - (s2i[7] * W3i);


Yi[7] = (s2r[7] * W3i) + (s2i[7] * W3r);

// complex addition for A + BWn

j=0;
for(i=0;i<4;i++)
{
Xr[i] = s2r[j] + Yr[i];
Xi[i] = s2i[j] + Yi[i];
j++;
}

// complex subtraction for A - BWn

j=0;
for(i=4;i<8;i++)
{
Xr[i] = s2r[j] - Yr[i];
Xi[i] = s2i[j] - Yi[i];
j++;
}

// sending output array to memory location

for(i=0;i<8;i++)
{
*Real_out ++= Xr[i];
*Imag_out ++= Xi[i];
}

for(;;);
}

RESULT

Thus, the 8 point FFT of given discrete sequence has performed and the result
is stored at memory location (0xC0001030 and 0xC0001050).
AIM
To perform the 8 point FFT using DIF process from a given discrete sequence
in TMS320C6745 KIT.
COMPONENTS REQUIREMENTS
a. CCS v 4
b. TMS320C6745 KIT
c. USB Cable
d. 5V Adapter
ALGORITHM
1. First initialize all the inputs and ouputs arrays.
2. Delare the twiddle factor values.
3. Delare the address value of inputs and outputs.(Real value & imaginary).
4. Load the input values to the input array t[8].
5. First stage computation with 2-point dft.
6. second stage computation with 4-point dft.
7. Third stage computation with 8-point dft.
8. Take the bit reversal process.
PROCEDURE

The procedure 1 to 11 steps are same as previous experiment.


12. VIEW → MEMORY
13. In right side, memory window will open. Type the adrress and give the
input at particular location.
Give the input as follow:
a. Enter An Address:0xC0001000 → Enter.(Input)
X(n)
0xC0001000 – 00000001
0xC0001004 – 00000002
0xC0001008 – 00000003
0xC000100C – 00000004
0xC0001010 – 00000004
0xC0001014 – 00000003
0xC0001018 – 00000002
0xC000101C – 00000001

14. View → Watch window → watch1.


b. Type the following array variable.
➔ tr( real part output)
➔ ti( imaginary part output)
15.TARGET → RUN.
16.TARGET → HALT.

See the Output at Particular location:


Example :
a.Enter An Address:0xC0001030 → Enter.(Real part output)
0xC0001030 – 00000014
0xC0001034 – FFFFFFFB
0xC0001038 – 00000001
0xC000103C – 00000000
0xC0001040 – 00000000
0xC0001044 – 00000000
0xC0001048 – 00000000
0xC000104C – FFFFFFFB
b.Enter An Address:0xC0001050 → Enter.(Imaginary part output)
0xC0001050 – 00000000
0xC0001054 – FFFFFFFFE
0xC0001058 – 00000000
0xC000105C – 00000000
0xC0001060 – 00000000
0xC0001064 – 00000000
0xC0001068 – 00000000
0xC000106C – 00000002

17. Or see the output at watch window.


Note: watch window will show exact decimal values, processor memory
location will show a hexadecimal values.

SOURCE CODE
#include <math.h>
#define PI 3.14159
float x[8],tr[8],ti[8],s1r[8],s1i[8],s2r[8],s2i[8],Xr[8],Xi[8],Yr[8],Yi[8];
const float W0r = 1,
W0i = 0,
W1r = 0.707,
W1i = -0.707,
W2r = 0,
W2i = -1,
W3r = -0.707,
W3i = -0.707;
void main()
{
int *Input,*Real_out,*Imag_out;
int i=0;

Input = (int *)0xC0001000;


Real_out = (int *)0xC0001030;
Imag_out = (int *)0xC0001050;

for(i=0;i<8;i++)
{
x[i] = 0;
x[i] = *(Input + i);
}
// stage one process
s1r[0] = (int)(x[0] + x[4]);
s1i[0] = 0;
s1r[1] = (int)(x[1] + x[5]);
s1i[1] = 0;
s1r[2] = (int)(x[2] + x[6]);
s1i[2] = 0;
s1r[3] = (int)(x[3] + x[7]);
s1i[3] = 0;
s1r[4] = (int)(x[0] - x[4]) * W0r;
s1i[4] = 0;
s1r[5] = (int)(x[1] - x[5]) * W1r;
s1i[5] = (int)(x[1] - x[5]) * W1i;
s1r[6] = 0;
s1i[6] = (int)(x[2] - x[6]) * W2i;
s1r[7] = (int)(x[3] - x[7]) * W3r;
s1i[7] = (int)(x[3] - x[7]) * W3i;

// stage two process


s2r[0] = (s1r[0] + s1r[2]);
s2i[0] = (s1i[0] + s1i[2]);
s2r[1] = (s1r[1] + s1r[3]);
s2i[1] = (s1i[1] + s1i[3]);
s2r[2] = (s1r[0] - s1r[2]) * W0r;
s2i[2] = 0; // (s1i[0] - s1i[2]) * W0i;
s2r[3] = 0; // (s1r[1] - s1r[3]) * W2r;
s2i[3] = (s1r[1] - s1r[3]) * W2i;

s2r[4] = (s1r[4] + s1r[6]);


s2i[4] = (s1i[4] + s1i[6]);
s2r[5] = (s1r[5] + s1r[7]);
s2i[5] = (s1i[5] + s1i[7]);
s2r[6] = (s1r[4] - s1r[6]) * 1;
s2i[6] = (s1i[4] - s1i[6]) * 1;

Yr[0] = s1r[5] - s1r[7];


Yi[0] = s1i[5] - s1i[7];

Yr[1] = ((Yr[0] * W2r) - (Yi[0] * W2i));


Yi[1] = ((Yr[0] * W2i) + (Yi[0] * W2r));
s2r[7] = Yr[1];
s2i[7] = Yi[1];
// output
Xr[0] = (s2r[0] + s2r[1]);
Xi[0] = (s2i[0] + s2i[1]);
Xr[1] = (s2r[0] - s2r[1]);
Xi[1] = (s2i[0] - s2i[1]);
Xr[2] = (s2r[2] + s2r[3]);
Xi[2] = (s2i[2] + s2i[3]);
Xr[3] = (s2r[2] - s2r[3]);
Xi[3] = (s2i[2] - s2i[3]);
Xr[4] = (s2r[4] + s2r[5]);
Xi[4] = (s2i[4] + s2i[5]);
Xr[5] = (s2r[4] - s2r[5]);
Xi[5] = (s2i[4] - s2i[5]);
Xr[6] = (s2r[6] + s2r[7]);
Xi[6] = (s2i[6] + s2i[7]);
Xr[7] = (s2r[6] - s2r[7]);
Xi[7] = (s2i[6] - s2i[7]);

// bit reversal
tr[0] = Xr[0];
ti[0] = Xi[0];
tr[1] = Xr[4];
ti[1] = Xi[4];
tr[2] = Xr[2];
ti[2] = Xi[2];
tr[3] = Xr[6];
ti[3] = Xi[6];
tr[4] = Xr[1];
ti[4] = Xi[1];
tr[5] = Xr[5];
ti[5] = Xi[5];
tr[6] = Xr[3];
ti[6] = Xi[3];
tr[7] = Xr[7];
ti[7] = Xi[7];
// sending output array to memory location
for(i=0;i<8;i++)
{
*Real_out ++= tr[i];
*Imag_out ++= ti[i];
}
for(;;)
}
RESULT
Thus, the 8 point FFT of given discrete sequence has performed and the result
is stored at memory location(0xC0001030 and 0xC0001050).
AIM
To Implement the FIR Low pass filter using TMS320C6745 KIT

COMPONENTS REQUIREMENTS
CCS v4
TMS320C6745 KIT
USB Cable
5V Adapter
Function Generator
DSO

ALGORITHM

1. First include the stdio.h file,math.h file,c6745.h file.spiadc.h file and spidac.h
file.
2. Define the analog to digital converter function.
3. Declare the spi write function.
4. Declare the local variables and global variables.
5. Define the lowpass co-efficent values to the arrays.
6. Initialize the c6745 function,spiadc function,spidac function.
7. set the commands for the read the adc values.
8. Multiply the co-efficent values and adc values and store to the temp variables.
9. Then we add temp plus sum and move to the sum variables.
10. set they delay function (xval[i+1]=xval[i]).
11. Finally adc values sent to spi write function and recover the original signal
from dac.
PROCEDURE
The procedures 1 to 11 steps are same as previous experiment.
12.paste the following header file in the project location.
a.spiadc.h
b.spidac.h
13.Set the sine wave at 3v from function generator.
14.Connect the FG output to ADC connector(jp1).
15. Connect the DSO at DAC connector(j2).
16. TARGET → RUN.
17. Output is displayed at DSO.
18. TARGET → HALT.
FDA tool for low-pass filter co-efficient generation:
Click Matlab ---- Type fdatool
Response type --- Lowpass
Design method --- Fir --- Equiripple
Specify order --- 50
Density factor --- 20
Frequency specifications
Units --- HZ
FS --- 6000
Fpass --- 200
Fstop ---400

Magnitude specification
Wpass --- 1
Wstop --- 1

Generate c Header:
Targets --- Generate c Header
✓ Click Export as
✓ Select single precision floating point
✓ Generate ----- save(any name)
✓ Open the saved folter.
✓ Copy the filter co-efficient and paste (float h[51]) in the program.

SOURCE CODE
#include <stdio.h>
#include <math.h>
#include "c6745.h"
#include "spiadc.h"
#include "spidac.h"

#defineDAC_CS_LOW(); SPI0_SPIPC3 = 0x0;


//(CS=Low:Enable)
#defineDAC_CS_HIGH(); SPI0_SPIPC3 = 0x1;
//(CS=High:Disable)

void SPI_Write(unsigned short Data);

unsigned short i,j=0,High,Value=0;


signed int adc_value;

//Low Pass samp fr=6khz sbf=200 pbf=400

float h[51] = {
0.01060591545, 0.004117832519, 0.004079894163, 0.003353076056,
0.001853102469,
-0.0004065925605,-0.003321184311,-0.006660183426, -0.01010407601, -
0.01322921738,
-0.01557052694, -0.01663137041, -0.01597031951, -0.01320868172,-
0.008123514242,
-0.000646590197, 0.0090885479, 0.02072319016, 0.03375224397,
0.04746999219,
0.06107512116, 0.07372291386, 0.08458722383, 0.09293565154,
0.09818658978,
0.09997936338, 0.09818658978, 0.09293565154, 0.08458722383,
0.07372291386,
0.06107512116, 0.04746999219, 0.03375224397, 0.02072319016,
0.0090885479,
-0.000646590197,-0.008123514242, -0.01320868172, -0.01597031951, -
0.01663137041,
-0.01557052694, -0.01322921738, -0.01010407601,-0.006660183426,-
0.003321184311,
-0.0004065925605, 0.001853102469, 0.003353076056, 0.004079894163,
0.004117832519,
0.01060591545
};

void main( void )


{
Uint8 spiadcbuf[3];
int i,xval[120],k;
float temp,sum;

C6745_init();
spiadc_init();
spidac_init();

for(i=0;i<52;i++)
{
xval[i]=0;
}

while(1)
{
spiadcbuf[0] = 0x01; // setup command
spiadcbuf[1] = 0xBF;
spiadcbuf[2] = 0x00;

spiadc_cycle(spiadcbuf, 3); // Execute spiadc read cycle


adc_value = ((spiadcbuf[1]&0x0f) << 8)| spiadcbuf[2];

xval[0] = adc_value;

sum = 0;
for(k=0;k<51;k++)
{
temp = (xval[k])*(h[k]);
sum = sum + temp;
}
SPI_Write(sum);

for(i=50;i>=0;i--)
{
xval[i+1] = xval[i];
}
}
}

/****************************/
/* GLCD SPI Sent Data 8 bit */
/****************************/
void SPI_Write(unsigned short Data)
{
unsigned short receive;

DAC_CS_LOW();
Data = ( 0x3000 | Data );

/* Clear any old data */


receive = SPI0_SPIBUF;

// Wait for transmit ready


while( SPI0_SPIBUF & 0x10000000 );

/* Write 1 byte */
SPI0_SPIDAT1 = Data;
while((SPI0_SPIBUF & 0x20000000)==1);

/* Read 1 byte */
receive = SPI0_SPIBUF;

for(i=0;i<10;i++);
DAC_CS_HIGH();
}
INPUT

OUTPUT
RESULT
Thus, the FIR Low pass filter was Implemented and displayed the results in
console window.
AIM
To Implement the FIR High pass filter using TMS320C6745 KIT

COMPONENTS REQUIREMENTS

a. CCS v4
b. TMS320C6745 KIT
c. USB Cable
d. 5V Adapter
e. Function Generator
f. DSO

ALGORITHM

1. First include the stdio.h file,math.h file,c6745.h file.spiadc.h file and spidac.h
file.
2. Define the analog to digital converter function.
3. Declare the spi write function.
4. Declare the local variables and global variables.
5. Define the highpass co-efficent values to the arrays.
6. Initialize the c6745 function,spiadc function,spidac function.
7. set the commands for the read the adc values.
8. Multiply the co-efficent values and adc values and store to the temp variables.
9. Then we add temp plus sum and move to the sum variables.
10. Then add the DC offset value(1625) with sum variable.
11. .set they delay function (xval[i+1]=xval[i]).
12. .Finally adc values sent to spi write function and recover the original signal
from dac.
PROCEDURE

The procedures 1 to 11 steps are same as previous experiment.


12.paste the following header file in the project location.
a.spiadc.h
b.spidac.h
13.Set the sine wave at 3v from function generator.
14.Connect the FG output to ADC connector(jp1).
15. Connect the DSO at DAC connector(j2).
16. TARGET → RUN.
17. Output is displayed at DSO.
18. TARGET → HALT.

FDA tool for filter co-efficient generation:

Click Matlab --- Type fdatool


Response type --- Highpass
Design method --- Fir --- Equiripple
Specify order --- 50
Density factor --- 20

Frequency specifications
Units ---HZ
FS --- 6000
Fpass --- 400
Fstop --- 200

Magnitude specification
Wpass --- 1
Wstop --- 1
Generate c Header:
Targets --- Generate c Header
✓ Click Export as
✓ Select single precision floating point
✓ Generate ----- save(any name)
✓ Open the saved folter.
✓ Copy the filter co-efficient and paste (float h[51]) in the program.

SOURCE CODE

#include <stdio.h>
#include <math.h>
#include "c6745.h"
#include "spiadc.h"
#include "spidac.h"

#defineDAC_CS_LOW(); SPI0_SPIPC3 = 0x0;


//(CS=Low:Enable)
#defineDAC_CS_HIGH(); SPI0_SPIPC3 = 0x1;
//(CS=High:Disable)

void SPI_Write(unsigned short Data);

unsigned short i,j=0,High,Value=0;


signed int adc_value;

//High Pass sf=6khz sbf=200 pbf=400

float h[51] ={
-0.01060591545,-0.004117832519,-0.004079894163,-0.003353076056,-
0.001853102469,
0.0004065925605, 0.003321184311, 0.006660183426, 0.01010407601,
0.01322921738,
0.01557052694, 0.01663137041, 0.01597031951, 0.01320868172,
0.008123514242,
0.000646590197, -0.0090885479, -0.02072319016, -0.03375224397, -
0.04746999219,
-0.06107512116, -0.07372291386, -0.08458722383, -0.09293565154, -
0.09818658978,
0.900020659, -0.09818658978, -0.09293565154, -0.08458722383, -
0.07372291386,
-0.06107512116, -0.04746999219, -0.03375224397, -0.02072319016, -
0.0090885479,
0.000646590197, 0.008123514242, 0.01320868172, 0.01597031951,
0.01663137041,
0.01557052694, 0.01322921738, 0.01010407601, 0.006660183426,
0.003321184311,
0.0004065925605,-0.001853102469,-0.003353076056,-0.004079894163,-
0.004117832519,
-0.01060591545
};
void main( void )
{
Uint8 spiadcbuf[3];
int i,xval[120],k;
float temp,sum;

C6745_init();
spiadc_init();
spidac_init();

for(i=0;i<52;i++)
{
xval[i]=0;
}

while(1)
{
spiadcbuf[0] = 0x01; // setup command
spiadcbuf[1] = 0xBF;
spiadcbuf[2] = 0x00;

spiadc_cycle(spiadcbuf, 3); // Execute spiadc read cycle


adc_value = ((spiadcbuf[1]&0x0f) << 8)| spiadcbuf[2];

xval[0] = adc_value;

sum = 0;
for(k=0;k<51;k++)
{
temp = (xval[k])*(h[k]);
sum = sum + temp;
}

SPI_Write(sum+1625);

for(i=50;i>=0;i--)
{
xval[i+1] = xval[i];
}
}
}

/****************************/
/* GLCD SPI Sent Data 8 bit */
/****************************/
void SPI_Write(unsigned short Data)
{
unsigned short receive;

DAC_CS_LOW();
Data = ( 0x3000 | Data );

/* Clear any old data */


receive = SPI0_SPIBUF;

// Wait for transmit ready


while( SPI0_SPIBUF & 0x10000000 );

/* Write 1 byte */
SPI0_SPIDAT0 = Data;
while((SPI0_SPIBUF & 0x20000000)==1);

/* Read 1 byte */
receive = SPI0_SPIBUF;

for(i=0;i<10;i++);
DAC_CS_HIGH();
}

INPUT
OUTPUT
RESULT
Thus, the FIR High pass filter was Implemented and displayed the results in
console window.
AIM:
To Implement the IIR Low pass filter using TMS320C6745 KIT

COMPONENTS REQUIREMENTS
CCS v4
TMS320C6745 KIT
USB Cable
5V Adapter
Function Generator
DSO

ALGORITHM

1. First include the header files(stdio.h,math.h,c6745.h,spiadc.h and spidac.h)


2. Define dac chip select lines function and gain values.
3. Declare the spi write function,input co-efficient function and chebyshev filter
function.
4. Declare the input co-efficients (a0,a1,a2 &b0,b1,b2)
5. Declare the local variables in main function.
6. .Initialize c6745,spiadc and spidac function.
7. Read the adc values and send to the chebyshev low pass filter
function.(yv=(b0*xv[0]+b2*xv[2])+b1*xv[1]-(a2*yv[0])-(a1*yv[1]))
8. Then the output value multiply with gain value.
9. The vout value return to the spi write function and finally the low pass filter
signal recover from dac (j2) connector.
10. Finally show the output waveform at DSO from dac.
PROCEDURE
The procedures 1 to 11 steps are same as previous experiment.
12.paste the following header file in the project location.
a.spiadc.h
b.spidac.h
13.Set the sine wave at 3v from function generator.
14.Connect the FG output to ADC connector(jp1).
15. Connect the DSO at DAC connector(j2).
16. TARGET → RUN.
17. Output is displayed at DSO.
18. TARGET → HALT.
Generate co-efficient by using scope iir:
Type --- chebyshev

Sampling frequency --- 6000HZ

Order --- 2

Cut-off --- 400HZ

Frequency :
Response --- select Lowpass

Co-efficient --- fixed point

Passband ripple --- 1dB

Stopband attenuation --- 80dB

Gain --- 1dB

Tick --- Use biquads

Tick --- Adjust for ripple

Tick --- Automatic

Type the a0,a1,a2 & b0,b1,b2 and Gain value (float &#define GAIN) in your c
code.

SOURCE CODE
#include <stdio.h>
#include <math.h>
#include "c6745.h"
#include "spiadc.h"
#include "spidac.h"

#defineDAC_CS_LOW(); SPI0_SPIPC3 = 0x0;


//(CS=Low:Enable)
#defineDAC_CS_HIGH(); SPI0_SPIPC3 = 0x1;
//(CS=High:Disable)
#define GAIN 0.03882011771
void SPI_Write(unsigned short Data);

static float xv[3], yv[3];

int Chebyshev(int input);

//LP co-efficient samp fr=6khz passband fr=400hz


float a0=1,a1=-1.481033206,a2= 0.6363137364;
float b0=1,b1=2,b2=1;

void main( void )


{
static Uint8 spiadcbuf[3];
int adc_value,vout=0;

C6745_init();
spiadc_init();
spidac_init();

while(1)
{
spiadcbuf[0] = 0x01; // setup command
spiadcbuf[1] = 0xBF;
spiadcbuf[2] = 0x00;

spiadc_cycle(spiadcbuf, 3); // Execute spiadc read cycle


adc_value = ((spiadcbuf[1]&0x0f) << 8)| spiadcbuf[2];

vout = Chebyshev(adc_value);
SPI_Write(vout);
}
}

/****************************/
/* GLCD SPI Sent Data 8 bit */
/****************************/
void SPI_Write(unsigned short Data)
{
unsigned short receive,j;

DAC_CS_LOW();
Data = ( 0x3000 | Data );

/* Clear any old data */


receive = SPI0_SPIBUF;

// Wait for transmit ready


while( SPI0_SPIBUF & 0x10000000 );

/* Write 1 byte */
SPI0_SPIDAT1 = Data;
while((SPI0_SPIBUF & 0x20000000)==1);

/* Read 1 byte */
receive = SPI0_SPIBUF;

for(j=0;j<10;j++);
DAC_CS_HIGH();
}

int Chebyshev(int input)


{
int vout=0;
xv[0] = xv[1];
xv[1] = xv[2];
xv[2] = input;
yv[0] = yv[1];
yv[1] = yv[2];
yv[2] = (b0*xv[0] + b2*xv[2]) + b1 * xv[1] - ( a2 * yv[0]) - ( a1 *
yv[1]);
vout = yv[2]*GAIN;
return vout;
}

INPUT:
OUTPUT:
RESULT
Thus, the IIR Low pass filter was Implemented and displayed the results in dso
window.
AIM
To Implement the IIR High pass filter using TMS320C6745 KIT.

COMPONENTS REQUIREMENTS

CCS v4
TMS320C6745 KIT
USB Cable
5V Adapter
Function Generator
DSO
ALGORITHM

1. First include the header files(stdio.h,math.h,c6745.h,spiadc.h and spidac.h)


2. Define dac chip select lines function,gain values and dc offset values.
3. Declare the spi write function,input co-efficient function and chebyshev filter
function.
4. Declare the input co-efficients (a0,a1,a2 &b0,b1,b2)
5. Declare the local variables in main function.
6. Initialize c6745,spiadc and spidac function.
7. Read the adc values and send to the chebyshev high-pass filter
function.(yv=(b0*xv[0]+b2*xv[2])+b1*xv[1]-(a2*yv[0])-(a1*yv[1]))
8. Then the output value multiply with gain value.
9. The vout value return to the spi write function and add the dc offset value with
vout variables.
10. Check the 12-bit values by using if-condition.
11. spi write function move to the spi dac function.
12. Finally show the output waveform at DSO from dac.
PROCEDURE
The procdure 1 to 11 steps are same as previous experiment.
12.Set the sine wave at 3v from function generator.
13.Connect the FG output to ADC connector(jp1).
14. Connect the DSO to DAC connector(j2).
15. TARGET → RUN.
13. Output is displayed at DSO.
14. TARGET → HALT

Generate co-efficient by using scope iir:

Type --- chebyshev


Sampling frequency --- 6000HZ
Order --- 2
Frequency :
Response --- select Highpass
Cut-off --- 600HZ
Co-efficient --- fixed point
Passband ripple --- 1dB
Stopband attenuation --- 80dB
Gain --- 1dB
Tick --- Use biquads
Tick --- Adjust for ripple
Tick --- Automatic
Type the a0,a1,a2 & b0,b1,b2 and Gain value (float &#define GAIN) in your c
code.

SOURCE CODE

#include <stdio.h>
#include <math.h>
#include "c6745.h"
#include "spiadc.h"
#include "spidac.h"

#defineDAC_CS_LOW(); SPI0_SPIPC3 = 0x0;


//(CS=Low:Enable)
#defineDAC_CS_HIGH(); SPI0_SPIPC3 = 0x1;
//(CS=High:Disable)
#define DCOFFSET 2711
//HP
#define GAIN 0.7045881152
void SPI_Write(unsigned short Data);

static float xv[3], yv[3];


int Chebyshev(int input);

//HP co-efficient samp fr=6khz passband fr=600hz


float a0=1,a1=-1.27423811,a2= 0.5441143513;
float b0= 1,b1=-2,b2=1;

void main( void )


{
static Uint8 spiadcbuf[3];
int adc_value,vout=0;

C6745_init();
spiadc_init();
spidac_init();

while(1)
{
spiadcbuf[0] = 0x01;

// setup command
spiadcbuf[1] = 0xBF;
spiadcbuf[2] = 0x00;

spiadc_cycle(spiadcbuf, 3);
//
Execute spiadc read cycle
adc_value = ((spiadcbuf[1]&0x0f) << 8)| spiadcbuf[2];

vout = Chebyshev(adc_value);
vout = vout + DCOFFSET;
if(vout>4095) vout=4095;
SPI_Write(vout);
}
}

/****************************/
/* GLCD SPI Sent Data 8 bit */
/****************************/
void SPI_Write(unsigned short Data)
{
unsigned short receive,j;
DAC_CS_LOW();
Data = ( 0x3000 | Data );

/* Clear any old data */


receive = SPI0_SPIBUF;

// Wait for transmit ready


while( SPI0_SPIBUF & 0x10000000 );

/* Write 1 byte */
SPI0_SPIDAT1 = Data;
while((SPI0_SPIBUF & 0x20000000)==1);

/* Read 1 byte */
receive = SPI0_SPIBUF;

for(j=0;j<10;j++);
DAC_CS_HIGH();
}

int Chebyshev(int input)


{
int vout=0;
xv[0] = xv[1];
xv[1] = xv[2];
xv[2] = input;
yv[0] = yv[1];
yv[1] = yv[2];
yv[2] = (b0*xv[0] + b2*xv[2]) + b1 * xv[1] - ( a2 * yv[0]) - ( a1
* yv[1]);
vout = yv[2]*GAIN;
return vout;

INPUT:
OUTPUT:
RESULT
Thus, the IIR High pass filter was implemented and displayed the results in DSO
window.
AIM

To Study the various addressing mode of TMS320C6745 DSP processor.

COMPONENTS REQUIREMENTS

CCS v4
TMS320C6745 KIT
USB Cable
5V Adapter

ADDRESSING MODES
The addressing modes in TMS320C6745
1. Register addressing mode
2. Memory mapped addressing mode
3. Linear addressing mode
4. Circular addressing mode

Register Addressing Mode:


Example SOURCE CODE:
32bit Addition:

.text ; text file indication


.def _c_int00 ; Memory address definition
_c_int00: ; Memory initialization

MVKL 0xC0000000, A1 ; Lower 16bit move to A1 Register


MVKH 0xC0000000, A1 ; Higher 16bit move to A1 Register
MVKL 0x12345678, A2 ; first input
MVKH 0x12345678, A2

MVKL 0x8799F593, A3 ; second input


MVKH 0x8799F593, A3
ADD A2, A3, A4 ; Add A2+A3 and move to A4 Register
STW A4,*A1 ; Store A4value to A1 Register
NOP ; No operation or instruction cycle delay
NOP
.END ; End of the program

Input Output
12345678 ---- A2 A1(0XC0000000) ---- 99CE4COB
8799F593 ---- A3

Memory mapped register addressing mode:


Example program:

Blinking LED:

.text ; text file indication


.def _c_int00 ; Memory address definition
_c_int00: ; Memory initialization

MVKL 0x01E26010, A1 ; Set the Gpio 0 Direction Register address


MVKH0x01E26010, A1
MVKL 0xF000FFFF, A2 ; Set 0 value for output LED in Gpio Direction Register
MVKH0xF000FFFF, A2

STW A2, *A1 ; Store A2 value into A1 Register


ADD A1, 4, A1 ; Add 4 for accessing Gpio out data Register address
(0X01E26014)
MVKL 0x0FFF0000, A2 ; Set FFF for LED ON
MVKH0x0FFF0000, A2

MVKL 0x00000000, A3 ; Set 000 for LED OFF


MVKH0x00000000, A3
on:
STW A2,*A1 ; Store A2 value into A1 Register
NOP 2 ; Two instruction cycle delay

MVKL off, B1 ; off address move to B1 Register


MVKH off, B1
B Delay ; Call delay
NOP 7 ; Seven instruction cycle delay
off:
STW A3, *A1 ; Store A3 value into A1 Register
NOP 2
MVKL on, B1 ; on address move to B1 Register
MVKH on, B1
B Delay ; Call delay
NOP 7
Delay:
MVKL 0x00FFFFFF, B0 ; Set delay
MVKH 0x00FFFFFF, B0
Loop3 SUB B0, 1, B0 ; FFFFFF Times decrement looping
NOP 3
[B0] B Loop3 ; Call loop3
NOP 7 ; if B0=0, Go to B1
B B1 ; Return to off and on simultaneously
Output:
The LED will blink on and off simultaneously in the TMS320C6745 DSP kit.

Linear Addressing Mode


Example program:

Linear convolution:

.text ; text file indication


.def _c_int00 ; Memory address definition
_c_int00: ; Memory initialization
mvkl 0xC0000000,a4 ; Lower 16bit move to a4 Register
mvkh 0xC0000000,a4 ; Higher 16bit move to a4 Register
mvkl 0xC0000100,a5
mvkh 0xC0000100,a5
add a4,10h,a4 ;Add a4+10h for ten memory allocation
nop 2 ;2 instruction cycle delay
add a5,10h,a5 ; Add a5+10h for ten memory allocation
nop 2
mvkl 0xC0000300,a3 ;0xc0000300 address move to a3 Register
mvkh 0xC0000300,a3
mvkl 0xC0000200,a6 ; 0xc0000200 address move to a6 Register
mvkh 0xC0000200,a6
mvkl 8h,b2 ;8h value move to b2 for looping
mvkh 8h,b2
zer: ;Zero function
mvkl 00000000h,a2 ;0h move to a2 Register
mvkh 00000000h,a2
stw a2,*a3++ ;clear the a3 memory address location

nop 7
stw a2,*a4++ ;clear the a4 memory address location

nop 7
stw a2,*a5++ ;clear the a5 memory address location

nop 7
stw a2,*a6++ ;clear the a6 memory address location

nop 7
sub b2,1h,b2 ;8 times decrement looping operation
nop 2
[b2] b zer ;if(b2>0), go to zer function
nop 6 ;if(b2<0), go to next operation

mvkl 0xC0000000,a4 ;0xc0000000 address move to a4 Register


mvkh 0xC0000000,a4
mvkl 7h,b1 ;7h value move to b1 for looping
mvkh 7h,b1
mvkl 0xC0000200,a9 ;0xc0000200 address move to a9 Register
mvkh 0xC0000200,a9
start1:
mvkl 0xC0000100,a1 ; 0xc0000100 address move to a1 Register

mvkh 0xC0000100,a1
mvkl 0xC0000300,a3 ; 0xc0000300 address move to a3 Register
mvkh 0xC0000300,a3
ldw *a4++[1],a8 ;Increment the a4 address and a4 value load to a8
nop 6 ;Register
stw a8,*a3 ;Store a8 value to a3 Register address
nop 6
mvkl 4h,b0 ;4h value move to b0 register for looping
mvkh 4h,b0
nop 3
MVKL 00000000H,a7 ;0h value move to a7 Register
MVKh 00000000H,a7
loop1:
ldw *a1++,a5 ;a1 Register value lode to a5 Register and
increment the a1 Register address
nop 6
ldw *a3++,a6 ;a3 Register value lode to a6
Register and
nop 6 ; increment the a3 address
mpy a5,a6,a6 ;Multiply a5*a6 and move to a6 Register
nop 4
add a7,a6,a7 ;Add a7+a6 and move to a7 Register
nop 2
sub b0,1,b0 ;Decrement looping for 4 times
nop 2
[b0] b loop1 ;if(b0>0) , go to loop1
nop 7 ;if(b0<0) , go to next operation
stw a7,*a9++[1] ;Store a7 value in incremented a9 Register
address
nop 6
mvkl 4h,b0 ;4h value move to b0 register for looping

mvkh 4h,b0
mvkl 0xC0000300,b3 ; 0xc0000300 address move to a3 Register
mvkh 0xC0000300,b3
ldw *b3,b4 ;load b3 value into b4 Register
nop 6
loop2:
ldw *+b3(4),b5 ;b3 value load to b5 Register but b3 address not
nop 6 ;incremented
stw b4,*++b3 ;b4 value store to incremented b3 Register
nop 6
mv b5,b4 ;Move b5 Register to b4 Register
nop 2
sub b0,1,b0 ;Decrement looping for 4 times
nop 2

[b0] b loop2 ;if(b0>0) , go to loop2


nop 6 ;if(b0<0) , go to next operation
sub b1,1,b1 ;Decrement looping for 7times
nop 2
[b1] b start1 ;if(b1>0) , go to start1
nop 7 ;if(b1<0) , go to next operation

halt: b halt ;End of the operation


nop 7
Input: Output:
x(n) h(n) y(n)
0XC0000000 --- 1 0XC0000100 --- 1 0XC0000200 --- 1
0XC0000004 --- 2 0XC0000104 --- 2 0XC0000204 --- 4
0XC0000008 --- 3 0XC0000108 --- 3 0XC0000208 --- A
0XC000000C --- 4 0XC000010C --- 3 0XC000020C --- 13
0XC0000210 --- 17
0XC0000214 --- 15
0XC0000208 --- C
Circular Addressing Mode:
Example program:

Circular convolution:

.text ;text file indication


.def _c_int00 ;Memory address definition
_c_int00: ;Memory initialization
mvkl 0xC0000000,a12 ;Lower 16bit move to a12 Register
mvkh 0xC0000000,a12 ;Higher 16bit move to a12 Register
mvkl 0xC0000100,a13 ;0XC0000100 move to a13 Register
mvkh 0xC0000100,a13
add a12,10h,a12 ;Add a12+10h and move to a12 Register
for
add a13,10h,a12 ;ten memory allocation
nop 2
mvkl 8h,b0 ;Move 8h value to b0 Register for looping
mvkh 8h,b0
zero a5 ;zero value move to a5 Register
filter:
stw a5,*a12++[1] ;Memory clear operation
nop 5
stw a5,*a12++[1] ;Memory clear operation
nop 5
sub b0,1,b0 ;Decrement looping for 8 times
nop 2
[b0] b filzer ;if(b0>0) ,go to filzer function
nop 7 ;if(b0<0) ,go to next operation
mvkl 0xC0000300,a12 ;0XC0000300 move to a12 Register
mvkh 0xC0000300,a12
nop
mvkl 0xC0000100,a13 ;0XC0000100 address move to a13 Register
mvkh 0xC0000100,a13
nop
mvkl 4h,b0 ;4h value move to b0 Register
mvkh 4,b0
nop
another:
ldw *a13++[1],a4 ;Load incremented a13 Register value to a4
Register
nop 6
stw a4,*a12++[1] ;Store a4 value to incremented a12 Register address
nop 5
sub b0,1,b0 ;Four times decrement loop
nop
[b0] b another ;if(b0>0) ,go to another function
Nop ;if(b0<0) ,go to next operation
nop 5
mvkl 0xC0000300,a14 ;0XC0000300 address move to a14 Register
mvkh 0xC0000300,a14
nop
ldw *++a14[1],a4 ;Incremented a14 Register value load to a4
Register
nop 5
ldw *++a14[2],a5 ;2 times incremented a14 address value load to a5
nop 5 ;Register
stw a4,*a14--[2] ;Store a4 value to 2times decremented a14
register nop ;address
nop 5
stw a5,*a14 ;Store a5 Register value to a14 Register address
nop
nop 5
mvkl 0xC0000200,a10 ;0XC0000200 address move to a10 Register
mvkh 0xC0000200,a10
nop
mvkl 4h,b2 ;4h value move to b2 Register
mvkh 4h,b2
nop
nextdata:
mvkl 0xC0000300,a11 ;0XC0000300 address move to a11 Register
mvkh 0xC0000300,a11
nop
mvkl 0xC0000000,a12 ;0XC0000000 address move to a12 Register
mvkh 0xC0000000,a12
nop
mvkl 4,b0 ;4h value move to b0 Register
mvkh 4,b0
nop
mvkl 0h,a9 ;0h value move to a9 Register
mvkh 0h,a9
nop
next:
ldw *a11++[1],a4 ; ;Load incremented a11 value to a4 Register
nop 6
ldw *a12++[1],a5 ;Load incremented a12 value to a5 Register
nop 6
mpy a4,a5,a6 ;Multiply a4*a5 and move to a6 Register
nop 3
add a6,a9,a9 ;Add a6*a9 and move to a9 Register
nop 3
sub b0,1,b0 ;Decrement loop for four times
nop 3
[b0] b next ;if(b0>0) , go to next operation
Nop ;if(b0<0) , go to next operation
nop 5
stw a9,*a10++[1] ;Store a9 value to incremented a10 Register
nop ;address
nop 5
mvkl back,b11 ;back address move to b11 Register
mvkh back,b11
nop
b shift ;Go to shift function
nop
nop 5
back:
sub b2,1,b2 ;Decrement loop for four times
nop 3
[b2] b nextdata ;if(b2>0) , go to next data
Nop ;if(b2<0) , go to halt operation
nop 5

halt: ;End of the program


b halt
nop
nop 5
shift:
mvkl 0xC0000300,a5 ;0XC0000300 address move to a5 Register
mvkh 0xC0000300,a5
nop
mvkl 3h,b1 ;3h value move to b1 Register
mvkh 3h,b1
nop
ldw *++a5[3],a4 ;3 times incremented a5 value move to a4
nop 6 ;Register
mvkl 0xC0000300,a5 ;0XC0000300 address move to a5 Register
mvkh 0xC0000300,a5
nop
add a5,8h,a5 ;Add a5+8h and move to a5 Register
nop 2
shloop:
ldw *a5++[1],a6 ;Incremented a5 value move to a6 Register
nop 6
stw a6,*a5--[2] ;Store a6 value to 2 times decremented a5
nop 6 ;Register
sub b1,1,b1 ;Decrement loop for 3 times
nop
[b1] b shloop ;if(b1>0) , go to shloop
Nop ;if(b1<0) , go to next operation
nop 6
mvkl 0xC0000300,a5 ;0XC0000300 address move to a5 Register
mvkh 0xC0000300,a5
nop
stw a4,*a5 ;Store a4 value to a5 Register
nop 6
b b11 ;Go to back function
nop
nop 6

Input: Output:
x(n) h(n) y(n)
0XC0000000 --- 1 0XC0000100 --- 1 0XC0000200 --- 18
0XC0000004 --- 2 0XC0000104 --- 2 0XC0000204 --- 19
0XC0000008--- 3 0XC0000108 --- 3 0XC0000208 --- 16
0XC000000C --- 4 0XC000010C --- 3 0XC000020C --- 13

ASM General Procedure to work C6745:


1. Open Code Composer Studio v4 .
2. In WorkSpace Launcher.
a. BROWSE → Select the project location and make one new folder, MAKE
NEW FOLDER →Type the Workspace name, OK → OK.
3. FILE → NEW → CCS PROJECT
a. Project name: Type your project name.
b. Tick use default location. →NEXT
c. Project type: C6000.
d. Tick Debug And Release. →NEXT → NEXT.
e. Output type: Executable.
f. Device Variant : generic C67XX Device.
g. Device Endianness : little
h. Code Generation Tools: TI v6.1.12.
i. Run time support library: automatic.
j. Tick Treat as an Assembly-only project.
k. Target content: none. →FINISH
4. FILE → NEW → SOURCE FILE
a. Source file: Type your add.asm( .asm extension is must ).
b. Type the program.
c. FILE → SAVE.
5. Paste the following board library files in workspace location.
a. Common folder (contains header files)
b. Gel folder (contains gel file)
c. Library folder(contains library files)
6. Paste the asm linker file and vectors.asm in the project location.(asm linker file
and vectors.asm is available in cd)
Note: Those folders and linker file are availble at cd.
7. PROJECT → PROPERTIES → C/C++ BUILD → BASIC OPTION
a. Target processor version(--silicon version, -mv) : 6400+
b. IN C/C++ BUILD, → INCLUDE OPTIONS (Add dir to #include search path(-

-include_path,-I)) select this add icon and add the following three path by
indivdually
➔ "${Diag}../../common/header"
➔ "${XDAIS_CG_ROOT}/packages/ti/xdais"
➔ "${C6000_CSL_CG_ROOT}/include"
8. FILE → NEW → TARGET CONFIGURATION FILE
a. file name: projectname. ccxml (.ccxml extension is must)
b. Connection: Texas Instrument XDS100 v1 USB Emulator.
c. Device: TMS320C6745. → SAVE → TARTGET CONFIGURATION
→C674X_0 →BROWSE, browse the workspace location, open the gel folder
and select the GEL file. → OPEN →SAVE.
9. In C/C++ Project window, Right click the project →REBUILD PROJECT.
10. Connections :
a. Connect the usb cable, in between PC to KIT.
b. Connect the 5v adapter and Power on the kit.
11. TARGET → DEBUG ACTIVE PROJECT.(Then see out at corresponding
place after run)
12. VIEW → MEMORY
13. In right side, memory window will open. Type the output adrress
0xC0001000
14. TARGET → RUN.
15. TARGET → HALT.
See the Output at Particular location:
0xC0000000 – 99CE4C0B........
RESULT:
The study of various addressing modes of TMS320C6745 DSP processor was
verified.
AIM
To Analysis of finite wordlength effects in floating point systems by using
TMS320C6745 Kit.

COMPONENTS REQUIREMENTS

CCS v4
TMS320C6745 KIT
USB Cable
5V Adapter

ALGORITHM

1. First include the header files and define the order of filter and define PI value.
2. Declare the filter coefficients without finite word length effect (or without
truncated values).
3. Declare the filter coefficients with finite word length effect (or with truncated
values).
4. Declare the input sample to the system.
5. .Declare the local variables in the main function.
6. Clearing the memory location.
7. Then do the convolution of without truncated filter coefficient with input
samples.
8. Then do the convolution of with truncated filter coefficient with input samples.
9. Finally print the output in console window
PROCEDURE
The procedure 1 to 11 steps are same as previous experiment
12. TARGET → RUN.(print the output in console window)
13. TARGET → HALT.
SOURCE CODE
#include<stdio.h>
#include <math.h>
#define N 10 // Order of filter
#define PI 3.14
// Filter Coefficents without finite word length effect (or without truncated values)
float coeff1[10] = {
8.6589421428571428571428571428571,
6.7794628518236352561053631471054,
3.8972346426831024540136532012540,
1.7564427498245744124212425412421,
0.9897547424241245242575225821010,
4.1489257262414010254101210211256,
7.7854962145874965135871587526322,
9.6587900787865645342354687900978,
2.9786543211246679087664433221121,
0.0975313354566778980909887654329,
};

// Filter Coefficents with finite word length effect (truncated values)


float coeff2[10] = {
8.65,
6.77,
3.89,
1.75,
0.98,
4.14,
7.78,
9.65,
2.97,
0.09,
};

// lets consider input sample to the system


unsigned int ISample[10] = {0xFAE, 0x111, 0x86C, 0xDA5, 0x7B8, 0x6E8, 0x645,
0x79D, 0xA12, 0xC68 };

float OSample1[10];
float OSample2[10];

void main()
{
unsigned int i=0,j=0;
unsigned int n=0;
unsigned int k=0;

for(i=0;i<N;i++) // Clearing the output memory


{
OSample1[i]=0;
OSample2[i]=0;
}

for(n=0;n<N;n++) // Convolution of input sample and filter coefficents


{
for(k=0;k<=n;k++) // Covolution without truncated
OSample1[n] = (OSample1[n]) + ((ISample[k])*(coeff1[n-k]));
}

for(n=0;n<N;n++) // Convolution of input sample and filter coefficents


{
for(k=0;k<=n;k++) // Convolution with truncated
OSample2[n] = (OSample2[n]) + ((ISample[k])*(coeff2[n-k]));
}

printf("\nEffect of Finite Word Length on Accuracy of Filter Coefficients ");


printf("\nwithout word length & with word length");
for(j=0;j<N;j++)
printf("\n%f %f",OSample1[j],OSample2[j]);

}
OUTPUT:

RESULT
Thus the finite word length effects output was verified in console window.

You might also like