Digital Signal Processing Lab r20
Digital Signal Processing Lab r20
me/jntua
C318.3 Analyze and observe magnitude and phase characteristics (Frequency response 04
Characteristics) of digital IIR-Butterworth, Chebyshev filters.
Analyze and observe magnitude and phase characteristics (Frequency response
C318.4 04
Characteristics) of digital FIR filters using window techniques.
C318.5 Analyze digital filters using Software Tools. 04
List of Experiments:
1. Generate the following standard discrete time signals.
i) Unit Impulse ii) Unit step iii) Ramp iv) Exponential v) Sawtooth
2. Generate sum of two sinusoidal signals and find the frequency response (magnitude and phase).
3. Implement and verify linear and circular convolution between two given signals.
4. Implement and verify autocorrelation for the given sequence and cross correlation between two
given signals.
5. Compute and implement the N-point DFT of a given sequence and compute the power density
spectrum of the sequence.
6. Implement and verify N-point DIT-FFT of a given sequence and find the frequency response
(magnitude and phase).
7. Implement and verify N-point IFFT of a given sequence.
8. Design IIR Butterworth filter and compare their performances with different orders (Low Pass
Filter /High Pass Filter)
9. Design IIR Chebyshev filter and compare their performances with different orders (Low Pass
Filter /High Pass Filter).
10. Design FIR filter (Low Pass Filter /High Pass Filter) using windowing technique.
i. Using rectangular window
ii. Using hamming window
iii. Using Kaiser window
11. Design and verify Filter (IIR and FIR) frequency response by using Filter design and Analysis
Tool.
12. Compute the Decimation and Interpolation for the given signal.
13. Real time implementation of an audio signal using a digital signal processor.
14. Compute the correlation coefficient for the two given audio signals of same length using a digital
signal processor.
Note: Any TWELVE of the experiments are to be conducted.
References:
1. Digital Signal Processing: Alon V. Oppenhelm, PHI
2. Digital Signal processing(II-Edition): S.K. Mitra, TMH
Online Learning Resources/Virtual Labs:
1. http://vlabs.iitkgp.ac.in/dsp/#
1. Implement and verify linear and circular convolution between two given signals.
2. Implement and verify autocorrelation for the given sequence and cross correlation between two
given signals.
3. Find DFT of given discrete time signal.
4. Implement and verify N-point DIT-FFT of a given sequence.
5. Implement and verify N-point IFFT of a given sequence
6. Design and implementation of FIR with low pass / high pass filter using any three
windowing techniques. Plot its magnitude and phase responses.
7. Design and implementation of IIR Butterworth (LP/HP) filter..
8. Design and implementation of IIR Chebyshev (LP/HP) filter.
9. Compute the Decimation and Interpolation for the given signal.
CONTENTS
S.NO. NAME OF THE EXPERIMENT PAGE NO
Software Experiments(Using Matlab)
Autocorrelation for the given sequence and Cross Correlation between two given
4
signals.
5 N-point DFT of a given Sequence .
Design and implementation of FIR filter with (LP/HP) filter using any three
10
windowing techniques. Plot its magnitude and phase responses
11 Filter (IIR and FIR) frequency response by using Filter design and Analysis Tool.
Design and implementation of FIR filter with (LP/HP) filter using any three
6
windowing techniques. Plot its magnitude and phase responses
Design and implementation of IIR Butterworth (LP/HP) filter
7
Design and implementation of IIR Chebyshev (LP/HP) filter.
8
Decimation and Interpolation for the given signal.
9
Advanced experiments (Beyond Curriculum)
SCHEME OF EVALUVATION
Marks Awarded
SOFTWARE EXPERIMENTS
(USING MATLAB)
SOFTWARE REQURIED :-
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
%unit impulse function%
%Discrete%
n=-10:10;
Xn=(n==0);
subplot(3,2,1);
stem(n,Xn);
axis([-11 11 -0.5 1.5]);
xlabel('Samples');
ylabel('amplitude');
title(' unit impulse function');
%unit step function%
%Discrete%
n=-10:10;
Xn=(n>=0);
subplot(3,2,2);
stem(n,Xn);
axis([-11 11 -0.5 1.5]);
xlabel('Samples');
ylabel('amplitude');
title(' discrete unit step function');
% exponential signal:
%Discrete%
n2=input('enter the length of the exponential sequence');
t=0:n2;
a=input('enter the a value');
y2=exp(a*t);
subplot(3,2,4);
stem(t,y2);
ylabel('amplitude');
xlabel('time period');
title('exponential sequence')
%sawtooth signal
%Discrete%
n=0:10;
Xn=sawtooth(pi*n/4);
subplot(3,2,5);
stem(n,Xn);
axis([-0.5 11 -1.5 1.5])
xlabel('time period');
ylabel('amplitude');
title('sawtooth sequence');
OUTPUT:-
RESULT:-
CONCLUSIONS:
VIVA QUESTIONS:
1. Define impulse, unit step, ramp signals and write their expressions?
AIM: - To write a MATLAB program to find the sum of two sinusoidal signals and to find
frequency response (magnitude and phase).
SOFTWARE REQURIED :-
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
clc;
Clear all;
Close all;
t=0:0.001:0.1;
f1=50;
x1=2*pi*f1*t;
y1=sin(x1);
figure;
subplot (3,1,1);
plot (t,y1);
title('sin(x1');
f2=100;
x2=2*pi*f2*t;
y2=sin(x2);
subplot(3,1,2);
plot(t,y2);
title('sin(x2)');
y=y1+y2;
subplot(3,1,3);
plot(t,y);
title('sinx1=sinx2')
OUTPUT:
RESULT:
CONCLUSIONS:
VIVA QUESTIONS
AIM: - To write MATLAB programs to find out the linear convolution and Circular
convolution of two sequences.
SOFTWARE REQURIED :-
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
%convolution operation
y=conv(x,h);
%to plot the signal
subplot(3,1,1);
stem(x);
ylabel('amplitude');
xlabel('n1. .. >');
title('input sequence')
subplot(3,1,2);
stem(h);
ylabel('amplitude');
xlabel('n2. .. >');
title('impulse signal')
subplot(3,1,3);
stem(y);
ylabel('amplitude');
xlabel('n3');
disp('the resultant signal is');y
input sequence
4
amlitude
0
1 1.5 2 2.5 3 3.5 4
n1.... >
impulse signal
4
amlitude
0
1 1.5 2 2.5 3 3.5 4
n2.... >
40
amlitude
20
0
1 2 3 4 5 6 7
n3
input sequence
2
amplitude
0
1 1.5 2 2.5 3 3.5 4
n1..>
impulse sequence
4
amplitude
0
1 1.5 2 2.5 3 3.5 4
n2
20
amplitude
10
0
1 1.5 2 2.5 3 3.5 4
n3
RESULT:
CONCLUSIONS:
VIVA QUESTIONS:
AIM: - To write a Matlab program to compute autocorrelation for the given sequence and
cross correlation between two signals.
SOFTWARE REQURIED :-
.PROCEDURE:
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:
OUTPUT:
PROGRAM:
clc;
close all;
clear all;
% two input sequences
x=input('enter input sequence');
h=input('enter the impulse suquence');
subplot(2,2,1);
stem(x);
xlabel('n');
ylabel('x(n)');
title('input sequence');
subplot(2,2,2);
stem(h);
xlabel('n');
ylabel('h(n)');
title('impulse sequence');
% cross correlation between two sequence
y=xcorr(x,h);
subplot(2,2,3);
stem(y);
xlabel('n');
ylabel('y(n)');
title(' cross correlation between two sequences ');
% auto correlation of input sequence
z=xcorr(x,x);
subplot(2,2,4);
stem(z);
xlabel('n');
ylabel('z(n)');
title('auto correlation of input sequence');
INPUT:
OUTPUT:
RESULT:
CONCLUSIONS:
VIVA QUESTIONS:
AIM: To find DFT of a given sequence and compute the power density spectrum of the
sequence.
SOFTWARE REQUIRED:
PROCEDURE:
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
THEORY:
Basic equation to find the DFT of a sequence is given below.
4. PROGRAM:
clc;
close all;
clear all;
tic;
fprintf('Date & Time:');
Date= datestr(now);
disp(Date);
%DFT
disp('D.F.T');
a=input('Enter the input sequence:');
n=length(a);
x=fft(a,n);
for k=1:n;
y(k)=0;
for i=1:n
y(k)=y(k)+a(i)*exp((-j)*2*pi*(i-1)*(k-1)*(1/n));
end
end
error=x-y;
disp(x);
disp(y);
disp(error);
subplot(3,2,1);
stem(a);
xlabel('time index n ----- >');
ylabel('amplitude');
title('input sequence');
subplot(3,2,2);
stem(0:n-1,abs(x));
xlabel('time index n ----- >');
ylabel('amplitude');
title('FFT sequence by inbuilt command');
subplot(3,2,5);
stem(0:n-1,abs(y));
xlabel('time index n ----- >');
ylabel('amplitude');
title('DFT by formula calculation');
subplot(3,2,6);
stem(error);
xlabel('time index n ----- >');
ylabel('amplitude');
title('error sequence');
% Power Spectral Density
P = x.* conj(x) / 512;
f = 1000*(0:256)/512;
figure,plot(f,P(1:257))
title('Frequency content of y');
xlabel('frequency (Hz)');
INPUT:
D.F.T
Enter the input sequence:[1 1 2 1 2 1 3 1]
OUTPUT
Columns 1 through 4
12.0000 -1.0000 + 1.0000i -2.0000 -1.0000 - 1.0000i
Columns 5 through 8
4.0000 -1.0000 + 1.0000i -2.0000 -1.0000 - 1.0000i
Columns 1 through 4
12.0000 -1.0000 + 1.0000i -2.0000 - 0.0000i -1.0000 - 1.0000i
Columns 5 through 8
4.0000 + 0.0000i -1.0000 + 1.0000i -2.0000 - 0.0000i -1.0000 - 1.0000i
1.0e-014 *
Columns 1 through 4
0 0.0444 + 0.0222i 0.0444 + 0.0888i -0.0666 - 0.0666i
Columns 5 through 8
0 - 0.1715i 0.7105 + 0.1887i 0.2665 + 0.2665i -0.1887 - 0.0666i
Elapsed time is 27.683359 seconds
RESULT:
CONCLUSIONS:
VIVA QUESTIONS:
1. What is the difference between DTFT and DFT?
5. How many no. of Complex Multiplications and Additions are required to compute N-Point
DFT?
2. SOFTWARE REQUIRED:
3. PROCEDURE:
Open MATLAB
Open new M-file
Type the program
.Save in current directory
Compile and Run the program
For the output see command window\ Figure window\
PROGRAM:
clc;
close all;
clear all;
tic;
fprintf('Date & Time:');
Date= Datestr(now);
disp(Date);
fprintf('DIT-FFT');
fprintf('\n\n');
N=input('Enter the length of the input sequence:');
for i=1:N
re(i)=input('Enter the real part of the time domain sequence:');
im(i)=input('Enter the imaginary part of the time domain sequence:');
end
[re1,im1]=DITFFT(re,im,N);
subplot(3,2,1);
stem(0:N-1,re);
xlabel('time index n ----- >');
ylabel('amplitude');
title('input real sequence');
subplot(3,2,2);
stem(0:N-1,im);
xlabel('time index n ----- >');
ylabel('amplitude');
title('input imaginary sequence');
subplot(3,2,5);
stem(0:N-1,re1);
xlabel('frequency ----- >');
ylabel('amplitude');
title('output real sequence');
subplot(3,2,6);
stem(0:N-1,im1);
xlabel('frequency ----- >');
ylabel('amplitude');
title('output imaginary sequence');
disp(re1);
disp(im1);
DIT-FFT
Enter the length of the input sequence:8
Enter the real part of the time domain sequence:1
Enter the imaginary part of the time domain sequence:2
Enter the real part of the time domain sequence:1
Enter the imaginary part of the time domain sequence:3
Enter the real part of the time domain sequence:1
Enter the imaginary part of the time domain sequence:2
Enter the real part of the time domain sequence:2
Enter the imaginary part of the time domain sequence:1
Enter the real part of the time domain sequence:2
Enter the imaginary part of the time domain sequence:1
Enter the real part of the time domain sequence:3
Enter the imaginary part of the time domain sequence:1
Enter the real part of the time domain sequence:2
Enter the imaginary part of the time domain sequence:1
Enter the real part of the time domain sequence:3
Enter the imaginary part of the time domain sequence:1
15.0000 0.7071 2.0000 0.1213 -3.0000 -0.7071 -2.0000 -4.1213
12.0000 5.5355 1.0000 0.7071 0 -1.5355 -1.0000 -0.7071
Elapsed time is 23.565254 seconds.
6. RESULT:
7. CONCLUSION:
VIVA QUESTIONS:
1. Write the Block diagram of 8-Point DIT FFT & DIF DFFT radix 2 Algorithm?
2. Explain using convolution the effects of taking an FFT of a sample with no windowing
SOFTWARE REQUIRED:
PC and MATLAB Software (2019b 9.7version)
PROCEDURE:
Open MATLAB
Open new M-file
Type the program
.Save in current directory
Compile and Run the program
For the output see command window\ Figure window\
4. PROGRAM:
clc;
clear all;
close all;
n=input('enter value of n=');
x=input('enter input sequence=');
a=1:1:n;
y=fft(x,n);
disp('fft of input sequence');
disp(y);
z=ifft(y);
disp('ifft of input sequence');
disp(z);
5. OUTPUT:
enter value of n=8
enter input sequence=[1 2 3 4 5 6 7 8]
fft of input sequence
Columns 1 through 6
36.0000 + 0.0000i -4.0000 + 9.6569i -4.0000 + 4.0000i -4.0000 + 1.6569i -4.0000 + 0.0000i -
4.0000 - 1.6569i
Columns 7 through 8
-4.0000 - 4.0000i -4.0000 - 9.6569i
ifft of input sequence
1 2 3 4 5 6 7 8
RESULT:
CONCLUSION:
VIVA QUESTIONS:
1.) What is the need of FFT?
3.) FFT is in complex domain how to use it in real life signals optimally?
5.) How many no. of Complex Multiplications and Additions are required to compute N-Point
DFT using FFT?
SOFTWARE REQUIRED:
PROCEDURE:
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:
clc;
clear all;
close all;
display('enter the iir filter design specifications');
rp=input('enter the pass band ripple:');
rs=input('enter the stop band ripple:');
wp=input('enter the pass band freq:');
ws=input('enter the stop band freq:');
fs=input('enter the sampling freq:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
c=input('enter choice filter 1.lpf 2.hpf /n');
if(c==1)
display('frequency response of IIR lpf is:');
[b,a]=butter(n,wn,'low');
end
if(c==2)
display('freq response of IIR hpf IS:');
[b,a]=butter(n,wn,'high');
end
w=0:0.01:pi;
h=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure;
subplot(2,1,1);
plot(w/pi,m);
title('mignitude response of IIR filter is:');
xlabel('(a)normalized frequency-->');
ylabel('gain in db-->');
subplot(2,1,2);
plot(w/pi,an);
titel('phase response of IIR filter is;');
RESULT:
CONCLUSION:
VIVA QUESTIONS:
1.) What do you mean by cut-off frequency?
3.) What is the difference between type 1 and type 2 filter structures?
SOFTWARE REQUIRED:
PROCEDURE:
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
4. PROGRAM:
% Program for the design of Chebyshev Type-1 low-pass filter
clc;
close all;clear all;
format long
rp=input(„enter the passband ripple...‟);
rs=input(„enter the stopband ripple...‟);
wp=input(„enter the passband freq...‟);
ws=input(„enter the stopband freq...‟);
fs=input(„enter the sampling freq...‟);
w1=2*wp/fs;w2=2*ws/fs;
[n,wn]=cheb1ord(w1,w2,rp,rs,‟s‟);
[b,a]=cheby1(n,rp,wn,‟s‟);
W=0:.01:pi;
[h,om]=freqs(b,a,w);
M=20*log10(abs(h));
An=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel(„Gain in dB --.‟);
xlabel(„(a) Normalised frequency --.‟);
subplot(2,1,2);
plot(om/pi,an);
xlabel(„(b) Normalised frequency --.‟);
ylabel(„Phase in radians --.‟);
% Program for the design of Chebyshev Type-2 High pass analog filter
clc;
close all;clear all;
format long
rp=input('enter the passband ripple...');
rs=input('enter the stopband ripple...');
wp=input('enter the passband freq...');
ws=input('enter the stopband freq...');
RESULT:
CONCLUSION:
VIVA QUESTIONS:
1.) What is the difference between type 1 and type 2 filter structures?
AIM: To write a MATLAB program to design FIR with Low pass filter and High Pass filter using any
three Windowing techniques.
SOFTWARE REQUIRED:
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:
end
ch=input('give type of filter 1:LPF,2:HPF');
switch ch
case 1
b=fir1(n,w1,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
plot(o/pi,m);
title('LPF');
xlabel('(a) Normalized frequency-->');
ylabel('Gain in dB-->');
case 2
b=fir1(n,w1,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
plot(o/pi,m);
title('HPF');
xlabel('(b) Normalized frequency-->');
ylabel('Gain in dB-->');
end
OUTPUT:
enter passband ripple 0.02
enter the stopband ripple
enter passband freq 1000
enter stopband freq 1500
enter sampling freq 10000
enter beta value 5
enter your choice of window function 1. rectangular 2.Hamming 3.kaiser:1
RESULT:
CONCLUSIONS:
VIVA QUESTIONS:
1. What is filter?
2. What is FIR and IIR filter define, and distinguish between these two?
3. What is window method? How you will design an FIR filter using window
method?
4. What are low-pass and band-pass filter and what is the difference
between these two?
AIM: -
To generate FIR filter (LP/HP) coefficients using windowing techniques
Using Rectangular Window
Using Triangular Window
Using Keiser Window
APPARATUS REQUIRED: -
THEORY: -
PROGRAM: -
% FIR Low pass filters using rectangular, triangular and kaiser windows
order = 30;
b_rect1=fir1(order,cf(1),boxcar(31)); Rectangular
b_tri1=fir1(order,cf(1),bartlett(31)); Triangular
b_rect2=fir1(order,cf(2),boxcar(31));
b_tri2=fir1(order,cf(2),bartlett(31));
b_kai2=fir1(order,cf(2),kaiser(31,8));
b_rect3=fir1(order,cf(3),boxcar(31));
b_tri3=fir1(order,cf(3),bartlett(31));
b_kai3=fir1(order,cf(3),kaiser(31,8));
fid=fopen('FIR_lowpass_rectangular.txt','wt');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -400Hz');
fprintf(fid,'\nfloat b_rect1[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect1);
fseek(fid,-1,0);
fprintf(fid,'};');
fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -800Hz');
fprintf(fid,'\nfloat b_rect2[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect2);
fseek(fid,-1,0);
fprintf(fid,'};');
fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -1200Hz');
fprintf(fid,'\nfloat b_rect3[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect3);
fseek(fid,-1,0);
fprintf(fid,'};');
fclose(fid);
winopen('FIR_highpass_rectangular.txt');
% FIR High pass filters using rectangular, triangular and kaiser windows
fid=fopen('FIR_highpass_rectangular.txt','wt');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -400Hz');
fprintf(fid,'\nfloat b_rect1[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect1);
fseek(fid,-1,0);
fprintf(fid,'};');
fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -800Hz');
fprintf(fid,'\nfloat b_rect2[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect2);
fseek(fid,-1,0);
fprintf(fid,'};');
fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -1200Hz');
fprintf(fid,'\nfloat b_rect3[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect3);
fseek(fid,-1,0);
fprintf(fid,'};');
fclose(fid);
winopen('FIR_highpass_rectangular.txt');
T.1 : Matlab generated Coefficients for FIR Low Pass Kaiser filter:
Cutoff -500Hz
float b_kai1[31]={-0.000019,-0.000170,-0.000609,-0.001451,-0.002593,-0.003511,-
0.003150,0.000000,0.007551,0.020655,0.039383,0.062306,0.086494,0.108031,0.122944,
0.128279,0.122944,0.108031,0.086494,0.062306,0.039383,0.020655,0.007551,0.000000,
-0.003150,-0.003511,-0.002593,-0.001451,-0.000609,-0.000170,-0.000019};
Cutoff -1000Hz
float b_kai2[31]={-0.000035,-0.000234,-0.000454,0.000000,0.001933,0.004838,0.005671,
-0.000000,-0.013596,-0.028462,-0.029370,0.000000,0.064504,0.148863,0.221349,0.249983,
0.221349,0.148863,0.064504,0.000000,-0.029370,-0.028462,-0.013596,-0.000000,0.005671,
IMPLEMENTATION OF AN FIR FILTER :
0.004838,0.001933,0.000000,-0.000454,-0.000234, -0.000035};
ALGORITHM
Cutoff -1500Hz TO IMPLEMENT :
float b_kai3[31]={-0.000046,-0.000166,0.000246,0.001414,0.001046,-0.003421,-0.007410,
We need to realize an advance FIR filter by implementing its difference equation as per the
0.000000,0.017764,0.020126,-0.015895,-0.060710,-0.034909,0.105263,0.289209,0.374978,
specifications. A direct form I implementation approach is taken. (The filter coefficients are
0.289209,0.105263,-0.034909,-0.060710,-0.015895,0.020126,0.017764,0.000000,-0.007410,
taken as ai as generated by the Matlab program.)
-0.003421,0.001046,0.001414,0.000246,-0.000166, -0.000046};
T.2 :Matlab generated Coefficients for FIR Low Pass Rectangular filter
Cutoff -500Hz
float b_rect1[31]={-0.008982,-0.017782,-0.025020,-0.029339,-0.029569,-0.024895,
-0.014970,0.000000,0.019247,0.041491,0.065053,0.088016,0.108421,0.124473,0.134729,
0.138255,0.134729,0.124473,0.108421,0.088016,0.065053,0.041491,0.019247,0.000000,
-0.014970,-0.024895,-0.029569,-0.029339,-0.025020,-0.017782,-0.008982};
Cutoff -1000Hz
float b_rect2[31]={-0.015752,-0.023869,-0.018176,0.000000,0.021481,0.033416,0.026254,-
0.000000,-0.033755,-0.055693,-0.047257,0.000000,0.078762,0.167080,0.236286,0.262448,
0.236286,0.167080,0.078762,0.000000,-0.047257,-0.055693,-0.033755,-0.000000,0.026254,
0.033416,0.021481,0.000000,-0.018176,-0.023869,-0.015752};
Cutoff -1500Hz
float b_rect2[31]={-0.020203,-0.016567,0.009656,0.027335,0.011411,-0.023194,-0.033672,
0.000000,0.043293,0.038657,-0.025105,-0.082004,-0.041842,0.115971,0.303048,0.386435,
0.303048,0.115971,-0.041842,-0.082004,-0.025105,0.038657,0.043293,0.000000,-0.033672,
-0.023194,0.011411,0.027335,0.009656,-0.016567,-0.020203};
FLOWCHART FOR FIR :
T.3 : Matlab generated Coefficients for FIR Low Pass Triangular filter
Cutoff -500Hz
float b_tri1[31]={0.000000,-0.001185,-0.003336,-0.005868,-0.007885,-0.008298,-0.005988,
0.000000,0.010265,0.024895,0.043368,0.064545,0.086737,0.107877,0.125747,0.138255,
0.125747,0.107877,0.086737,0.064545,0.043368,0.024895,0.010265,0.000000,-0.005988,
-0.008298,-0.007885,-0.005868,-0.003336,-0.001185,0.000000};
Cutoff -1000Hz
float b_tri2[31]={0.000000,-0.001591,-0.002423,0.000000,0.005728,0.011139,0.010502,
-0.000000,-0.018003,-0.033416,-0.031505,0.000000,0.063010,0.144802,0.220534,0.262448,
0.220534,0.144802,0.063010,0.000000,-0.031505,-0.033416,-0.018003,-0.000000,0.010502,
0.011139,0.005728,0.000000,-0.002423,-0.001591,0.000000};
Cutoff -1500Hz
float b_tri3[31]={0.000000,-0.001104,0.001287,0.005467,0.003043,-0.007731,-0.013469,
0.000000,0.023089,0.023194,-0.016737,-0.060136,-0.033474,0.100508,0.282844,0.386435,
0.282844,0.100508,-0.033474,-0.060136,-0.016737,0.023194,0.023089,0.000000,-0.013469,
-0.007731,0.003043,0.005467,0.001287,-0.001104,0.000000};
T.1 : MATLAB generated Coefficients for FIR High Pass Kaiser filter:
Cutoff -400Hz
float b_kai1[31]={0.000050,0.000223,0.000520,0.000831,0.000845,-0.000000,-0.002478,
-0.007437,-0.015556,-0.027071,-0.041538,-0.057742,-0.073805,-0.087505,-0.096739,
0.899998,-0.096739,-0.087505,-0.073805,-0.057742,-0.041538,-0.027071,-0.015556,
-0.007437,-0.002478,-0.000000,0.000845,0.000831,0.000520,0.000223,0.000050};
Cutoff -800Hz
float b_kai2[31]={0.000000,-0.000138,-0.000611,-0.001345,-0.001607,-0.000000,0.004714,
0.012033,0.018287,0.016731,0.000000,-0.035687,-0.086763,-0.141588,-0.184011,0.800005,
IMPLEMENTATION OF AN FIR FILTER :
-0.184011,-0.141588,-0.086763,-0.035687,0.000000,0.016731,0.018287,0.012033,0.004714,
-0.000000,-0.001607,-0.001345,-0.000611,-0.000138,0.000000};
ALGORITHM TO IMPLEMENT :
Cutoff -1200Hz
We need
float to realize an advance FIR filter by implementing its difference equation as per the
b_kai3[31]={-0.000050,-0.000138,0.000198,0.001345,0.002212,-0.000000,-0.006489,
specifications. A direct form I implementation approach is taken. (The filter coefficients are
-0.012033,-0.005942,0.016731,0.041539,0.035687,-0.028191,-0.141589,-0.253270,0.700008,
taken as ai as generated by the Matlab program.)
-0.253270,-0.141589,-0.028191,0.035687,0.041539,0.016731,-0.005942,-0.012033,-0.006489,
-0.000000,0.002212,0.001345,0.000198,-0.000138,-0.000050};
T.2 :MATLAB generated Coefficients for FIR High pass Rectangular filter
Cutoff -400Hz
float b_rect1[31]={0.021665,0.022076,0.020224,0.015918,0.009129,-0.000000,-0.011158,
-0.023877,-0.037558,-0.051511,-0.064994,-0.077266,-0.087636,-0.095507,-.100422,0.918834,
-0.100422,-0.095507,-0.087636,-0.077266,-0.064994,-0.051511,-0.037558,-0.023877,
-0.011158,-0.000000,0.009129,0.015918,0.020224,0.022076,0.021665};
Cutoff -800Hz
float b_rect2[31]={0.000000,-0.013457,-0.023448,-0.025402,-0.017127,-0.000000,0.020933,
0.038103,0.043547,0.031399,0.000000,-0.047098,-0.101609,-0.152414,-0.188394,0.805541,
-0.188394,-0.152414,-0.101609,-0.047098,0.000000,0.031399,0.043547,0.038103,0.020933,
-0.000000,-0.017127,-0.025402,-0.023448,-0.013457,0.000000};
Cutoff -1200Hz
float b_rect3[31]={-0.020798,-0.013098,0.007416,0.024725,0.022944,-0.000000,-0.028043,
-0.037087,-0.013772,0.030562,0.062393,0.045842,-0.032134,-0.148349,-0.252386,0.686050,
-0.252386,-0.148349,-0.032134,0.045842,0.062393,0.030562,-0.013772,-0.037087,-0.028043,
-0.000000,0.022944,0.024725,0.007416,-0.013098,-0.020798};
T.3 : MATLAB generated Coefficients for FIR High Pass Triangular filter
Cutoff -400Hz
float b_tri1[31]={0.000000,0.001445,0.002648,0.003127,0.002391,-0.000000,-0.004383,
-0.010943,-0.019672,-0.030353,-0.042554,-0.055647,-0.068853,-0.081290,-0.092048,
0.902380,-0.092048,-0.081290,-0.068853,-0.055647,-0.042554,-0.030353,-0.019672,
-0.010943,-0.004383,-0.000000,0.002391,0.003127,0.002648,0.001445,0.000000};
Cutoff -800Hz
float b_tri2[31]={0.000000,-0.000897,-0.003126,-0.005080,-0.004567,-0.000000,0.008373,
0.017782,0.023225,0.018839,0.000000,-0.034539,-0.081287,-0.132092,-0.175834,0.805541,
-0.175834,-0.132092,-0.081287,-0.034539,0.000000,0.018839,0.023225,0.017782,0.008373,
-0.000000,-0.004567,-0.005080,-0.003126,-0.000897,0.000000};
Cutoff -1200Hz
float b_tri3[31]={0.000000,-0.000901,0.001021,0.005105,0.006317,-0.000000,-0.011581,
-0.017868,-0.007583,0.018931,0.042944,0.034707,-0.026541,-0.132736,-0.243196,0.708287,
-0.243196,-0.132736,-0.026541,0.034707,0.042944,0.018931,-0.007583,-0.017868,-0.011581,
-0.000000,0.006317,0.005105,0.001021,-0.000901,0.000000};
5. MODEL GRAPHS:-
RESULT: -
CONCLUSION
VIVA QUESTIONS:
APPARATUS REQUIRED: -
MATLAB and PC
PROGRAM: -
order = 2;
cf=[2500/12000,8000/12000,1600/12000];
fid=fopen('IIR_LP_BW.txt','wt');
fprintf(fid,'\t\t-----------Pass band range: 0-2500Hz --------- \n');
fprintf(fid,'\t\t-----------Magnitude response: Monotonic ---- \n\n\');
fprintf(fid,'\n float num_bw1[9]={');
fprintf(fid,'%f,%f,%f,%f,%f,\n%f,%f,%f,%f};\n',num_bw1);
fprintf(fid,'\nfloat den_bw1[9]={');
fprintf(fid,'%f,%f,%f,%f,%f,\n%f,%f,%f,%f};\n',den_bw1);
fclose(fid);
winopen('IIR_LP_BW.txt');
fid=fopen('IIR_LP_CHEB Type1.txt','wt');
fprintf(fid,'\t\t-----------Pass band range: 2500Hz --------- \n');
fprintf(fid,'\t\t-----------Magnitude response: Rippled (3dB) ----- \n\n\');
fprintf(fid,'\nfloat num_cb1[9]={');
fprintf(fid,'%f,%f,%f,%f,%f,\n%f,%f,%f,%f};\n',num_cb1);
fprintf(fid,'\nfloat den_cb1[9]={');
fprintf(fid,'%f,%f,%f,%f,%f,\n%f,%f,%f,%f};\n',den_cb1);
fprintf(fid,'\n\n\n\t\t-----------Pass band range: 8000Hz ----------\n');
fprintf(fid,'\t\t-----------Magnitude response: Rippled (3dB) ---- \n\n');
fprintf(fid,'\nfloat num_cb2[9]={');
fprintf(fid,'%f,%f,%f,%f,%f,\n%f,%f,%f,%f};\n',num_cb2);
fprintf(fid,'\nfloat den_cb2[9]={');
fprintf(fid,'%f,%f,%f,%f,%f,\n%f,%f,%f,%f};\n',den_cb2);
fclose(fid);
winopen('IIR_LP_CHEB Type1.txt');
%%%%%%%%%%%%%%%%%%
figure(1);
[h,w]=freqz(num_bw1,den_bw1);
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2)
hold on
[h,w]=freqz(num_cb1,den_cb1);
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2,'color','r')
grid on
legend('Butterworth','Chebyshev Type-1');
xlabel('Frequency in Hertz');
ylabel('Magnitude in Decibels');
title('Magnitude response of Low pass IIR filters (Fc=2500Hz)');
figure(2);
[h,w]=freqz(num_bw2,den_bw2);
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2)
hold on
[h,w]=freqz(num_cb2,den_cb2);
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2,'color','r')
grid on
legend('Butterworth','Chebyshev Type-1 (Ripple: 3dB)');
xlabel('Frequency in Hertz');
ylabel('Magnitude in Decibels');
title('Magnitude response in the passband');
axis([0 12000 -20 20]);
Note: We have Multiplied Floating Point Values with 32767(215) to get Fixed Point
Values.
RESULT: -
CONCLUSION
VIVA QUESTIONS:
3. What are the steps involved to design digital filter using bilinear transformations?
SOFTWARE REQUIRED:
clc;
close all;
clear all;
M = input('enter Down-sampling factor : ');
N = input('enter number of samples :');
n = 0:N-1;
x = sin(2*pi*0.043*n) + sin(2*pi*0.031*n);
y = decimate(x,M,'fir');
subplot(2,1,1);
stem(n,x(1:N));
title('Input Sequence');
xlabel('Time index n');
ylabel('Amplitude');
subplot(2,1,2);
m = 0:(N/M)-1
title('Output Sequence');
xlabel('Time index n');ylabel('Amplitude');
INPUT:
enter Down-sampling factor : 3
enter number of samples :100
OUTPUT
PROGRAM INTERPOLATION
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:
Output Waveforms:
RESULT: -
CONCLUSION
VIVA QUESTIONS:
3. Define interpolation.
4. Define decimation.
5. Define aliasing.
HARDWARE EXPERIMENTS
(USING DSP PROCESSOR)
AIM: To write a C- program to find linear convolution and circular convolution of given
sequences.
#include<stdio.h>
#define LENGHT1 6 /*Lenght of i/p samples sequence*/
#define LENGHT2 4 /*Lenght of impulse response Co-efficients */
int x[2*LENGHT1-1]={1,2,3,4,5,6,0,0,0,0,0}; /*Input Signal Samples*/
int h[2*LENGHT1-1]={1,2,3,4,0,0,0,0,0,0,0}; /*Impulse Response Co-efficients*/
int y[LENGHT1+LENGHT2-1];
void main()
{
int i=0,j;
for(i=0;i<(LENGHT1+LENGHT2-1);i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
printf("\nLinear convolution values are as follows:\n");
for(i=0;i<(LENGHT1+LENGHT2-1);i++)
printf("%d\t",y[i]);
}
OUTPUT:
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];
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]);
}
OUTPUT
RESULT:
CONCLUSION
VIVA QUESTION:
AIM: Auto correlation and Cross-correlation of a given sequence and verification of its
properties
APPARATUS REQUIRED
PROCEDURE
1. To create the New Project
2. Project→ New CCS Project (Give name to project with location to save or use default
3. location)
4. Select project type→ Executable
5. Device Family→C6000
6. Variant→C674xFloating-point DSP
7. Connection →Texas Instruments XDS100V2USB Emulator
8. Click on Empty Project then Finish
9. To create a Source file
10. File →New→ Source file (Save & give file name, Eg: sum.c).Click on Finish
11. Write the C-Program To build the program project →Build All
12. After Build Finished without errors, Now DSP kit is turned ON
13. Debug the Program after loading is done
14. Run the Program and verify the output
15. Program asks for values of x[N], you have to enter values as 1st real & 2nd imaginary
for all N no of values.
PROGRAM AUTO-CORRELATION:
#include<stdio.h>
#include<math.h>
#define PI 3.14
#define PTS 512
void delay1();
void sinewave(float fm1, float fc1, int no, int result);
void main()
{
int i,j;
for (i = 0 ; i < PTS ; i++)
{
sinewave(100, 8000, i, 0);
//x[i] = sin(2 * PI * 100 * i / 8000.0);
y[i]=0.0;
}
float m;
float n;
delay1();
delay1();
m = 6.28 * fm1 * no;
delay1();
delay1();
n = (m / fc1);
delay1();
delay1();
if(result == 0)
{
delay1();
x[no]= sin(n);
delay1();
}
delay1();
delay1();
void delay1()
{
int y=150;
while(y!=0)
y--;
OUTPUT
1. For auto correlation
We generated samplesine wave as a input named as x.
Final output of auto correlation named as z.
To view input / output graphically,
Select Tool graph Dual time
PROGRAM CROSS-CORRELATION
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#define PI 3.14
#define PTS 128
void delay1();
void sinewave(float fm1, float fc1, int no, int result);
float x[PTS];
float y[PTS];
float z[PTS];
float n[PTS];
void main()
{
int i,j;
float xx;
for (i = 0 ; i < PTS ; i++)
{
sinewave(20, 128, i, 0);
//x[i] = sin(2*PI*i*20/128.0);
y[i]=0.0;
n[i]=x[i] + rand() * 10 ;
float m;
float n;
delay1();
delay1();
m = 6.28 * fm1 * no;
delay1();
delay1();
n = (m / fc1);
delay1();
delay1();
if(result == 0)
{
delay1();
x[no]= sin(n);
delay1();
}
delay1();
delay1();
void delay1()
{
int y=150000;
while(y!=0)
y--;
OUTPUT
We generated sample sine wave as a input named as x.
Then generate noise signal using random function and added with original signal,
that
is denoted as n
Cross-correlation output saved in z variable.
To view input graphically,
Select Tool graph Dual time
Graph setting &Graph
RESULT:
CONCLUSION
VIVA QUESTION
DFT OF A SIGNAL
AIM: - To compute the N (=4/8/16) point DFT of the given sequence.
APPARATUS REQUIRED
PROCEDURE
16. To create the New Project
17. Project→ New CCS Project (Give name to project with location to save or use default
18. location)
19. Select project type→ Executable
20. Device Family→C6000
21. Variant→C674xFloating-point DSP
22. Connection →Texas Instruments XDS100V2USB Emulator
23. Click on Empty Project then Finish
24. To create a Source file
25. File →New→ Source file (Save & give file name, Eg: sum.c).Click on Finish
26. Write the C-Program To build the program project →Build All
27. After Build Finished without errors, Now DSP kit is turned ON
28. Debug the Program after loading is done
29. Run the Program and verify the output
30. Program asks for values of x[N], you have to enter values as 1st real & 2nd imaginary
for all N no of values.
Eg. x[N]={1+0j,1+0j,1+0j,1+0j,1+0j,1+0j,1+0j,1+0j}.
It enter in program as → 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
PROGRAM DFT:
#include<stdio.h>
#include<math.h>
#define pi 3.14
typedef struct {
float real;
float img;
}com;
void main()
{
com x[50],y[50],temp[50];
int pofd=0,i,k,n;
float WN,c,s,WK;
for(i=0;i<50;i++) /*make output array value to 0.0*/
{
y[i].real=0.0;
y[i].img=0.0;
}
WK=k*WN;
for(n=0;n<pofd;n++) /*DFT calculation*/
{
c=cos(WK*n);
s=sin(WK*n);
temp[k].real=temp[k].real+(x[n].real*c)+(x[n].img*s);
temp[k].img=temp[k].img+(x[n].img*c)-(x[n].real*s);
}
y[k].real=1/sqrt(pofd)*temp[k].real;
y[k].img=1/sqrt(pofd)*temp[k].img;
}
printf("\nDFT OF GIVEN SIGNAL:-\n"); /*Display values of F[k]*/
for(i=0;i<pofd;i++)
{
printf("\nF(%d)=(%0.1f)+j(%0.1f)\n",i,y[i].real,y[i].img);
}
}
OUTPUT:
DFT:
Input x[n]= {1+0j, 1+0j, 1+0j, 1+0j, 1+0j, 1+0j, 1+0j, 1+0j}.
Output X[K]={2.8+j0.0, 0.0+j0.0, 0.0+j0.0, 0.0+j0.0, 0.0+j0.0, 0.0+j0.0,
0.0+j0.0,0.0+j0.0}.
RESULT:
CONCLUSION
VIVA QUESTIONS
PROGRAM
#include<stdio.h>
//#include<conio.h>
#include<math.h>
#define PI 3.14
typedef struct
{
float real,imag;
}com;
void main()
{
com xx[8],x[8],temp[8],temp1[8],y[8],a[8],b[8],w[4];
int i,j=0;//loop counter variables
// printf("Enter the no of pionts of FFT==");
// scanf("%d", &PTS);
printf("\nEnter values==");
for(i=0;i<8;i++)
{
scanf("%f",&xx[i].real);
scanf("%f",&xx[i].imag);
}
j=0;
for(i=0;i<8;i=i+2)
{
x[j].real=xx[i].real;
x[j].imag=xx[i].imag;
x[j+1].real=xx[i+4].real;
x[j+1].imag=xx[i+4].imag;
if(i==2)
i=-1;
j=j+2;
}
for(i=0;i<4;i++)
{
w[i].real=cos(2*PI*i/8);
w[i].imag=-sin(2*PI*i/8);
}
for(i=0;i<8;i=i+2)
{
temp[i].real=x[i].real+x[i+1].real;
temp[i].imag=x[i].imag+x[i+1].imag;
temp[i+1].real=x[i].real-x[i+1].real;
temp[i+1].imag=x[i].imag-x[i+1].imag;
}
for(i=2;i<8;i=3*i)
{
a[i].real=temp[i].real*w[0].real-temp[i].imag*w[0].imag;
a[i].imag=temp[i].real*w[0].imag+temp[i].imag*w[0].real;
a[i+1].real=temp[i+1].real*w[2].real-temp[i+1].imag*w[2].imag;
a[i+1].imag=temp[i+1].real*w[2].imag+temp[i+1].imag*w[2].real;
temp[i].real=a[i].real;
temp[i].imag=a[i].imag;
temp[i+1].real=a[i+1].real;
temp[i+1].imag=a[i+1].imag;
}
for(i=0;i<6;i++)
{
temp1[i].real=temp[i].real+temp[i+2].real;
temp1[i].imag=temp[i].imag+temp[i+2].imag;
temp1[i+2].real=temp[i].real-temp[i+2].real;
temp1[i+2].imag=temp[i].imag-temp[i+2].imag;
if(i==1)
i=3;
}
for(i=4;i<8;i++)
{
b[i].real=temp1[i].real*w[i-4].real-temp1[i].imag*w[i-4].imag;
b[i].imag=temp1[i].real*w[i-4].imag+temp1[i].imag*w[i-4].real;
temp1[i].real=b[i].real;
temp1[i].imag=b[i].imag;
}
for(i=0;i<4;i++)
{
y[i].real=temp1[i].real+temp1[i+4].real;
y[i].imag=temp1[i].imag+temp1[i+4].imag;
y[i+4].real=temp1[i].real-temp1[i+4].real;
y[i+4].imag=temp1[i].imag-temp1[i+4].imag;
}
printf("\nDFT values==\n");
for(i=0;i<8;i++)
{
printf("\nF(%d)=(%0.1f)+j(%0.1f)\n",i,y[i].real,y[i].imag);
}
}
OUTPUT
Input x[n]= {1+0j, 1+0j, 1+0j, 1+0j, 1+0j, 1+0j, 1+0j, 1+0j}; for both DIT & DIF –FFT
algorithm.
Output X[K]={8+j0.0, 0.0+j0.0, 0.0+j0.0, 0.0+j0.0, 0.0+j0.0, 0.0+j0.0,
0.0+j0.0, 0.0+j0.0}; for both DIT & DIF-FFT algorithm.
Result of DFT using DIT-FFT method
RESULT:
CONCLUSION
VIVA QUESTIONS
PROGRAM:
#include<stdio.h>
//#include<conio.h>
#include<math.h>
#define PI 3.14
typedef struct
{
float real,imag;
}com;
void main()
{
com xx[8],x[8],temp[8],temp1[8],y[8],a[8],b[8],w[4];
int i,j=0;//loop counter variables
// printf("Enter the no of pionts of FFT==");
// scanf("%d", &PTS);
printf("\nEnter values==");
for(i=0;i<8;i++)
{
scanf("%f",&xx[i].real);
scanf("%f",&xx[i].imag);
}
j=0;
for(i=0;i<8;i=i+2)
{
x[j].real=xx[i].real;
x[j].imag=xx[i].imag;
x[j+1].real=xx[i+4].real;
x[j+1].imag=xx[i+4].imag;
if(i==2)
i=-1;
j=j+2;
}
for(i=0;i<4;i++)
{
w[i].real=cos(2*PI*i/8);
w[i].imag=sin(2*PI*i/8);
}
for(i=0;i<8;i=i+2)
{
temp[i].real=x[i].real+x[i+1].real;
temp[i].imag=x[i].imag+x[i+1].imag;
temp[i+1].real=x[i].real-x[i+1].real;
temp[i+1].imag=x[i].imag-x[i+1].imag;
}
for(i=2;i<8;i=3*i)
{
a[i].real=temp[i].real*w[0].real-temp[i].imag*w[0].imag;
a[i].imag=temp[i].real*w[0].imag+temp[i].imag*w[0].real;
a[i+1].real=temp[i+1].real*w[2].real-temp[i+1].imag*w[2].imag;
a[i+1].imag=temp[i+1].real*w[2].imag+temp[i+1].imag*w[2].real;
temp[i].real=a[i].real;
temp[i].imag=a[i].imag;
temp[i+1].real=a[i+1].real;
temp[i+1].imag=a[i+1].imag;
}
for(i=0;i<6;i++)
{
temp1[i].real=temp[i].real+temp[i+2].real;
temp1[i].imag=temp[i].imag+temp[i+2].imag;
temp1[i+2].real=temp[i].real-temp[i+2].real;
temp1[i+2].imag=temp[i].imag-temp[i+2].imag;
if(i==1)
i=3;
}
for(i=4;i<8;i++)
{
b[i].real=temp1[i].real*w[i-4].real-temp1[i].imag*w[i-4].imag;
b[i].imag=temp1[i].real*w[i-4].imag+temp1[i].imag*w[i-4].real;
temp1[i].real=b[i].real;
temp1[i].imag=b[i].imag;
}
for(i=0;i<4;i++)
{
y[i].real=temp1[i].real+temp1[i+4].real;
y[i].imag=temp1[i].imag+temp1[i+4].imag;
y[i+4].real=temp1[i].real-temp1[i+4].real;
y[i+4].imag=temp1[i].imag-temp1[i+4].imag;
}
printf("\nIFFT values==\n");
for(i=0;i<8;i++)
{
printf("\nF(%d)=(%0.1f)+j(%0.1f)\n",i,y[i].real/8,y[i].imag/8);
}
}
OUTPUT
Input x[n]= {8.0+j0.0, 0.0+j0.0, 0.0+j0.0, 0.0+j0.0, 0.0+j0.0, 0.0+j0.0, 0.0+j0.0,
0.0+j0.0};
for both DIT & DIF–FFT algorithm.
Output X[K]={1+0j, 1+0j, 1+0j, 1+0j, 1+0j, 1+0j, 1+0j, 1+0j }; for both DIT & DIF-FFT
Algorithm
RESULT:
CONCLUSION
VIVA QUESTIONS
APPARATUS REQUIRED
CODE COMPOSER STUDIO
TMS320C6745 DSP TRAINER KIT
PROCEDURE:
1. To create the New Project
2. Project→ New CCS Project (Give name to project with location to save or use default
3. location)
4. Select project type→ Executable
5. Device Family→C6000
6. Variant→C674xFloating-point DSP
7. Connection →Texas Instruments XDS100V2USB Emulator
8. Click on Empty Project then Finish
9. To create a Source file
10. File →New→ Source file (Save & give file name, Eg: sum.c).Click on Finish
11. Write the C-Program To build the program project →Build All
12. After Build Finished without errors, Now DSP kit is turned ON
13. Debug the Program after loading is done
14. Run the Program and verify the output
15. Connect CRO to the LINE OUT.
16. Connect a Signal Generator to the LINE IN.
17. Switch on the Signal Generator with a sine wave of frequency 100 Hz. and Vp-
p=1.0v&vary the frequency.
PROGRAM:
#include<stdio.h>
#include "sysreg.h"
#define Uint32 unsigned int
#define Uint16 unsigned short
#define Uint8 unsigned char
#define Int32 int
#define Int16 short
#define Int8 char
static Uint32 spidat1;
SPI_SPIDAT1 = spidat1;
SPI_SPIDELAY = 0
| ( 8 << 24 ) // C2TDELAY
| ( 8 << 16 ); // T2CDELAY
SPI_SPIDEF = 0
| ( 1 << 1 ) // EN1 inactive high
| ( 1 << 0 ); // EN0 inactive high
SPI_SPIINT = 0;
SPI_SPIDEF = 0x01;
SPI_SPIGCR1 |= ( 1 << 24 ); //Enable SPI
}
MCASP0_GBLCTL = 0;
MCASP0_RGBLCTL = 0;
MCASP0_XGBLCTL = 0;
MCASP0_PWRDEMU = 1;
MCASP0_RMASK = 0xFFFFFFFF;
MCASP0_RFMT = 0x00018078; // MSB 16bit, 0-delay, no pad, CFGBus
MCASP0_AFSRCTL = 0x00000000; // 2TDM,1bit Rising edge INTERNAL FS, word
MCASP0_ACLKRCTL = 0x00000081;//0x000000AF;//Rising INTERNAL CLK(from tx
side)
MCASP0_AHCLKRCTL = 0x00008000;//INT CLK (from tx side)
MCASP0_RTDM = 0x00000003; // Slots 0,1
MCASP0_PFUNC = 0x00;
MCASP0_PDIR = 0x00000001;
MCASP0_DITCTL = 0x00000000; // Not used
MCASP0_DLBCTL = 0x00000000; // Not used
MCASP0_AMUTE = 0x00000000; // Not used
MCASP0_XGBLCTL |= GBLCTL_XCLKRST_ON;
// Clk
while ( ( MCASP0_XGBLCTL & GBLCTL_XCLKRST_ON ) !=
GBLCTL_XCLKRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RCLKRST_ON;
// Clk
while ( ( MCASP0_RGBLCTL & GBLCTL_RCLKRST_ON ) !=
GBLCTL_RCLKRST_ON );
MCASP0_XGBLCTL |= GBLCTL_XSRCLR_ON;
// Serialize
while ( ( MCASP0_XGBLCTL & GBLCTL_XSRCLR_ON ) != GBLCTL_XSRCLR_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSRCLR_ON;
// Serialize
while ( ( MCASP0_RGBLCTL & GBLCTL_RSRCLR_ON ) != GBLCTL_RSRCLR_ON
);
MCASP0_XBUF0 = 0;
MCASP0_XGBLCTL |= GBLCTL_XSMRST_ON;
// State Machine
while ( ( MCASP0_XGBLCTL & GBLCTL_XSMRST_ON ) != GBLCTL_XSMRST_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSMRST_ON;
// State Machine
while ( ( MCASP0_RGBLCTL & GBLCTL_RSMRST_ON ) != GBLCTL_RSMRST_ON
);
MCASP0_XGBLCTL |= GBLCTL_XFRST_ON;
// Frame Sync
while ( ( MCASP0_XGBLCTL & GBLCTL_XFRST_ON ) != GBLCTL_XFRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RFRST_ON;
// Frame Sync
while ( ( MCASP0_RGBLCTL & GBLCTL_RFRST_ON ) != GBLCTL_RFRST_ON );
while(1)
{
#include<stdio.h>
#include "sysreg.h"
#define Uint32 unsigned int
#define Uint16 unsigned short
#define Uint8 unsigned char
#define Int32 int
#define Int16 short
#define Int8 char
static Uint32 spidat1;
void DSP6745_wait( Uint32 delay )
{
volatile Uint32 i;
for ( i = 0 ; i < delay ; i++ )
{
}
}
void spi_init( )
{
/* Reset SPI */
SPI_SPIGCR0 = 0;
DSP6745_wait( 1000 );
/* Release SPI */
SPI_SPIGCR0 = 1;
spidat1 = 0
| ( 0 << 28 ) // CSHOLD
| ( 0 << 24 ) // DFSEL Format [0]
| ( 1 << 26 )
| ( 0 << 16 ) // CSNR
| ( 0 << 0 ); //
SPI_SPIFMT0 = 0
| ( 0 << 20 ) // SHIFTDIR
| ( 0 << 17 ) // Polarity
| ( 1 << 16 ) // Phase
| ( 14 << 8 ) // Prescale to 30MHz (150/(value+1))//29
| ( 16 << 0 ); // Char Len | ( 1F << 0 );
SPI_SPIDAT1 = spidat1;
SPI_SPIDELAY = 0
| ( 8 << 24 ) // C2TDELAY
| ( 8 << 16 ); // T2CDELAY
SPI_SPIDEF = 0
| ( 1 << 1 ) // EN1 inactive high
| ( 1 << 0 ); // EN0 inactive high
SPI_SPIINT = 0;
SPI_SPIDEF = 0x01;
SPI_SPIGCR1 |= ( 1 << 24 ); //Enable SPI
}
MCASP0_PWRDEMU = 1;
MCASP0_RMASK = 0xFFFFFFFF;
MCASP0_RFMT = 0x00018078; // MSB 16bit, 0-delay, no
pad, CFGBus
MCASP0_AFSRCTL = 0x00000000; // 2TDM, 1bit Rising edge
INTERNAL FS, word
MCASP0_ACLKRCTL = 0x00000081;//0x000000AF; // Rising
INTERNAL CLK(from tx side)
MCASP0_AHCLKRCTL = 0x00008000;//INT CLK (from tx side)
MCASP0_RTDM = 0x00000003; // Slots 0,1
MCASP0_RINTCTL = 0x00000000; // Not used
MCASP0_RCLKCHK = 0x00FF0008; // 255-MAX 0-MIN, div-by-
256
MCASP0_XMASK = 0xFFFFFFFF; // No padding used
MCASP0_XFMT = 0x00018078; // MSB 16bit, 0-delay, no
pad, CFGBus
MCASP0_AFSXCTL = 0x00000000; // 2TDM, 1bit Rising edge
INTERNAL FS, word
MCASP0_ACLKXCTL = 0x00000081;//0x000000AF; // ASYNC,
Rising INTERNAL CLK, div-by-16
MCASP0_AHCLKXCTL = 0x00008000;// INT CLK, div-by-4
MCASP0_XTDM = 0x00000003; // Slots 0,1
MCASP0_XINTCTL = 0x00000000; // Not used
MCASP0_XCLKCHK = 0x00FF0008; // 255-MAX 0-MIN, div-by-
256
MCASP0_PFUNC = 0x00;
MCASP0_PDIR = 0x00000001;
MCASP0_DITCTL = 0x00000000; // Not used
MCASP0_DLBCTL = 0x00000000; // Not used
MCASP0_AMUTE = 0x00000000; // Not used
MCASP0_XGBLCTL |= GBLCTL_XCLKRST_ON;
// Clk
while ( ( MCASP0_XGBLCTL & GBLCTL_XCLKRST_ON ) !=
GBLCTL_XCLKRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RCLKRST_ON;
// Clk
while ( ( MCASP0_RGBLCTL & GBLCTL_RCLKRST_ON ) !=
GBLCTL_RCLKRST_ON );
MCASP0_XGBLCTL |= GBLCTL_XSRCLR_ON;
// Serialize
while ( ( MCASP0_XGBLCTL & GBLCTL_XSRCLR_ON ) != GBLCTL_XSRCLR_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSRCLR_ON;
// Serialize
while ( ( MCASP0_RGBLCTL & GBLCTL_RSRCLR_ON ) != GBLCTL_RSRCLR_ON
);
MCASP0_XBUF0 = 0;
MCASP0_XGBLCTL |= GBLCTL_XSMRST_ON;
// State Machine
while ( ( MCASP0_XGBLCTL & GBLCTL_XSMRST_ON ) != GBLCTL_XSMRST_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSMRST_ON;
// State Machine
while ( ( MCASP0_RGBLCTL & GBLCTL_RSMRST_ON ) != GBLCTL_RSMRST_ON
);
MCASP0_XGBLCTL |= GBLCTL_XFRST_ON;
// Frame Sync
while ( ( MCASP0_XGBLCTL & GBLCTL_XFRST_ON ) != GBLCTL_XFRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RFRST_ON;
// Frame Sync
while ( ( MCASP0_RGBLCTL & GBLCTL_RFRST_ON ) != GBLCTL_RFRST_ON );
while(1)
{
while ( ! ( MCASP0_SRCTL1 & 0x20 ) );
input_data1 = MCASP0_RBUF1_32BIT;
input_data2 = FIR_FILTER(filter_Coeff , input_data1);
while ( ! ( MCASP0_SRCTL0 & 0x10 ) );
MCASP0_XBUF0_32BIT = (input_data2 << 16);
}
}
signed int FIR_FILTER(float h[], signed int x)
{
int i=0;
signed long output=0;
in_buffer[0] = x; /* new input at buffer[0] */
for(i=29;i>0;i--)
in_buffer[i] = in_buffer[i-1]; /* shuffle the buffer */
for(i=0;i<31;i++)
output = output + h[i] * in_buffer[i];
return(output);
}
SPI_SPIDEF = 0
MCASP0_GBLCTL = 0;
MCASP0_RGBLCTL = 0;
MCASP0_XGBLCTL = 0;
MCASP0_PWRDEMU = 1;
MCASP0_RMASK = 0xFFFFFFFF;
MCASP0_RFMT = 0x00018078; // MSB 16bit, 0-delay, no
pad, CFGBus
MCASP0_AFSRCTL = 0x00000000; // 2TDM, 1bit Rising edge
INTERNAL FS, word
MCASP0_ACLKRCTL = 0x00000081;//0x000000AF; // Rising
INTERNAL CLK(from tx side)
MCASP0_PFUNC = 0x00;
MCASP0_PDIR = 0x00000001;
MCASP0_DITCTL = 0x00000000; // Not used
MCASP0_DLBCTL = 0x00000000; // Not used
MCASP0_AMUTE = 0x00000000; // Not used
MCASP0_XGBLCTL |= GBLCTL_XCLKRST_ON;
// Clk
while ( ( MCASP0_XGBLCTL & GBLCTL_XCLKRST_ON ) !=
GBLCTL_XCLKRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RCLKRST_ON;
// Clk
while ( ( MCASP0_RGBLCTL & GBLCTL_RCLKRST_ON ) !=
GBLCTL_RCLKRST_ON );
MCASP0_XGBLCTL |= GBLCTL_XSRCLR_ON;
// Serialize
while ( ( MCASP0_XGBLCTL & GBLCTL_XSRCLR_ON ) != GBLCTL_XSRCLR_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSRCLR_ON;
// Serialize
MCASP0_XBUF0 = 0;
MCASP0_XGBLCTL |= GBLCTL_XSMRST_ON;
// State Machine
while ( ( MCASP0_XGBLCTL & GBLCTL_XSMRST_ON ) != GBLCTL_XSMRST_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSMRST_ON;
// State Machine
while ( ( MCASP0_RGBLCTL & GBLCTL_RSMRST_ON ) != GBLCTL_RSMRST_ON
);
MCASP0_XGBLCTL |= GBLCTL_XFRST_ON;
// Frame Sync
while ( ( MCASP0_XGBLCTL & GBLCTL_XFRST_ON ) != GBLCTL_XFRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RFRST_ON;
// Frame Sync
while ( ( MCASP0_RGBLCTL & GBLCTL_RFRST_ON ) != GBLCTL_RFRST_ON );
while(1)
{
PROGRAM:
#include<stdio.h>
#include "sysreg.h"
#define Uint32 unsigned int
#define Uint16 unsigned short
#define Uint8 unsigned char
#define Int32 int
#define Int16 short
#define Int8 char
static Uint32 spidat1;
void DSP6745_wait( Uint32 delay )
{
volatile Uint32 i;
for ( i = 0 ; i < delay ; i++ )
{
}
}
void spi_init( )
{
/* Reset SPI */
SPI_SPIGCR0 = 0;
DSP6745_wait( 1000 );
/* Release SPI */
SPI_SPIGCR0 = 1;
/* SPI 4-Pin Mode setup */
SPI_SPIGCR1 = 0
| ( 0 << 24 )//Deactivates SPI
| ( 0 << 16 )//Internal loop-back test mode disabled/enabled=0/1
//| ( 1 << 1 )//MASTER MODE. SPIx_CLK is an output and the SPI initiates
transfers
| ( 3 << 0 );//MASTER MODE. SPIx_CLK is an output and the SPI initiates
transfers
SPI_SPIPC0 = 0
| ( 1 << 11 ) // DI
| ( 1 << 10 ) // DO
| ( 1 << 9 ) // CLK
| ( 1 << 8 ) // EN0
| ( 1 << 0 ); // CS
spidat1 = 0
| ( 0 << 28 ) // CSHOLD
| ( 0 << 24 ) // DFSEL Format [0]
| ( 1 << 26 )
| ( 0 << 16 ) // CSNR
| ( 0 << 0 ); //
SPI_SPIFMT0 = 0
| ( 0 << 20 ) // SHIFTDIR
| ( 0 << 17 ) // Polarity
| ( 1 << 16 ) // Phase
| ( 14 << 8 ) // Prescale to 30MHz (150/(value+1))//29
| ( 16 << 0 ); // Char Len | ( 1F << 0 );
SPI_SPIDAT1 = spidat1;
SPI_SPIDELAY = 0
| ( 8 << 24 ) // C2TDELAY
| ( 8 << 16 ); // T2CDELAY
SPI_SPIDEF = 0
| ( 1 << 1 ) // EN1 inactive high
| ( 1 << 0 ); // EN0 inactive high
SPI_SPIINT = 0;
SPI_SPIDEF = 0x01;
SPI_SPIGCR1 |= ( 1 << 24 ); //Enable SPI
}
int temp,i;
signed int input_data1, input_data2;
Uint16 codec_reg_val[] = {0X0017, 0X0217, 0X04D8, 0X06D8, 0X0811, 0X0A00,
0X0C00, 0X0E53, 0X100C, 0x1201};
PINMUX7 = 0x10110000;
PINMUX9 = 0x11011000;
PINMUX10 = 0x00000110;
spi_init( );
temp = SPI_SPIDAT1;
MCASP0_GBLCTL = 0;
MCASP0_RGBLCTL = 0;
MCASP0_XGBLCTL = 0;
MCASP0_PWRDEMU = 1;
MCASP0_RMASK = 0xFFFFFFFF;
MCASP0_RFMT = 0x00018078; // MSB 16bit, 0-delay, no
pad, CFGBus
MCASP0_AFSRCTL = 0x00000000; // 2TDM, 1bit Rising edge
INTERNAL FS, word
MCASP0_ACLKRCTL = 0x00000081;//0x000000AF; // Rising
INTERNAL CLK(from tx side)
MCASP0_AHCLKRCTL = 0x00008000;//INT CLK (from tx side)
MCASP0_RTDM = 0x00000003; // Slots 0,1
MCASP0_RINTCTL = 0x00000000; // Not used
MCASP0_RCLKCHK = 0x00FF0008; // 255-MAX 0-MIN, div-by-
256
MCASP0_PFUNC = 0x00;
MCASP0_PDIR = 0x00000001;
MCASP0_DITCTL = 0x00000000; // Not used
MCASP0_DLBCTL = 0x00000000; // Not used
MCASP0_AMUTE = 0x00000000; // Not used
MCASP0_XGBLCTL |= GBLCTL_XCLKRST_ON;
// Clk
while ( ( MCASP0_XGBLCTL & GBLCTL_XCLKRST_ON ) !=
GBLCTL_XCLKRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RCLKRST_ON;
// Clk
while ( ( MCASP0_RGBLCTL & GBLCTL_RCLKRST_ON ) !=
GBLCTL_RCLKRST_ON );
MCASP0_XGBLCTL |= GBLCTL_XSRCLR_ON;
// Serialize
while ( ( MCASP0_XGBLCTL & GBLCTL_XSRCLR_ON ) != GBLCTL_XSRCLR_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSRCLR_ON;
// Serialize
while ( ( MCASP0_RGBLCTL & GBLCTL_RSRCLR_ON ) != GBLCTL_RSRCLR_ON
);
MCASP0_XBUF0 = 0;
MCASP0_XGBLCTL |= GBLCTL_XSMRST_ON;
// State Machine
while ( ( MCASP0_XGBLCTL & GBLCTL_XSMRST_ON ) != GBLCTL_XSMRST_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSMRST_ON;
// State Machine
while ( ( MCASP0_RGBLCTL & GBLCTL_RSMRST_ON ) != GBLCTL_RSMRST_ON
);
MCASP0_XGBLCTL |= GBLCTL_XFRST_ON;
// Frame Sync
while ( ( MCASP0_XGBLCTL & GBLCTL_XFRST_ON ) != GBLCTL_XFRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RFRST_ON;
// Frame Sync
while ( ( MCASP0_RGBLCTL & GBLCTL_RFRST_ON ) != GBLCTL_RFRST_ON );
while(1)
{ while ( ! ( MCASP0_SRCTL1 & 0x20 ) );
input_data1 = MCASP0_RBUF1_32BIT;
input_data2 = FIR_FILTER(filter_Coeff , input_data1);
while ( ! ( MCASP0_SRCTL0 & 0x10 ) );
MCASP0_XBUF0_32BIT = (input_data2 << 16);
}
}
signed int FIR_FILTER(float h[], signed int x)
{
int i=0;
signed long output=0;
in_buffer[0] = x; /* new input at buffer[0] */
for(i=29;i>0;i--)
in_buffer[i] = in_buffer[i-1]; /* shuffle the buffer */
for(i=0;i<31;i++)
output = output + h[i] * in_buffer[i];
return(output);
}
}
}
void spi_init( )
{
/* Reset SPI */
SPI_SPIGCR0 = 0;
DSP6745_wait( 1000 );
/* Release SPI */
SPI_SPIGCR0 = 1;
SPI_SPIPC0 = 0
| ( 1 << 11 ) // DI
| ( 1 << 10 ) // DO
| ( 1 << 9 ) // CLK
| ( 1 << 8 ) // EN0
| ( 1 << 0 ); // CS
spidat1 = 0
| ( 0 << 28 ) // CSHOLD
| ( 0 << 24 ) // DFSEL Format [0]
| ( 1 << 26 )
| ( 0 << 16 ) // CSNR
| ( 0 << 0 ); //
SPI_SPIFMT0 = 0
| ( 0 << 20 ) // SHIFTDIR
| ( 0 << 17 ) // Polarity
| ( 1 << 16 ) // Phase
| ( 14 << 8 ) // Prescale to 30MHz (150/(value+1))//29
SPI_SPIDAT1 = spidat1;
SPI_SPIDELAY = 0
| ( 8 << 24 ) // C2TDELAY
| ( 8 << 16 ); // T2CDELAY
SPI_SPIDEF = 0
| ( 1 << 1 ) // EN1 inactive high
| ( 1 << 0 ); // EN0 inactive high
SPI_SPIINT = 0;
SPI_SPIDEF = 0x01;
SPI_SPIGCR1 |= ( 1 << 24 ); //Enable SPI
}
void main( )
{
Uint32 GBLCTL_XHCLKRST_ON = 0X00000200;
Uint32 GBLCTL_RHCLKRST_ON = 0x00000002;
Uint32 GBLCTL_XCLKRST_ON = 0X00000100;
Uint32 GBLCTL_RCLKRST_ON = 0X00000001;
Uint32 GBLCTL_XSRCLR_ON = 0X00000400;
Uint32 GBLCTL_RSRCLR_ON = 0X00000004;
Uint32 GBLCTL_XSMRST_ON = 0X00000800;
Uint32 GBLCTL_RSMRST_ON = 0X00000008;
Uint32 GBLCTL_XFRST_ON = 0X00001000;
Uint32 GBLCTL_RFRST_ON = 0X00000010;
int temp,i;
signed int input_data1, input_data2;
Uint16 codec_reg_val[] = {0X0017, 0X0217, 0X04D8, 0X06D8, 0X0811, 0X0A00,
0X0C00, 0X0E53, 0X100C, 0x1201};
PINMUX7 = 0x10110000;
PINMUX9 = 0x11011000;
PINMUX10 = 0x00000110;
spi_init( );
temp = SPI_SPIDAT1;
}
SPI_SPIGCR0 = 0;
DSP6745_wait( 1000 );
MCASP0_GBLCTL = 0;
MCASP0_RGBLCTL = 0;
MCASP0_XGBLCTL = 0;
MCASP0_PWRDEMU = 1;
MCASP0_RMASK = 0xFFFFFFFF;
MCASP0_RFMT = 0x00018078; // MSB 16bit, 0-delay, no
pad, CFGBus
MCASP0_AFSRCTL = 0x00000000; // 2TDM, 1bit Rising edge
INTERNAL FS, word
MCASP0_ACLKRCTL = 0x00000081;//0x000000AF; // Rising
INTERNAL CLK(from tx side)
MCASP0_AHCLKRCTL = 0x00008000;//INT CLK (from tx side)
MCASP0_RTDM = 0x00000003; // Slots 0,1
MCASP0_RINTCTL = 0x00000000; // Not used
MCASP0_RCLKCHK = 0x00FF0008; // 255-MAX 0-MIN, div-by-
256
MCASP0_XMASK = 0xFFFFFFFF; // No padding used
MCASP0_XFMT = 0x00018078; // MSB 16bit, 0-delay, no
pad, CFGBus
MCASP0_AFSXCTL = 0x00000000; // 2TDM, 1bit Rising edge
INTERNAL FS, word
MCASP0_ACLKXCTL = 0x00000081;//0x000000AF; // ASYNC,
Rising INTERNAL CLK, div-by-16
MCASP0_AHCLKXCTL = 0x00008000;// INT CLK, div-by-4
MCASP0_XTDM = 0x00000003; // Slots 0,1
MCASP0_XINTCTL = 0x00000000; // Not used
MCASP0_XCLKCHK = 0x00FF0008; // 255-MAX 0-MIN, div-by-
256
MCASP0_SRCTL1 = 0x0002; // MCASP0.AXR0[1] <-- DOUT
MCASP0_SRCTL0 = 0x0001; // MCASP0.AXR0[0] --> DIN
MCASP0_PFUNC = 0x00;
MCASP0_PDIR = 0x00000001;
MCASP0_DITCTL = 0x00000000; // Not used
MCASP0_DLBCTL = 0x00000000; // Not used
MCASP0_AMUTE = 0x00000000; // Not used
MCASP0_XGBLCTL |= GBLCTL_XCLKRST_ON;
// Clk
while ( ( MCASP0_XGBLCTL & GBLCTL_XCLKRST_ON ) !=
GBLCTL_XCLKRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RCLKRST_ON;
// Clk
while ( ( MCASP0_RGBLCTL & GBLCTL_RCLKRST_ON ) !=
GBLCTL_RCLKRST_ON );
MCASP0_XGBLCTL |= GBLCTL_XSRCLR_ON;
// Serialize
while ( ( MCASP0_XGBLCTL & GBLCTL_XSRCLR_ON ) != GBLCTL_XSRCLR_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSRCLR_ON;
// Serialize
while ( ( MCASP0_RGBLCTL & GBLCTL_RSRCLR_ON ) != GBLCTL_RSRCLR_ON
);
MCASP0_XBUF0 = 0;
MCASP0_XGBLCTL |= GBLCTL_XSMRST_ON;
// State Machine
while ( ( MCASP0_XGBLCTL & GBLCTL_XSMRST_ON ) != GBLCTL_XSMRST_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSMRST_ON;
// State Machine
while ( ( MCASP0_RGBLCTL & GBLCTL_RSMRST_ON ) != GBLCTL_RSMRST_ON
);
MCASP0_XGBLCTL |= GBLCTL_XFRST_ON;
// Frame Sync
while ( ( MCASP0_XGBLCTL & GBLCTL_XFRST_ON ) != GBLCTL_XFRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RFRST_ON;
// Frame Sync
while ( ( MCASP0_RGBLCTL & GBLCTL_RFRST_ON ) != GBLCTL_RFRST_ON );
/* Start by sending a dummy write */
while( ! ( MCASP0_SRCTL0 & 0x10 ) ); // Check for Tx ready
MCASP0_XBUF0 = 0;
while(1)
{
while ( ! ( MCASP0_SRCTL1 & 0x20 ) );
input_data1 = MCASP0_RBUF1_32BIT;
input_data2 = FIR_FILTER(filter_Coeff , input_data1);
while ( ! ( MCASP0_SRCTL0 & 0x10 ) );
MCASP0_XBUF0_32BIT = (input_data2 << 16);
}
}
signed int FIR_FILTER(float h[], signed int x)
{
int i=0;
signed long output=0;
in_buffer[0] = x; /* new input at buffer[0] */
for(i=29;i>0;i--)
in_buffer[i] = in_buffer[i-1]; /* shuffle the buffer */
for(i=0;i<31;i++)
output = output + h[i] * in_buffer[i];
return(output);
}
#include<stdio.h>
#include "sysreg.h"
#define Uint32 unsigned int
#define Uint16 unsigned short
#define Uint8 unsigned char
#define Int32 int
#define Int16 short
#define Int8 char
static Uint32 spidat1;
void DSP6745_wait( Uint32 delay )
{
volatile Uint32 i;
for ( i = 0 ; i < delay ; i++ )
{
}
}
void spi_init( )
{
/* Reset SPI */
SPI_SPIGCR0 = 0;
DSP6745_wait( 1000 );
/* Release SPI */
SPI_SPIGCR0 = 1;
SPI_SPIPC0 = 0
| ( 1 << 11 ) // DI
| ( 1 << 10 ) // DO
| ( 1 << 9 ) // CLK
| ( 1 << 8 ) // EN0
| ( 1 << 0 ); // CS
spidat1 = 0
| ( 0 << 28 ) // CSHOLD
| ( 0 << 24 ) // DFSEL Format [0]
| ( 1 << 26 )
| ( 0 << 16 ) // CSNR
| ( 0 << 0 ); //
SPI_SPIFMT0 = 0
| ( 0 << 20 ) // SHIFTDIR
| ( 0 << 17 ) // Polarity
| ( 1 << 16 ) // Phase
SPI_SPIDAT1 = spidat1;
SPI_SPIDELAY = 0
| ( 8 << 24 ) // C2TDELAY
| ( 8 << 16 ); // T2CDELAY
SPI_SPIDEF = 0
| ( 1 << 1 ) // EN1 inactive high
| ( 1 << 0 ); // EN0 inactive high
SPI_SPIINT = 0;
SPI_SPIDEF = 0x01;
SPI_SPIGCR1 |= ( 1 << 24 ); //Enable SPI
}
float filter_Coeff[] ={-0.000050,-0.000138,0.000198,0.001345,0.002212,-0.000000,-
0.006489,
-0.012033,-0.005942,0.016731,0.041539,0.035687,-0.028191,-0.141589,-
0.253270,0.700008,
-0.253270,-0.141589,-0.028191,0.035687,0.041539,0.016731,-0.005942,-0.012033,-
0.006489,
-0.000000,0.002212,0.001345,0.000198,-0.000138,-0.000050};
static short in_buffer[100];
signed int FIR_FILTER(float h[], signed int x);
void main( )
{
Uint32 GBLCTL_XHCLKRST_ON = 0X00000200;
Uint32 GBLCTL_RHCLKRST_ON = 0x00000002;
Uint32 GBLCTL_XCLKRST_ON = 0X00000100;
Uint32 GBLCTL_RCLKRST_ON = 0X00000001;
Uint32 GBLCTL_XSRCLR_ON = 0X00000400;
Uint32 GBLCTL_RSRCLR_ON = 0X00000004;
Uint32 GBLCTL_XSMRST_ON = 0X00000800;
Uint32 GBLCTL_RSMRST_ON = 0X00000008;
Uint32 GBLCTL_XFRST_ON = 0X00001000;
Uint32 GBLCTL_RFRST_ON = 0X00000010;
int temp,i;
signed int input_data1, input_data2;
Uint16 codec_reg_val[] = {0X0017, 0X0217, 0X04D8, 0X06D8, 0X0811, 0X0A00,
0X0C00, 0X0E53, 0X100C, 0x1201};
PINMUX7 = 0x10110000;
PINMUX9 = 0x11011000;
PINMUX10 = 0x00000110;
spi_init( );
temp = SPI_SPIDAT1;
MCASP0_PWRDEMU = 1;
MCASP0_RMASK = 0xFFFFFFFF;
MCASP0_RFMT = 0x00018078; // MSB 16bit, 0-delay, no
pad, CFGBus
MCASP0_AFSRCTL = 0x00000000; // 2TDM, 1bit Rising edge
INTERNAL FS, word
MCASP0_ACLKRCTL = 0x00000081;//0x000000AF; // Rising
INTERNAL CLK(from tx side)
MCASP0_AHCLKRCTL = 0x00008000;//INT CLK (from tx side)
MCASP0_RTDM = 0x00000003; // Slots 0,1
MCASP0_RINTCTL = 0x00000000; // Not used
MCASP0_RCLKCHK = 0x00FF0008; // 255-MAX 0-MIN, div-by-
256 MCASP0_XMASK = 0xFFFFFFFF; // No padding used
MCASP0_XFMT = 0x00018078; // MSB 16bit, 0-delay, no
pad, CFGBus
MCASP0_AFSXCTL = 0x00000000; // 2TDM, 1bit Rising edge
INTERNAL FS, word
MCASP0_ACLKXCTL = 0x00000081;//0x000000AF; // ASYNC,
Rising INTERNAL CLK, div-by-16
MCASP0_AHCLKXCTL = 0x00008000;// INT CLK, div-by-4
MCASP0_XTDM = 0x00000003; // Slots 0,1
MCASP0_XINTCTL = 0x00000000; // Not used
MCASP0_XCLKCHK = 0x00FF0008; // 255-MAX 0-MIN, div-by-
256
MCASP0_PFUNC = 0x00;
MCASP0_PDIR = 0x00000001;
MCASP0_DITCTL = 0x00000000; // Not used
MCASP0_DLBCTL = 0x00000000; // Not used
MCASP0_AMUTE = 0x00000000; // Not used
/* Starting sections of the McASP*/
MCASP0_XGBLCTL |= GBLCTL_XHCLKRST_ON;
// HS Clk
while ( ( MCASP0_XGBLCTL & GBLCTL_XHCLKRST_ON ) !=
GBLCTL_XHCLKRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RHCLKRST_ON;
// HS Clk
while ( ( MCASP0_RGBLCTL & GBLCTL_RHCLKRST_ON ) !=
GBLCTL_RHCLKRST_ON );
MCASP0_XGBLCTL |= GBLCTL_XCLKRST_ON;
// Clk
while ( ( MCASP0_XGBLCTL & GBLCTL_XCLKRST_ON ) !=
GBLCTL_XCLKRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RCLKRST_ON;
// Clk
while ( ( MCASP0_RGBLCTL & GBLCTL_RCLKRST_ON ) !=
GBLCTL_RCLKRST_ON );
MCASP0_XGBLCTL |= GBLCTL_XSRCLR_ON;
// Serialize
MCASP0_XBUF0 = 0;
MCASP0_XGBLCTL |= GBLCTL_XSMRST_ON;
// State Machine
while ( ( MCASP0_XGBLCTL & GBLCTL_XSMRST_ON ) != GBLCTL_XSMRST_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSMRST_ON;
// State Machine
while ( ( MCASP0_RGBLCTL & GBLCTL_RSMRST_ON ) != GBLCTL_RSMRST_ON
);
MCASP0_XGBLCTL |= GBLCTL_XFRST_ON;
// Frame Sync
while ( ( MCASP0_XGBLCTL & GBLCTL_XFRST_ON ) != GBLCTL_XFRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RFRST_ON;
// Frame Sync
while ( ( MCASP0_RGBLCTL & GBLCTL_RFRST_ON ) != GBLCTL_RFRST_ON );
/* Start by sending a dummy write */
while( ! ( MCASP0_SRCTL0 & 0x10 ) ); // Check for Tx ready
MCASP0_XBUF0 = 0;
while(1)
{
while ( ! ( MCASP0_SRCTL1 & 0x20 ) );
input_data1 = MCASP0_RBUF1_32BIT;
input_data2 = FIR_FILTER(filter_Coeff , input_data1);
while ( ! ( MCASP0_SRCTL0 & 0x10 ) );
MCASP0_XBUF0_32BIT = (input_data2 << 16);
}
}
signed int FIR_FILTER(float h[], signed int x)
{
int i=0;
signed long output=0;
in_buffer[0] = x; /* new input at buffer[0] */
for(i=29;i>0;i--)
in_buffer[i] = in_buffer[i-1]; /* shuffle the buffer */
for(i=0;i<31;i++)
output = output + h[i] * in_buffer[i];
return(output);
}
OUTPUT:
As we giving applied sine input through line in, the output will appear as per the filter
type on DSO.
Output will decreasing after the cutoff frequency for low pass filter
Output will appear at the cutoff frequency for high pass filter
LPF
INPUT FREQUENCY (500Hz) OUTPUT
HPF
INPUT FREQUENCY (400Hz) OUTPUT
5. Result
Conclusion
Viva Questions
1. Write the procedure for design of FIR filters by using Kaiser Window?
125 | P a g e VEMU INSTITUTE OF TECHNOLOGY, DEPT OF E.C.E
2. Write the expression for rectangular widow and what is Peak amplitude of side lobe
(db, Main lobe width and minimum stop band attenuation?
3. Write the expression for Triangular widow and what is Peak amplitude of side lobe (db,
Main lobe width and minimum stop band attenuation?
4. Write the expression for Hanning widow and what is Peak amplitude of side lobe (db,
Main lobe width and minimum stop band attenuation?
5. Write the expression for Hamming widow and what is Peak amplitude of side lobe (db,
Main lobe width and minimum stop band attenuation?
AIM: To design and implement an IIR Butterworth LP/HP Filter for given specification.
APPARATUS REQUIRED
Procedure
1. To create the New Project
2. Project→ New CCS Project (Give name to project with location to save or use default
location)Select project type→ Executable
3. Device Family→C6000
4. Variant→C674xFloating-point DSP
5. Connection →Texas Instruments XDS100V2USB Emulator
6. Click on Empty Project then Finish
7. To create a Source file
8. File →New→ Source file (Save & give file name, Eg: sum.c).Click on Finish
9. Write the C-Program To build the program project →Build All
10. After Build Finished without errors, Now DSP kit is turned ON
11. Debug the Program after loading is done
12. Run the Program and verify the output
13. Connect CRO to the LINE OUT.
14. Connect a Signal Generator to the LINE IN.
15. Switch on the Signal Generator with a sine wave of frequency 100 Hz. and Vp-p=1.0v
& vary the frequency.
#include<stdio.h>
#include "sysreg.h"
#define Uint32 unsigned int
#define Uint16 unsigned short
#define Uint8 unsigned char
#define Int32 int
#define Int16 short
#define Int8 char
}
}
void spi_init( )
{
/* Reset SPI */
SPI_SPIGCR0 = 0;
DSP6745_wait( 1000 );
/* Release SPI */
SPI_SPIGCR0 = 1;
/* SPI 4-Pin Mode setup */
SPI_SPIGCR1 = 0
| ( 0 << 24 )//Deactivates SPI
| ( 0 << 16 )//Internal loop-back test mode disabled/enabled=0/1
//| ( 1 << 1 )//MASTER MODE. SPIx_CLK is an output and the SPI initiates
transfers
| ( 3 << 0 );//MASTER MODE. SPIx_CLK is an output and the SPI initiates
transfers
SPI_SPIPC0 = 0
| ( 1 << 11 ) // DI
| ( 1 << 10 ) // DO
| ( 1 << 9 ) // CLK
| ( 1 << 8 ) // EN0
| ( 1 << 0 ); // CS
spidat1 = 0
| ( 0 << 28 ) // CSHOLD
| ( 0 << 24 ) // DFSEL Format [0]
| ( 1 << 26 )
| ( 0 << 16 ) // CSNR
| ( 0 << 0 ); //
SPI_SPIFMT0 = 0
| ( 0 << 20 ) // SHIFTDIR
| ( 0 << 17 ) // Polarity
| ( 1 << 16 ) // Phase
SPI_SPIDAT1 = spidat1;
SPI_SPIDELAY = 0
| ( 8 << 24 ) // C2TDELAY
| ( 8 << 16 ); // T2CDELAY
SPI_SPIDEF = 0
| ( 1 << 1 ) // EN1 inactive high
| ( 1 << 0 ); // EN0 inactive high
SPI_SPIINT = 0;
SPI_SPIDEF = 0x01;
SPI_SPIGCR1 |= ( 1 << 24 ); //Enable SPI
}
const signed int filter_Coeff[] =
{
312,312,312,32767,-27943,24367 /*LP 800 */
} ;
signed int IIR_FILTER(const signed int h[], signed int x1);
void main( )
{
Uint32 GBLCTL_XHCLKRST_ON = 0X00000200;
Uint32 GBLCTL_RHCLKRST_ON = 0x00000002;
Uint32 GBLCTL_XCLKRST_ON = 0X00000100;
Uint32 GBLCTL_RCLKRST_ON = 0X00000001;
Uint32 GBLCTL_XSRCLR_ON = 0X00000400;
Uint32 GBLCTL_RSRCLR_ON = 0X00000004;
Uint32 GBLCTL_XSMRST_ON = 0X00000800;
Uint32 GBLCTL_RSMRST_ON = 0X00000008;
Uint32 GBLCTL_XFRST_ON = 0X00001000;
Uint32 GBLCTL_RFRST_ON = 0X00000010;
int temp,i;
signed int input_data1, input_data2;
//Uint16 x, y, z;
Uint16 codec_reg_val[] = {0X0017, 0X0217, 0X04D8, 0X06D8, 0X0811, 0X0A00,
0X0C00, 0X0E53, 0X100C, 0x1201};
PINMUX7 = 0x10110000;
PINMUX9 = 0x11011000;
PINMUX10 = 0x00000110;
spi_init( );
temp = SPI_SPIDAT1;
MCASP0_GBLCTL = 0;
MCASP0_RGBLCTL = 0;
MCASP0_XGBLCTL = 0;
MCASP0_PWRDEMU = 1;
MCASP0_RMASK = 0xFFFFFFFF;
MCASP0_RFMT = 0x00018078; // MSB 16bit, 0-delay, no
pad, CFGBus
MCASP0_AFSRCTL = 0x00000000; // 2TDM, 1bit Rising edge
INTERNAL FS, word
MCASP0_ACLKRCTL = 0x00000081;//0x000000AF; // Rising
INTERNAL CLK(from tx side)
MCASP0_AHCLKRCTL = 0x00008000;//INT CLK (from tx side)
MCASP0_RTDM = 0x00000003; // Slots 0,1
MCASP0_RINTCTL = 0x00000000; // Not used
MCASP0_RCLKCHK = 0x00FF0008; // 255-MAX 0-MIN, div-by-
256
MCASP0_PFUNC = 0x00;
MCASP0_PDIR = 0x00000001;
MCASP0_DITCTL = 0x00000000; // Not used
MCASP0_DLBCTL = 0x00000000; // Not used
MCASP0_AMUTE = 0x00000000; // Not used
MCASP0_XGBLCTL |= GBLCTL_XCLKRST_ON;
// Clk
while ( ( MCASP0_XGBLCTL & GBLCTL_XCLKRST_ON ) !=
GBLCTL_XCLKRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RCLKRST_ON;
// Clk
while ( ( MCASP0_RGBLCTL & GBLCTL_RCLKRST_ON ) !=
GBLCTL_RCLKRST_ON );
MCASP0_XGBLCTL |= GBLCTL_XSRCLR_ON;
// Serialize
while ( ( MCASP0_XGBLCTL & GBLCTL_XSRCLR_ON ) != GBLCTL_XSRCLR_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSRCLR_ON;
// Serialize
while ( ( MCASP0_RGBLCTL & GBLCTL_RSRCLR_ON ) != GBLCTL_RSRCLR_ON
);
MCASP0_XBUF0 = 0;
MCASP0_XGBLCTL |= GBLCTL_XSMRST_ON;
// State Machine
while ( ( MCASP0_XGBLCTL & GBLCTL_XSMRST_ON ) != GBLCTL_XSMRST_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSMRST_ON;
// State Machine
while ( ( MCASP0_RGBLCTL & GBLCTL_RSMRST_ON ) != GBLCTL_RSMRST_ON
);
MCASP0_XGBLCTL |= GBLCTL_XFRST_ON;
// Frame Sync
while ( ( MCASP0_XGBLCTL & GBLCTL_XFRST_ON ) != GBLCTL_XFRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RFRST_ON;
// Frame Sync
while ( ( MCASP0_RGBLCTL & GBLCTL_RFRST_ON ) != GBLCTL_RFRST_ON );
while(1)
{
while ( ! ( MCASP0_SRCTL1 & 0x20 ) );
input_data1 = MCASP0_RBUF1_32BIT;
input_data2 = IIR_FILTER(filter_Coeff , input_data1);
while ( ! ( MCASP0_SRCTL0 & 0x10 ) );
MCASP0_XBUF0_32BIT = (input_data2 << 16);
}
signed int IIR_FILTER(const signed int h[], signed int x1)
{
static signed int x[6] = { 0, 0, 0, 0, 0, 0 }; /* x(n), x(n-1), x(n-2). Must be
static */
static signed int y[6] = { 0, 0, 0, 0, 0, 0 }; /* y(n), y(n-1), y(n-2). Must be
static */
int temp=0;
temp = (short int)x1; /* Copy input to temp */
x[0] = (signed int) temp; /* Copy input to x[stages][0] */
temp = ( (int)h[0] * x[0]) ; /* B0 * x(n) */
2. Butterworth HPF
PROGRAM:
#include<stdio.h>
#include "sysreg.h"
#define Uint32 unsigned int
#define Uint16 unsigned short
#define Uint8 unsigned char
#define Int32 int
#define Int16 short
#define Int8 char
static Uint32 spidat1;
}
}
void spi_init( )
{
/* Reset SPI */
SPI_SPIGCR0 = 0;
DSP6745_wait( 1000 );
/* Release SPI */
SPI_SPIGCR0 = 1;
SPI_SPIPC0 = 0
| ( 1 << 11 ) // DI
| ( 1 << 10 ) // DO
| ( 1 << 9 ) // CLK
| ( 1 << 8 ) // EN0
| ( 1 << 0 ); // CS
spidat1 = 0
| ( 0 << 28 ) // CSHOLD
| ( 0 << 24 ) // DFSEL Format [0]
| ( 1 << 26 )
| ( 0 << 16 ) // CSNR
| ( 0 << 0 ); //
SPI_SPIFMT0 = 0
| ( 0 << 20 ) // SHIFTDIR
| ( 0 << 17 ) // Polarity
| ( 1 << 16 ) // Phase
| ( 14 << 8 ) // Prescale to 30MHz (150/(value+1))//29
| ( 16 << 0 ); // Char Len | ( 1F << 0 );
SPI_SPIDAT1 = spidat1;
SPI_SPIDELAY = 0
| ( 8 << 24 ) // C2TDELAY
| ( 8 << 16 ); // T2CDELAY
SPI_SPIDEF = 0
| ( 1 << 1 ) // EN1 inactive high
| ( 1 << 0 ); // EN0 inactive high
SPI_SPIINT = 0;
SPI_SPIDEF = 0x01;
SPI_SPIGCR1 |= ( 1 << 24 ); //Enable SPI
}
void main( )
{
Uint32 GBLCTL_XHCLKRST_ON = 0X00000200;
Uint32 GBLCTL_RHCLKRST_ON = 0x00000002;
Uint32 GBLCTL_XCLKRST_ON = 0X00000100;
Uint32 GBLCTL_RCLKRST_ON = 0X00000001;
Uint32 GBLCTL_XSRCLR_ON = 0X00000400;
int temp,i;
signed int input_data1, input_data2;
//Uint16 x, y, z;
Uint16 codec_reg_val[] = {0X0017, 0X0217, 0X04D8, 0X06D8, 0X0811, 0X0A00,
0X0C00, 0X0E53, 0X100C, 0x1201};
PINMUX7 = 0x10110000;
PINMUX9 = 0x11011000;
PINMUX10 = 0x00000110;
spi_init( );
temp = SPI_SPIDAT1;
MCASP0_GBLCTL = 0;
MCASP0_RGBLCTL = 0;
MCASP0_XGBLCTL = 0;
MCASP0_PWRDEMU = 1;
MCASP0_RMASK = 0xFFFFFFFF;
MCASP0_RFMT = 0x00018078; // MSB 16bit, 0-delay, no
pad, CFGBus
MCASP0_AFSRCTL = 0x00000000; // 2TDM, 1bit Rising edge
INTERNAL FS, word
MCASP0_ACLKRCTL = 0x00000081;//0x000000AF; // Rising
INTERNAL CLK(from tx side)
MCASP0_AHCLKRCTL = 0x00008000;//INT CLK (from tx side)
MCASP0_RTDM = 0x00000003; // Slots 0,1
MCASP0_RINTCTL = 0x00000000; // Not used
MCASP0_RCLKCHK = 0x00FF0008; // 255-MAX 0-MIN, div-by-
256
MCASP0_PFUNC = 0x00;
MCASP0_PDIR = 0x00000001;
MCASP0_DITCTL = 0x00000000; // Not used
MCASP0_DLBCTL = 0x00000000; // Not used
MCASP0_AMUTE = 0x00000000; // Not used
MCASP0_XGBLCTL |= GBLCTL_XCLKRST_ON;
// Clk
while ( ( MCASP0_XGBLCTL & GBLCTL_XCLKRST_ON ) !=
GBLCTL_XCLKRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RCLKRST_ON;
// Clk
while ( ( MCASP0_RGBLCTL & GBLCTL_RCLKRST_ON ) !=
GBLCTL_RCLKRST_ON );
MCASP0_XGBLCTL |= GBLCTL_XSRCLR_ON;
// Serialize
while ( ( MCASP0_XGBLCTL & GBLCTL_XSRCLR_ON ) != GBLCTL_XSRCLR_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSRCLR_ON;
// Serialize
while ( ( MCASP0_RGBLCTL & GBLCTL_RSRCLR_ON ) != GBLCTL_RSRCLR_ON
);
MCASP0_XBUF0 = 0;
MCASP0_XGBLCTL |= GBLCTL_XSMRST_ON;
// State Machine
while ( ( MCASP0_XGBLCTL & GBLCTL_XSMRST_ON ) != GBLCTL_XSMRST_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSMRST_ON;
// State Machine
while ( ( MCASP0_RGBLCTL & GBLCTL_RSMRST_ON ) != GBLCTL_RSMRST_ON
);
MCASP0_XGBLCTL |= GBLCTL_XFRST_ON;
// Frame Sync
while ( ( MCASP0_XGBLCTL & GBLCTL_XFRST_ON ) != GBLCTL_XFRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RFRST_ON;
// Frame Sync
while(1)
{
OUTPUT:
As we giving applied sine input through line in, the output will appear as per the
filter type on DSO.
Output will decreasing after the cutoff frequency for low pass filter
Output will appear at the cutoff frequency for high pass filter
RESULT
CONCLUSION
VIVA QUESTIONS
1. Write the design procedure of butter worth IIR filter using Bilinear Transformation
Method?
2. Write the design procedure of butter worth IIR filter using Impulse Invariant Method?
APPARATUS REQUIRED
1. Chebyshev LPF
PROGRAM:
#include<stdio.h>
#include "sysreg.h"
#define Uint32 unsigned int
#define Uint16 unsigned short
#define Uint8 unsigned char
#define Int32 int
#define Int16 short
#define Int8 char
static Uint32 spidat1;
void DSP6745_wait( Uint32 delay )
{
volatile Uint32 i;
for ( i = 0 ; i < delay ; i++ )
{
}
}
void spi_init( )
{
/* Reset SPI */
SPI_SPIGCR0 = 0;
DSP6745_wait( 1000 );
/* Release SPI */
SPI_SPIGCR0 = 1;
SPI_SPIPC0 = 0
| ( 1 << 11 ) // DI
| ( 1 << 10 ) // DO
| ( 1 << 9 ) // CLK
| ( 1 << 8 ) // EN0
| ( 1 << 0 ); // CS
spidat1 = 0
| ( 0 << 28 ) // CSHOLD
| ( 0 << 24 ) // DFSEL Format [0]
| ( 1 << 26 )
| ( 0 << 16 ) // CSNR
| ( 0 << 0 ); //
SPI_SPIFMT0 = 0
| ( 0 << 20 ) // SHIFTDIR
| ( 0 << 17 ) // Polarity
| ( 1 << 16 ) // Phase
| ( 14 << 8 ) // Prescale to 30MHz (150/(value+1))//29
| ( 16 << 0 ); // Char Len | ( 1F << 0 );
SPI_SPIDAT1 = spidat1;
SPI_SPIDELAY = 0
| ( 8 << 24 ) // C2TDELAY
| ( 8 << 16 ); // T2CDELAY
SPI_SPIDEF = 0
| ( 1 << 1 ) // EN1 inactive high
| ( 1 << 0 ); // EN0 inactive high
SPI_SPIINT = 0;
SPI_SPIDEF = 0x01;
SPI_SPIGCR1 |= ( 1 << 24 ); //Enable SPI
}
void main( )
{
Uint32 GBLCTL_XHCLKRST_ON = 0X00000200;
Uint32 GBLCTL_RHCLKRST_ON = 0x00000002;
Uint32 GBLCTL_XCLKRST_ON = 0X00000100;
Uint32 GBLCTL_RCLKRST_ON = 0X00000001;
Uint32 GBLCTL_XSRCLR_ON = 0X00000400;
Uint32 GBLCTL_RSRCLR_ON = 0X00000004;
Uint32 GBLCTL_XSMRST_ON = 0X00000800;
Uint32 GBLCTL_RSMRST_ON = 0X00000008;
Uint32 GBLCTL_XFRST_ON = 0X00001000;
Uint32 GBLCTL_RFRST_ON = 0X00000010;
int temp,i;
signed int input_data1, input_data2;
//Uint16 x, y, z;
Uint16 codec_reg_val[] = {0X0017, 0X0217, 0X04D8, 0X06D8, 0X0811, 0X0A00,
0X0C00, 0X0E53, 0X100C, 0x1201};
PINMUX7 = 0x10110000;
PINMUX9 = 0x11011000;
PINMUX10 = 0x00000110;
spi_init( );
temp = SPI_SPIDAT1;
MCASP0_GBLCTL = 0;
MCASP0_RGBLCTL = 0;
MCASP0_XGBLCTL = 0;
MCASP0_PWRDEMU = 1;
MCASP0_RMASK = 0xFFFFFFFF;
MCASP0_RFMT = 0x00018078; // MSB 16bit, 0-delay, no
pad, CFGBus
MCASP0_AFSRCTL = 0x00000000; // 2TDM, 1bit Rising edge
INTERNAL FS, word
MCASP0_ACLKRCTL = 0x00000081;//0x000000AF; // Rising
INTERNAL CLK(from tx side)
MCASP0_AHCLKRCTL = 0x00008000;//INT CLK (from tx side)
MCASP0_RTDM = 0x00000003; // Slots 0,1
MCASP0_RINTCTL = 0x00000000; // Not used
MCASP0_RCLKCHK = 0x00FF0008; // 255-MAX 0-MIN, div-by-
256
MCASP0_PFUNC = 0x00;
MCASP0_PDIR = 0x00000001;
MCASP0_DITCTL = 0x00000000; // Not used
MCASP0_DLBCTL = 0x00000000; // Not used
MCASP0_AMUTE = 0x00000000; // Not used
MCASP0_XGBLCTL |= GBLCTL_XCLKRST_ON;
// Clk
while ( ( MCASP0_XGBLCTL & GBLCTL_XCLKRST_ON ) !=
GBLCTL_XCLKRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RCLKRST_ON;
// Clk
while ( ( MCASP0_RGBLCTL & GBLCTL_RCLKRST_ON ) !=
GBLCTL_RCLKRST_ON );
MCASP0_XGBLCTL |= GBLCTL_XSRCLR_ON;
// Serialize
while ( ( MCASP0_XGBLCTL & GBLCTL_XSRCLR_ON ) != GBLCTL_XSRCLR_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSRCLR_ON;
// Serialize
while ( ( MCASP0_RGBLCTL & GBLCTL_RSRCLR_ON ) != GBLCTL_RSRCLR_ON
);
MCASP0_XBUF0 = 0;
MCASP0_XGBLCTL |= GBLCTL_XSMRST_ON;
// State Machine
while ( ( MCASP0_XGBLCTL & GBLCTL_XSMRST_ON ) != GBLCTL_XSMRST_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSMRST_ON;
// State Machine
while ( ( MCASP0_RGBLCTL & GBLCTL_RSMRST_ON ) != GBLCTL_RSMRST_ON
);
MCASP0_XGBLCTL |= GBLCTL_XFRST_ON;
// Frame Sync
while ( ( MCASP0_XGBLCTL & GBLCTL_XFRST_ON ) != GBLCTL_XFRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RFRST_ON;
// Frame Sync
while ( ( MCASP0_RGBLCTL & GBLCTL_RFRST_ON ) != GBLCTL_RFRST_ON );
while(1)
{
}
signed int IIR_FILTER(const signed int h[], signed int x1)
{
static signed int x[6] = { 0, 0, 0, 0, 0, 0 }; /* x(n), x(n-1), x(n-2). Must be
static */
static signed int y[6] = { 0, 0, 0, 0, 0, 0 }; /* y(n), y(n-1), y(n-2). Must be
static */
int temp=0;
temp = (short int)x1; /* Copy input to temp */
x[0] = (signed int) temp; /* Copy input to x[stages][0] */
}
}
void spi_init( )
{
/* Reset SPI */
SPI_SPIGCR0 = 0;
DSP6745_wait( 1000 );
/* Release SPI */
SPI_SPIGCR0 = 1;
SPI_SPIGCR1 = 0
| ( 0 << 24 )//Deactivates SPI
| ( 0 << 16 )//Internal loop-back test mode disabled/enabled=0/1
//| ( 1 << 1 )//MASTER MODE. SPIx_CLK is an output and the SPI initiates
transfers
| ( 3 << 0 );//MASTER MODE. SPIx_CLK is an output and the SPI initiates
transfers
SPI_SPIPC0 = 0
| ( 1 << 11 ) // DI
| ( 1 << 10 ) // DO
| ( 1 << 9 ) // CLK
| ( 1 << 8 ) // EN0
| ( 1 << 0 ); // CS
spidat1 = 0
| ( 0 << 28 ) // CSHOLD
| ( 0 << 24 ) // DFSEL Format [0]
| ( 1 << 26 )
| ( 0 << 16 ) // CSNR
| ( 0 << 0 ); //
SPI_SPIFMT0 = 0
| ( 0 << 20 ) // SHIFTDIR
| ( 0 << 17 ) // Polarity
| ( 1 << 16 ) // Phase
| ( 14 << 8 ) // Prescale to 30MHz (150/(value+1))//29
| ( 16 << 0 ); // Char Len | ( 1F << 0 );
SPI_SPIDAT1 = spidat1;
SPI_SPIDELAY = 0
| ( 8 << 24 ) // C2TDELAY
| ( 8 << 16 ); // T2CDELAY
SPI_SPIDEF = 0
| ( 1 << 1 ) // EN1 inactive high
| ( 1 << 0 ); // EN0 inactive high
SPI_SPIINT = 0;
SPI_SPIDEF = 0x01;
SPI_SPIGCR1 |= ( 1 << 24 ); //Enable SPI
}
void main( )
{
Uint32 GBLCTL_XHCLKRST_ON = 0X00000200;
Uint32 GBLCTL_RHCLKRST_ON = 0x00000002;
Uint32 GBLCTL_XCLKRST_ON = 0X00000100;
Uint32 GBLCTL_RCLKRST_ON = 0X00000001;
int temp,i;
signed int input_data1, input_data2;
//Uint16 x, y, z;
Uint16 codec_reg_val[] = {0X0017, 0X0217, 0X04D8, 0X06D8, 0X0811, 0X0A00,
0X0C00, 0X0E53, 0X100C, 0x1201};
PINMUX7 = 0x10110000;
PINMUX9 = 0x11011000;
PINMUX10 = 0x00000110;
spi_init( );
temp = SPI_SPIDAT1;
MCASP0_GBLCTL = 0;
MCASP0_RGBLCTL = 0;
MCASP0_XGBLCTL = 0;
MCASP0_PWRDEMU = 1;
MCASP0_RMASK = 0xFFFFFFFF;
MCASP0_RFMT = 0x00018078; // MSB 16bit, 0-delay, no
pad, CFGBus
MCASP0_AFSRCTL = 0x00000000; // 2TDM, 1bit Rising edge
INTERNAL FS, word
MCASP0_ACLKRCTL = 0x00000081;//0x000000AF; // Rising
INTERNAL CLK(from tx side)
MCASP0_AHCLKRCTL = 0x00008000;//INT CLK (from tx side)
MCASP0_RTDM = 0x00000003; // Slots 0,1
MCASP0_RINTCTL = 0x00000000; // Not used
MCASP0_RCLKCHK = 0x00FF0008; // 255-MAX 0-MIN, div-by-
256
MCASP0_PFUNC = 0x00;
MCASP0_PDIR = 0x00000001;
MCASP0_DITCTL = 0x00000000; // Not used
MCASP0_DLBCTL = 0x00000000; // Not used
MCASP0_AMUTE = 0x00000000; // Not used
MCASP0_XGBLCTL |= GBLCTL_XCLKRST_ON;
// Clk
while ( ( MCASP0_XGBLCTL & GBLCTL_XCLKRST_ON ) !=
GBLCTL_XCLKRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RCLKRST_ON;
// Clk
while ( ( MCASP0_RGBLCTL & GBLCTL_RCLKRST_ON ) !=
GBLCTL_RCLKRST_ON );
MCASP0_XGBLCTL |= GBLCTL_XSRCLR_ON;
// Serialize
while ( ( MCASP0_XGBLCTL & GBLCTL_XSRCLR_ON ) != GBLCTL_XSRCLR_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSRCLR_ON;
// Serialize
while ( ( MCASP0_RGBLCTL & GBLCTL_RSRCLR_ON ) != GBLCTL_RSRCLR_ON
);
MCASP0_XBUF0 = 0;
MCASP0_XGBLCTL |= GBLCTL_XSMRST_ON;
// State Machine
while ( ( MCASP0_XGBLCTL & GBLCTL_XSMRST_ON ) != GBLCTL_XSMRST_ON
);
MCASP0_RGBLCTL |= GBLCTL_RSMRST_ON;
// State Machine
while ( ( MCASP0_RGBLCTL & GBLCTL_RSMRST_ON ) != GBLCTL_RSMRST_ON
);
MCASP0_XGBLCTL |= GBLCTL_XFRST_ON;
// Frame Sync
while ( ( MCASP0_XGBLCTL & GBLCTL_XFRST_ON ) != GBLCTL_XFRST_ON );
MCASP0_RGBLCTL |= GBLCTL_RFRST_ON;
// Frame Sync
while ( ( MCASP0_RGBLCTL & GBLCTL_RFRST_ON ) != GBLCTL_RFRST_ON );
while(1)
{
OUTPUT:
As we giving applied sine input through line in, the output will appear as per the filter
type on DSO.
Output will decreasing after the cutoff frequency for low pass filter
Output will appear at the cutoff frequency for high pass filter
RESULT
CONCLUSION
Viva Questions
1. PROGRAM:
Decimation process
include<stdio.h>
#include<math.h>
#define TIME 100
#define PI 3.14
#define L 4
#define M 4
float x[TIME],y[TIME*L],z[TIME*L],z1[TIME*L],y1[TIME];
float temp12_L[31], temp12_M[31];
static float in_buffer[100];
void delay1()
{
int y=150000;
while(y!=0)
y--;
float m;
float n;
delay1();
delay1();
m = 6.28 * fm * no;
delay1();
delay1();
n = (m / fc);
delay1();
delay1();
if(result == 0)
{
delay1();
x[no]= sin(n);
delay1();
}
if(result == 1)
{
delay1();
temp12_L[no]= sin(n);
delay1();
}
if(result == 2)
{
delay1();
temp12_M[no]= sin(n);
delay1();
}
delay1();
delay1();
void main()
{
int i,j,p,q;
float filter_Coeff_L[31],xx,yy,zz,zz1,zz2,filter_Coeff_M[31];
for(i=0;i<TIME;i++)
sinewave(1000, 8000.0, i, 0);
printf("\ninterpolation\n");
filter_Coeff_L[0]=1.0;
for(i=1;i<31;i++)
{
sinewave(0.5, L, i, 1);
xx = temp12_L[i];
yy = PI * i;
zz = yy/ L;
filter_Coeff_L[i]=(xx/zz);
}
printf("\ndecimation\n");
filter_Coeff_M[0]= L / M;
for(i=1;i<31;i++)
{
sinewave(0.5, M, i, 2);
xx = temp12_M[i];
yy = PI * i;
zz = yy/ M;
zz1 = xx / zz;
zz2 = (zz1 * L);
filter_Coeff_M[i]=(zz2/M);
}
for(i=0;i<TIME*L;i=i+L)
{
p = (i / L);
y[i]=x[p];
for(j=i+1;j<(i+L);j++)
y[j]=0.000000;
}
for(i=0;i<TIME*L;i++)
{
delay1();
z[i]=FIR_FILTER(filter_Coeff_L ,y[i]);
delay1();
}
for(i=0; i<100; i++)
in_buffer[i] = 0;
for(i=0;i<TIME*L;i++)
{
delay1();
z1[i]=FIR_FILTER(filter_Coeff_M ,z[i]);
delay1();
}
for(i=0;i<TIME;i++)
{
delay1();
q = (i * L);
delay1();
y1[i]=z1[q];
delay1();
printf("\n%f",y1[i]);
}
printf("\nCompleted\n");
OUTPUT
We generated sample interpolated input named as z1
Then it pass through decimation process, that output named as y1
To view input graphically,
.
2. PROGRAM:
Interpolation process
#include<stdio.h>
#include<math.h>
#define TIME 100
#define PI 3.14
#define L 4
float x[TIME],y[TIME*L],z[TIME*L];
float temp12[31];
static float in_buffer[100]={0.0};
void delay1()
{
int y=150000;
while(y!=0)
y--;
float m;
float n;
delay1();
delay1();
m = 6.28 * fm * no;
delay1();
delay1();
n = (m / fc);
delay1();
delay1();
if(result == 0)
{
delay1();
x[no]= sin(n);
delay1();
}
else
{
if(result == 1)
{
delay1();
temp12[no]= sin(n);
delay1();
}
}
delay1();
delay1();
void main()
{
int i,j;
float filter_Coeff_L[31],xx,yy,zz;
for(i=0;i<TIME;i++)
sinewave(1000, 8000.0, i, 0);
//x[i]=sin(2*3.14*1000*i/8000);
filter_Coeff_L[0]=1.0;
for(i=1;i<31;i++)
{
sinewave(0.5, 4, i, 1);
xx = temp12[i];
yy = PI * i;
zz = yy/ L;
filter_Coeff_L[i]=(xx/zz);
//printf("\n%f",filter_Coeff_L[i]);
}
for(i=0;i<TIME*L;i=i+L)
{
y[i]=x[i/L];
for(j=i+1;j<(i+L);j++)
y[j]=0.000000;
}
for(i=0;i<TIME*L;i++)
{
delay1();
z[i]=FIR_FILTER(filter_Coeff_L ,y[i]);
delay1();
printf("\n%f",z[i]);
//delay1();
}
OUTPUT
We generated sample sine wave as a input named as x
Then it pass through interpolation process, that output named as z
To view input graphically,
Select Tool graph single time
Interpolation graph
RESULT:
CONCLUSION
VIVA QUESTIONS
1. Explain about multi rate digital signal processing.
3. Define interpolation.
4. Define decimation.
5. Define aliasing
ADVANCED
EXPERIMENTS
2. SOFTWARE REQUIRED:
4. PROGRAM:
clc;
clear all;
fc=44100;
t=0:0.000002:0.00002;
x=sin(2*pi*fc*t);
subplot(3,1,1);
stem(t,x);
title('original cd signal');
xlabel('no of samples');
ylabel('amplitude');
i=13;
d=6;
y=resample(x,i,d);
subplot(3,1,2);
stem(y);
title('dvd signal after using the re sample');
xlabel('no of samples');
ylabel('amplitude');
in=interp(x,i);
de=decimate(in,d);
subplot(3,1,3);
stem(de);
title('dvd signal after interpolation and decimation');
xlabel('no of samples');
ylabel('amplitude');
OUTPUT:
6.
RESULT:
CONCLUSION
7. VIVA QUESTIONS
APPARATUS REQUIRED:
Code Composer Studio
TMS320C6745 DSP Trainer Kit
PROCEDURE:
1. To create the New Project
2. Project→ New CCS Project (Give name to project with location to save or use default
3. location)
4. Select project type→ Executable
5. Device Family→C6000
6. Variant→C674xFloating-point DSP
7. Connection →Texas Instruments XDS100V2USB Emulator
8. Click on Empty Project then Finish
9. To create a Source file
10. File →New→ Source file (Save & give file name, Eg: sum.c).Click on Finish
11. Write the C-Program To build the program project →Build All
12. After Build Finished without errors, Now DSP kit is turned ON
13. Debug the Program after loading is done
14. Run the Program and verify the output
PROGRAM:
#include<stdio.h>
#include<math.h>
#define N 16
#define PI 3.14159
typedef struct
{
float real,imag;
}
complex;
complex x[N];
float iobuffer[N];
float x1[N],y[N];
int i;
main()
{
complex w[N];
complex temp1,temp2;
float sum=0.0;
int j,k,n,upper_leg,lower_leg,leg_diff,index,step;
for(i=0;i<N;i++)
{
iobuffer[i]=sin((2*PI*2*i)/15.0);
}
for(n=0;n<N;n++)
{
sum=0;
for(k=0;k<N-n;k++)
{
sum=sum+(iobuffer[k]*iobuffer[n+k]);
}
x1[n]=sum;
}
for(i=0;i<N;i++)
{
x[i].real=x1[i];
x[i].imag=0.0;
}
for(i=0;i<N;i++)
{
w[i].real=cos((2*PI*i)/(N*2.0));
w[i].imag=-sin((2*PI*i)/(N*2.0));
}
leg_diff=N/2;
step=2;
for(i=0;i<4;i++)
{
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=(x[upper_leg]).real+(x[lower_leg]).real;
temp1.imag=(x[upper_leg]).imag+(x[lower_leg]).imag;
temp2.real=(x[upper_leg]).real-(x[lower_leg]).real;
temp2.imag=(x[upper_leg]).imag-(x[lower_leg]).imag;
(x[lower_leg]).real=temp2.real*(w[index]).real-temp2.imag*(w[index]).imag;
(x[lower_leg]).imag=temp2.real*(w[index]).imag+temp2.imag*(w[index]).real;
(x[upper_leg]).real=temp1.real;
(x[upper_leg]).imag=temp1.imag;
}
index+=step;
}
leg_diff=(leg_diff)/2;
step=step*2;
}
j=0;
for(i=1;i<(N-1);i++)
{
k=N/2;
while(k<=j)
{
j=j-k;
k=k/2;
}
j=j+k;
if(i<j)
{
temp1.real=(x[j]).real;
temp1.imag=(x[j]).imag;
(x[j]).real=(x[i]).real;
(x[j]).imag=(x[i]).imag;
(x[i]).real=temp1.real;
(x[i]).imag=temp1.imag;
}
}
for(i=0;i<N;i++)
{
y[i]=sqrt((x[i].real*x[i].real)+(x[i].imag*x[i].imag));
}
for(i=0;i<N;i++)
{
printf("%f\t",y[i]);
}
return(0);
}
OUTPUT:
RESULT:
CONCLUSION
VIVA QUESTIONS
1. What do you mean by phase spectrum and magnitude spectrum give comparison?