Dsp&matlab Manuals
Dsp&matlab Manuals
Tech II Sem
PART-A
1. AIM: To write a MATLAB program to generate random signal and plot the waveform.
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
4. PROGRAM:
clc;
clear all;
close all;
t=-10:0.1:10;
L=length(t);
n=randn(1,L);
%subplot(2,1,1);
plot(t,n);
xlabel('time');
ylabel('amplitude');
title('random signal');
nmean=mean(n);
disp('mean=');
disp(nmean);
nmeansquare=sum(n.^2)/length(n);
disp('meansquare=');
disp(nmeansquare);
nstd=std(n);
disp('std=');
disp(nstd);
nvar=var(n);
disp('var=');
disp(nvar);
nskew=skewness(n);
disp('skew=');
disp(nskew);
5. OUTPUT:
VEMU INSTITUTE OF TECHNOLOGY, DEPT OF E.C.E Page
DIGITAL SIGNAL PROCESSINGLABORATORY III B.Tech II Sem
random signal
3
0
amplitude
-1
-2
-3
-4
-10 -8 -6 -4 -2 0 2 4 6 8 10
time
6. RESULT:
mean=
meansquare=
std=
var=
skew=
7. CONCLUSIONS:
1. The Statistical averages mean, mean square, standard deviation& variance are equivalent to DC
value, total power RMS value and AC power of a random signal.
2. Skew describes the shape of PDF of a random variable.
8. VIVA QUESTIONS:
1. Define impulse, unit step, ramp signals and write their expressions?
2. Define exponential and sinusoidal signals and write their expressions?
3. Express unit step signal in terms of unit impulse?
4. Express ramp signal in terms of unit step signal?
5. Represent the signal x[n]={1,2,-1,3,2}using impulse signal?
1. AIM: To write a MATLAB program to find power of a given signal and plot the power spectral
density (PSD).
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
4. PROGRAM:
clc;
clear all;
close all;
T=10;
Ts=0.001;
Fs=1/Ts;
t=[0:Ts:T];
x=cos(2*pi*100*t)+cos(2*pi*200*t)+sin(2*pi*300*t);
power=(norm(x)^2)/length(x);
disp(p);p
psd1=spectrum(x,1024);
specplot(psd1,Fs);
psd1=spectrum(x,1024);
hpsd=dspdata.psd(psd1,'Fs',Fs);
plot(hpsd);
5. OUTPUT:
20
-20
-40
Power/frequency (dB/Hz)
-60
-80
-100
-120
-140
-160
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
6. RESULT:
Thus the MATLAB program for finding Energy and power of a signal has been done successfully.
7. CONCLUSION:
All periodic signals are power signals &non-periodic signals are energy signals.
8. VIVA QUESTIONS
1.) Define a signal?
2.) What is an Energy signal?
3.) Write the formula to compute the energy of a signal?
4.) Define a power signal?
5.) Write the formula to compute the power of a signal?
2. SOFTWARE REQUIRED:
4. PROGRAM:
clc;
x=input('enter x:');
h=input('enter h:');
n=length(x);
k=length(h);
x1=[x,zeros(1,k)];
h1=[h,zeros(1,n)];
for r=1:n+k-1
y(r)=0;
for i=1:n
if(r-i+1>0)
y(r)=y(r)+x1(i)*h1(r-i+1);
m(r)=y(r);
else
end
end
end
display('output is:');m
subplot(3,1,1);
stem(x);
xlabel('n');
ylabel('x[n]');
title('x[n] vs n');
subplot(3,1,2);
stem(h);
xlabel('n');
ylabel('h[n]');
title('h[n] vs n');
subplot(3,1,3);
stem(m);
grid;
xlabel('n');
ylabel('y[n]');
title('liner convolution');
5. OUTPUT:
enter x:
enter h:
output is:
m=
x[n] vs n
10
5
x[n]
0
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
n
h[n] vs n
10
5
h[n]
0
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
n
liner convolution
100
50
y[n]
0
1 2 3 4 5 6 7 8 9 10 11
n
6. RESULT:
Thus the MATLAB program for linear convolution of discrete sequences has been obtained
successfully.
7. CONCLUSIONS:
1. Linear convolution can be used to find the response or output of LTI system.
2. Convolution & correlation are equal when any one of the signal is even signal
1. AIM: To write a MATLAB program to perform circular convolution of discrete sequences without
using built in functions.
2. SOFTWARE REQUIRED:
clc;
x=input('enter the sequence1:');
h=input('enter the sequence2:');
N1=length(x);
N2=length(h);
N=max(N1,N2);
N3=N1-N2;
if(N3>0)
h=[h,zeros(1,N3)];
else
x=[x,zeros(1,-N3)];
end
for n=1:N
y(n)=0
for i=1:N
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=[y(n)+(x(i)*h(j))]
end
end
disp('the resultant is');y
subplot(3,1,1);
stem(x);
xlabel('n');
ylabel('x[n]');
title('x[n] vs n');
subplot(3,1,2);
stem(h);
xlabel('n');
ylabel('h[n]');
title('h[n] vs n');
subplot(3,1,3);
stem(m);
grid;
xlabel('n');
ylabel('y[n]');
title('circular convolution');
5. OUTPUT:
y=
x[n] vs n
10
5
x[n]
0
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
n
h[n] vs n
5
h[n]
0
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
n
circular convolution
100
50
y[n]
0
1 2 3 4 5 6 7 8 9 10 11
n
6. RESULT:
Thus the MATLAB program for circular convolution of discrete sequences has been obtained
successfully.
7. CONCLUSION:
Circular convolution is used to analyze the signal in frequency domain using DFT.
8. VIVA QUESTIONS:
1.) Define Convolution?
2.) What are the types of Convolution?
3.) What is Linear Convolution & Circular Convolution?
4.) State the methods available to compute Convolution Sum?
5.) What is the significance of convolution?
1. AIM: To write a MATLAB program to perform auto correlation of discrete sequences without
using built in functions.
2. SOFTWARE REQUIRED:
5. OUTPUT:
m=
autocorrelation
12
10
8
amplitude
0
1 1.5 2 2.5 3 3.5 4 4.5 5
time
6. RESULT:
Thus the MATLAB program for auto correlation of discrete sequences has been obtained
successfully.
7. CONCLUSIONS:
1. Autocorrelation is always even function.
2. The maximum value of Autocorrelation occurs at τ = 0, which is equal to total power of the signal.
8. VIVA QUESTIONS:
1.) Define Correlation?
2.) What are the applications of Correlation?
3.) Classify Correlation?
4.) How Correlation is different from convolution?
5.) Describe the formula to compute Correlation?
1. AIM: To write a MATLAB program to perform cross correlation of discrete sequences without
using built in functions.
2. SOFTWARE REQUIRED:
end
n=1:N;
%plotting cross correlation output
disp('output sequence of cross correlation=');
disp(y);
%pause;
stem(n,y);
grid on;
grid minor;
xlabel('time');
ylabel('amplitude');
title('cross correlation of sequence x1 and x2');
5. OUTPUT:
enter the first sequence=
enter the second sequence=
y=
10
8
amplitude
0
1 1.5 2 2.5 3 3.5 4 4.5 5
time
6. RESULT:
Thus the MATLAB program to perform cross correlation of discrete sequences has been done
successfully.
7. CONCLUSION:
The cross correlation between two orthogonal sequence is zero.
8. VIVA QUESTIONS:
1.) Define Cross Correlation?
2.) What are the applications of Cross Correlation in signal de noising?
3.) Define Cross Power Spectral Density?
4.) How Cross Correlation is different Auto Correlation?
5.) Describe the formula to compute Cross Correlation?
DTFT OF A SIGNAL
1. AIM: Write a MATLAB program to perform DTFT of a given signal and plot the waveforms.
2. SOFTWARE REQUIRED:
4. PROGRAM:
clc;
N=input('enter the value of n');
xn=input('enter the input sequence');
N=length(xn);
k=500;p=1;
N=0:N-1;
for w=0:pi/k:pi;
xp=exp(-j*w*N);
xw(p)=xn*xp';
p=p+1;
end
w=0:pi/k:pi;
subplot(2,2,1);
plot(w/pi,abs(xw));
xlabel('freq in pi units');
ylabel('amplitude');
title('magnitude response');
grid;
subplot(2,2,2);
plot(w/pi,angle(xw));
xlabel('freq in pi units');
ylabel('amplitude');
title('phase response');
grid;
subplot(2,2,3);
plot(w/pi,real(xw));
xlabel('freq in pi units');
ylabel('amplitude');
title('real part');
grid;
subplot(2,2,4);
plot(w/pi,imag(xw));
xlabel('freq in pi units');
ylabel('amplitude');
title('imaginary part');
grid;
5. OUTPUT: enter the value of n5
enter the input sequence[1 2 3 4 5]
>>
6. RESULT:
Thus the MATLAB program to perform to perform DTFT of a given signal has been done
successfully.
7. CONCLUSION:
1. The magnitude& phase spectrums of a discrete signal using DTFT are continuous.
2. The digital frequency is varied between –П to + П Radians.
8. VIVA QUESTIONS
1.) Define DTFT?
2.) Write the Formula to Compute the DTFT?
3.) List the differences between the DFT and DTFT?
4.) Write the time shifting, frequency shifting and linearity properties?
5.) What are the drawbacks of DTFT?
2. SOFTWARE REQUIRED:
PC and MATLAB software
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
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=
enter input sequence=
fft of input sequence=
ifft of input sequence=
6. RESULT:
Thus the MATLAB program to perform N-point FFT of a given signal has been done successfully.
7. CONCLUSION:
DFT of a discrete time signal can be obtained using FFT with reduced number of complex
multiplications & additions.
8. VIVA QUESTIONS:
1.) What is the need of FFT?
2.) List the differences between FFT and DFT?
3.) Give FFT & IFFT formulae and calculate for any input sequence?
4.) What is the importance of FFT in OFDM technology?
2. SOFTWARE REQUIRED:
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi,m);
title('lpf');
ylabel('gain in db-->');
xlabel('(a)normalized freq__>');
%hpf
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi,m);
title('hpf');
ylabel('gain in db___>');
xlabel('(b)normalized freq__>');
%bpf
wn=[wp,ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m);
title('bpf');
ylabel('gain in db__>');
xlabel('(c)normalized freq__>');
%bsf
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi,m);
title('bsf');
ylabel('gain in db__>');
xlabel('(d)normalized freq__>');
5. RESULT:
Thus the MATLAB program to design FIR filter using Windowing techniques has been done
successfully.
6. CONCLUSIONS:
1. FIR Filters are always stable.
2. FIR Filters are generally used if no phase distortion is desired.
3. FIR Filters can have exactly linear phase response so that no phase distortion is introduced in the
signal by a filter.
7. VIVA QUESTIONS:
1.) Define a Filter?
2.) What is FIR and IIR filter define, and distinguish between these two?
3.) What is window method?
4.) How you will design an FIR filter using window method?
5.) What are low-pass and band-pass filter and what is the difference between these two?
8. OUTPUT:
enter pass band ripple:2
enter the stop band ripple:10
enter pass band freq:1000
enter stop band freq:3000
enter sampling freq:7000
enter your choice of window function 1.rectangular 2.triangular 3.kaiser:
1. AIM: To write a MATLAB program to design IIR LP\HP using windowing Techniques.
2. SOFTWARE REQUIRED:
5. OUTPUT:
enter the iir filter design specifications
enter the pass band ripple:2
enter the stop band ripple:20
enter the pass band freq:1000
enter the stop band freq:2000
enter the sampling freq:5000
enter choice filter 1.lpf 2.hpf /n
6. RESULT:
Thus the MATLAB program to design IIR LP\HP using windowing Techniques has been done
successfully.
8. CONCLUSION:
1. IIR filters are stable but not always guaranteed.
2. IIR Filters are generally used if sharp cutoff and high throughput is required.
3. IIR Filter requires less processing time and storage when compared to FIR Filter.
7. VIVA QUESTIONS:
1.) What do you mean by cut-off frequency?
2.) Give the differences between analog and digital filters?
3.) What is the difference between type 1 and type 2 filter structures?
4.) What is the role of delay element in filter design?
5.) List the Differences between Butterworth and chebyshev filters?
PART-B
2. PROGRAM:
#include<stdio.h>
int m=6
int n=6;
int i=0,j;
int x[15]={1,2,3,4,5,6,0,0,0,0,0,0};
int h[15]={1,2,3,4,5,6,0,0,0,0,0,0};
int y[20];
main()
{
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
for(i=0;i<m+n-1;i++)
printf("%d \n",y[i]);
}
3. OUTPUT:
VEMU INSTITUTE OF TECHNOLOGY, DEPT OF E.C.E Page
DIGITAL SIGNAL PROCESSINGLABORATORY III B.Tech II Sem
y=
4. RESULT:
Thus the C- program to find linear convolution of given two sequences has been done
successfully.
2. PROGRAM:
#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 1st sequence\n");
scanf("%d",&m);
printf("enter the length of the second sequence\n");
scanf("%d",&n);
printf("enter the 1st 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(m>n)
{
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++)
a[j]=h[n-j];
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
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];
}
}
printf("the circular convolution is\n");
for(i=0;i<n;i++)
printf("%d\t",y[i]);
}
3. INPUT:
enter the length of the 1st sequence
enter the length of the second sequence
enter the 1st sequence
enter the second sequence
4. OUTPUT:
The circular convolution is
5. RESULT:
Thus the C- program to find Circular convolution of given two sequences has been done
successfully.
DTFT OF A SIGNAL
1. AIM: - To compute the N (=4/8/16) point DFT of the given sequence.
2. PROGRAM:
#include<stdio.h>
#include<math.h>
#define PI 3.1415926538979
void main()
{
int x[10],n,N,k;
float yr[10],yi[10];
printf("enter the length of the input sequence\n");
scanf("%d",&N);
printf("enter the sequence\n");
for(n=0;n<N;n++)
scanf("%d",&x[n]);
printf("\n The DFT of the sequence is:");
for(n=0;n<N;n++)
{
yr[n]=0;
yi[n]=0;
for(k=0;k<N;k++)
{
yr[n]+=(x[k]*cos((2*PI*n*k)/N));
yi[n]+=(x[k]*sin((2*PI*n*k)/N));
}
if(yi[n]<0)
{
yi[n]=-yi[n];
printf("%f-j%f\t",yr[n],yi[n]);
}
else
printf("%f+j%f\n",yr[n],yi[n]);
}
}
3. OUTPUT:
Enter the length of the input sequence
Enter the sequence
The DFT of the sequence is:
4. RESULT:
Thus the program to compute the N (=4/8/16) point DFT of the given sequence has been done
successfully.
1. AIM: TO write a C- program to compute N=8 – FFT of given sequences using DIF – FFT
algorithm
2. PROGRAM:
#include<stdio.h>
#include<math.h>
#define N 8
#define PI 3.14159
typedef struct
{
float real,imag;
}
complex;
main()
{
int i;
complex w[N];
complex x[8]={0,0.0,1,0.0,2,0.0,3,0.0,4,0.0,5,0.0,6,0.0,7,0.0};
complex temp1,temp2;
int j,k,upper_leg,lower_leg,leg_diff,index,step;
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<3;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;
}
}
printf("the fft of the given input sequence is \n");
for(i=0;i<8;i++)
{
printf("%f %f \n",(x[i]).real,(x[i]).imag);
}
}
3. OUTPUT:
4. RESULT:
Thus the program to compute N=8 – FFT of given sequences using DIF – FFT
algorithm has been done successfully.
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_RINTCTL = 0x00000000; // Not used
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)
{
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;
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_RMASK = 0xFFFFFFFF;
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);
}
#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;
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)
{
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_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
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);
}
#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_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 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_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);
}
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
}
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_RMASK = 0xFFFFFFFF;
MCASP0_RFMT = 0x00018078; // MSB 16bit, 0-delay, no
pad, CFGBus
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
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);
}
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
1. AIM: To design and implement a FIR- LP/HP Filter for given specification.
a. Procedure to Work on Code Composer Studio
To create the New Project
Project→ New CCS Project (Give name to project with location to save or use default
location)Select project type→ Executable
Device Family→C6000
Variant→C674xFloating-point DSP
Connection →Texas Instruments XDS100V2USB Emulator
Click on Empty Project then Finish
To create a Source file
File →New→ Source file (Save & give file name, Eg: sum.c).Click on Finish
Write the C-Program To build the program project →Build All
After Build Finished without errors, Now DSP kit is turned ON
Debug the Program after loading is done
Run the Program and verify the 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
}
}
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
}
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) */
temp += ( (int)h[1] * x[1]); /* B1/2 * x(n-1) */
temp += ( (int)h[1] * x[1]); /* B1/2 * x(n-1) */
temp += ( (int)h[2] * x[2]); /* B2 * x(n-2) */
temp -= ( (int)h[4] * y[1]); /* A1/2 * y(n-1) */
temp -= ( (int)h[4] * y[1]); /* A1/2 * y(n-1) */
temp -= ( (int)h[5] * y[2]); /* A2 * y(n-2) */
/* Divide temp by coefficients[A0] */
temp >>= 15;
if ( temp > 32767 )
{
temp = 32767;
}
else if ( temp < -32767)
{
temp = -32767;
}
y[0] = temp ;
/* Shuffle values along one place for next time */
y[2] = y[1]; /* y(n-2) = y(n-1) */
y[1] = y[0]; /* y(n-1) = y(n) */
x[2] = x[1]; /* x(n-2) = x(n-1) */
x[1] = x[0]; /* x(n-1) = x(n) */
/* temp is used as input next time through */
return (temp<<2);
}
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;
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)
{
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
1. AIM: To design and implement Analog- LP/HP Filter for given specification.
a. Procedure to Work on Code Composer Studio
To create the New Project
Project→ New CCS Project (Give name to project with location to save or use default
location)Select project type→ Executable
Device Family→C6000
Variant→C674xFloating-point DSP
Connection →Texas Instruments XDS100V2USB Emulator
Click on Empty Project then Finish
To create a Source file
File →New→ Source file (Save & give file name, Eg: sum.c).Click on Finish
Write the C-Program To build the program project →Build All
After Build Finished without errors, Now DSP kit is turned ON
Debug the Program after loading is done
Run the Program and verify the output
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
}
{
1455,1455,1455,32767,-23140,21735 /*LP 2500 */
} ;
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] */
temp = ( (int)h[0] * x[0]) ; /* B0 * x(n) */
temp += ( (int)h[1] * x[1]); /* B1/2 * x(n-1) */
temp += ( (int)h[1] * x[1]); /* B1/2 * x(n-1) */
temp += ( (int)h[2] * x[2]); /* B2 * x(n-2) */
temp -= ( (int)h[4] * y[1]); /* A1/2 * y(n-1) */
temp -= ( (int)h[4] * y[1]); /* A1/2 * y(n-1) */
temp -= ( (int)h[5] * y[2]); /* A2 * y(n-2) */
/* Divide temp by coefficients[A0] */
temp >>= 15;
if ( temp > 32767 )
{
temp = 32767;
}
else if ( temp < -32767)
{
temp = -32767;
}
y[0] = temp ;
/* Shuffle values along one place for next time */
}
}
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;
while( !(SPI_SPIFLG&0x200));
DSP6745_wait( 1000 );
}
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_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
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
PART- C
ADVANCED
EXPERIMENTS
VEMU INSTITUTE OF TECHNOLOGY, DEPT OF E.C.E Page
DIGITAL SIGNAL PROCESSINGLABORATORY III B.Tech II Sem
2. SOFTWARE REQUIRED:
4. 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')
5. OUTPUT:
6. RESULT:
Thus the MATLAB program to find sum of two signals has been done successfully
2. SOFTWARE REQUIRED:
PC and MATLAB software
3. PROCEDURE:
Open MATLAB Software
Open new M-file
Type the program
Save in current directory
Run the program
For the output see command window\ Figure window.
4. 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);
}
5. OUTPUT:
6. RESULT: Thus the C- program to compute power density spectrum of given one –
dimensional signal has been done successfully.