DSP Lab Manual DSK Technical Programming With C, MATLAB Programs 2008 B.Tech ECE IV-I JNTU Hyd V1.9
DSP Lab Manual DSK Technical Programming With C, MATLAB Programs 2008 B.Tech ECE IV-I JNTU Hyd V1.9
DSP Lab Manual DSK Technical Programming With C, MATLAB Programs 2008 B.Tech ECE IV-I JNTU Hyd V1.9
OF
LAB MANUAL
TH
B.TECH (ECE) IV YR IST SEM
Feature Use
Fast-Multiply accumulate Most DSP algorithms, including
filtering, transforms, etc. are
multiplication- intensive
Multiple – access memory Many data-intensive DSP operations
architecture require reading a program instruction
and multiple data items during each
instruction cycle for best performance
Specialized addressing modes Efficient handling of data arrays and
first-in, first-out buffers in memory
Specialized program control Efficient control of loops for many
iterative DSP algorithms. Fast interrupt
handling for frequent I/O operations.
On-chip peripherals and I/O On-chip peripherals like A/D converters
interfaces allow for small low cost system designs.
Similarly I/O interfaces tailored for
common peripherals allow clean
interfaces to off-chip I/O devices.
The C67xx DSP architecture is built around eight major 16-bit buses (four program/data
buses and four address buses):
_ The program bus (PB) carries the instruction code and immediate operands from
program memory.
_ Three data buses (CB, DB, and EB) interconnect to various elements, such as the CPU,
data address generation logic, program address generation logic, on-chip peripherals, and
data memory.
_ The CB and DB carry the operands that are read from data memory.
_ The EB carries the data to be written to memory.
_ Four address buses (PAB, CAB, DAB, and EAB) carry the addresses needed for
instruction execution.
The C67xx DSP can generate up to two data-memory addresses per cycle using the two
auxiliary register arithmetic units (ARAU0 and ARAU1). The PB can carry data operands
stored in program space (for instance, a coefficient table) to the multiplier and adder for
multiply/accumulate operations or to a destination in data space for data move instructions
(MVPD and READA). This capability, in conjunction with the feature of dual-operand
read, supports the execution of single-cycle, 3-operand instructions such as the FIRS
instruction. The C67xx DSP also has an on-chip bidirectional bus for accessing on-chip
peripherals. This bus is connected to DB and EB through the bus exchanger in the CPU
interface. Accesses that use this bus can require two or more cycles for reads and writes,
depending on the peripheral’s structure.
The CPU is common to all C67xE devices. The C67x CPU contains:
The C67x DSP performs 2s-complement arithmetic with a 40-bit arithmetic logic unit
(ALU) and two 40-bit accumulators (accumulators A and B). The ALU can also perform
Boolean operations. The ALU uses these inputs:
The ALU can also function as two 16-bit ALUs and perform two 16-bit operations
simultaneously.
2008 Private Engineering College, Affiliated to JNTU, Hyderabad 7/52
Fig 2 – 2 ALU UNIT
Accumulators
Accumulators A and B store the output from the ALU or the multiplier/adder block. They
can also provide a second input to the ALU; accumulator A can be an input to the
multiplier/adder. Each accumulator is divided into three parts:
_ Guard bits (bits 39–32)
_ High-order word (bits 31–16)
_ Low-order word (bits 15–0)
Instructions are provided for storing the guard bits, for storing the high- and the low-order
accumulator words in data memory, and for transferring 32-bit accumulator words in or
out of data memory. Also, either of the accumulators can be used as temporary storage for
the other.
Barrel Shifter
The C67x DSP barrel shifter has a 40-bit input connected to the accumulators or to data
memory (using CB or DB), and a 40-bit output connected to the ALU or to data memory
(using EB). The barrel shifter can produce a left shift of 0 to 31 bits and a right shift of 0
to 16 bits on the input data. The shift requirements are defined in the shift count field of
the instruction, the shift count field (ASM) of status register ST1, or in temporary register
T (when it is designated as a shift count register).The barrel shifter and the exponent
encoder normalize the values in an accumulator in a single cycle. The LSBs of the output
are filled with 0s, and the MSBs can be either zero filled or sign extended, depending on
These are the some of the important parts of the processor and you are instructed to go
through the detailed architecture once which helps you in developing the optimized code
for the required application.
1. Linear Convolution
AIM
To verify Linear Convolution.
EQUIPMENTS
THEORY
In this equation, x1(k), x2 (n-k) and y(n) represent the input to and output from the system
at time n. Here we could see that one of the input is shifted in time by a value everytime it
is multiplied with the other input signal. Linear Convolution is quite often used as a
method of implementing filters of various types.
ALGORITHM
Step 1 Declare three buffers namely Input buffer, Temporary Buffer, Output Buffer.
Step 2 Get the input from the CODEC, store it in Input buffer and transfer it to the first
location of the
Temporary buffer.
Step 3 Make the Temporary buffer to point to the last location.
Step 4 Multiply the temporary buffer with the coefficients in the data memory and
accumulate it with
the previous output.
Step 5 Store the output in the output buffer.
Step 6 Repeat the steps from 2 to 5.
PROGRAM
#include<stdio.h>
int x[15],h[15],y[15];
main()
{
int i,j,m,n;
printf("\n enter value for m");
scanf("%d",&m);
printf("\n enter value for n");
scanf("%d",&n);
2008 Private Engineering College, Affiliated to JNTU, Hyderabad 10/52
printf("Enter values for i/p\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("Enter Values for n \n");
for(i=0;i<n;i++)
scanf("%d",&h[i]);
for(i=m;i<=m+n-1;i++)
x[i]=0;
for(i=n;i<=m+n-1;i++)
h[i]=0;
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
{
y[i]=y[i]+(x[j]*h[i-j]);
}
}
for(i=0;i<m+n-1;i++)
printf("\n The Value of output y[%d]=%d",i,y[i]);
}
Result:
enter value for m4
EQUIPMENTS
THEORY
Circular convolution is another way of finding the convolution sum of two input signals. It
resembles the linear convolution, except that the sample values of one of the input signals
is folded and right shifted before the convolution sum is found. Also note that circular
convolution could also be found by taking the DFT of the two input signals and finding
the product of the two frequency domain signals. The Inverse DFT of the product would
give the output of the signal in the time domain which is the circular convolution output.
The two input signals could have been of varying sample lengths. But we take the DFT of
higher point, which ever signals levels to. For eg. If one of the signal is of length 256 and
the other spans 51 samples, then we could only take 256 point DFT. So the output of
IDFT would be containing 256 samples instead of 306 samples, which follows N1+N2 – 1
where N1 & N2 are the lengths 256 and 51 respectively of the two inputs. Thus the output
which should have been 306 samples long is fitted into 256 samples. The
256 points end up being a distorted version of the correct signal. This process is called
circular convolution.
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 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]);
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];
}
}
Model Graph:-
EQUIPMENTS
THEORY:
Correlation is measures of the degree to which two sequences are similar .There are two
types of Correlation 1. Cross correlation 2.Auto correlation
Cross Correlation:- given two real valued sequences x1(n) of finite energy , the cross
correlation of x1(n) and x2(n) is a sequence rxy (1) defined as
rxy( 1 )=
#include<stdio.h>
int m,n,X[30],RXY[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 secound sequence\n");
for(j=0;j<n;j++)
scanf("%d",&Y[j]);
for(i=n;i<m+n-1;i++)
X[i]=0;
for(i=m;i<n+m-1;i++)
Y[i]=0;
if(m>n)
a=m;
else
a=n
for(l=0;l<a;l++)
{
RXY[l]=0;
for(n=0;n<a;n++)
OUTPUT:
AIM
To find the Fast Fourier Transform for the realtime samples.
HARDWARE REQUIREMENTS
TMS320C6713 DSK.
USB Cable.
Power Cord
5V Adapter
1. THEORY
The Transform Domain Technique involves the transformation of the time domain
signal into a frequency domain one. The available methods of implementing the
transformation are
N −1 nk
− j 2π
x (k ) = ∑ x(n) W n
;0 < k < N − 1 (5)
n =0
PROGRAM:
#include<stdio.h>
#include<math.h>
#define pi 3.1415
#define PTS 64
float X[PTS];
main()
{
float xr[PTS],xi[PTS],k,n,N=PTS;
float XR[PTS],XI[PTS];
for(i=0;i<PTS-1;++)
{
xr[i]=sin(2*pi*10*i/64.0);
xi[i]=0;
}
for (k=0;k<N;k++)
{
Xr[k]=0;
Xi[k]=0;
for (n=0; <N; n++)
{
XR[k]+=(xr[n]*cos(2*pi*k*n/N))+(xi[n]*sin(2*pi*k*n/N));
XI[k]+=(xi[n]*sin(2*pi*k*n/N))-(xr[n]*cos(2*pi*k*n/N));
}
X[k]=sqrt((XR[k]*XR[k])+(XI[k]*XI[k]));
printf("%f\n",X[k]);
}
HARDWARE REQUIREMENTS
TMS320C6713 DSK.
USB Cable.
Power Cord
5V Adapter
THEORY
The Fast Fourier Transform is useful to map the time-domain sequence into a
continuous function of a frequency variable. The FFT of a sequence {x(n)} of length
N is given by a complex-valued sequence X(k).
M nk
− j 2π
X ( k ) = ∑ x ( n) e n
;0 < k < N − 1
k =0
The above equation is the mathematical representation of the DFT. As the number of
computations involved in transforming a N point time domain signal into its
corresponding frequency domain signal was found to be N2 complex multiplications,
an alternative algorithm involving lesser number of computations is opted.
When the sequence x(n) is divided into 2 sequences and the DFT performed
separately, the resulting number of computations would be N2/2
(i.e.)
N2 N2
2−1 2−1
x(k ) = ∑ x(2n) WN2 nk + ∑ x(2n + 1) WN( 2 n+1) k (6)
n =0 n =0
Consider x(2n) be the even sample sequences and x(2n+1) be the odd sample sequence
derived form x(n).
N2
2 −1
∑ x ( 2n)
n =0
WN2 nk
N2 N2 N2
= + = Computatio ns
4 4 2
N N
2 −1 k 2−1
= ∑ x(2n) WN2 nk + W ∑ x(2n + 1) WN( 2 nk ) (10)
N
n =0 n =0
Dividing the sequence x(2n) into further 2 odd and even sequences would reduce the
computations.
− j 2π
nk
W nk
N =e n
N N
K+ K+
W
N
2
= WN W
N
2
(11)
− j 2π − j 2π n
k n 2
=e n
e
− j 2π
k
= WNk e n
N
K+
=W
N
2
= WNk (−1)
N
K+
=W 2
= WNk (12)
N
N
2−1 K N
N
x(k + ) = ∑ x(2n) WN2 nk − W ∑ x (2n + 1) 2−1 WN( 2 nk ) (14)
2 n =0 N
The time burden created by this large number of computations limits the usefulness of
DFT in many applications. Tremendous efforts devoted to develop more efficient
ways of computing DFT resulted in the above explained Fast Fourier Transform
algorithm. This mathematical shortcut reduces the number of calculations the DFT
requires drastically. The above mentioned radix-2 decimation in time FFT is employed
for domain transformation.
Dividing the DFT into smaller DFTs is the basis of the FFT. A radix-2 FFT divides the
DFT into two smaller DFTs, each of which is divided into smaller DFTs and so on,
resulting in a combination of two-point DFTs. The Decimation -In-Time (DIT) FFT
divides the input (time) sequence into two groups, one of even samples and the other
of odd samples. N/2 point DFT are performed on the these sub-sequences and their
outputs are combined to form the N point DFT.
FIG. 3A.1
The above shown mathematical representation forms the basis of N point FFT and is
called the Butterfly Structure.
STAGE – III
PROGRAM: -
#include <math.h>
#define PTS 128 //# of points for FFT
#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n); //FFT prototype
float iobuffer[PTS]; //as input and output buffer
float x1[PTS],x[PTS]; //intermediate buffer
short i; //general purpose index variable
short buffercount = 0; //number of new samples in iobuffer
short flag = 0; //set to 1 by ISR when iobuffer full
float y[128];
COMPLEX w[PTS]; //twiddle constants stored in w
COMPLEX samples[PTS]; //primary working buffer
main()
{
float j,sum=0.0 ;
int n,k,i,a;
for (i = 0 ; i<PTS ; i++) // set up twiddle constants in w
{
w[i].real = cos(2*PI*i/(PTS*2.0)); //Re component of twiddle constants
w[i].imag =-sin(2*PI*i/(PTS*2.0)); /*Im component of twiddle constants*/
}
for(i=0,j=0;i<PTS;i++)
{ x[i] = sin(2*PI*5*i/PTS); // Signal x(Fs)=sin(2*pi*f*i/Fs);
samples[i].real=0.0;
samples[i].imag=0.0;
}
} //end of main
index = 0;
for (j = 0; j < leg_diff; j++)
{
for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff))
{
lower_leg = upper_leg+leg_diff;
temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real;
temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag;
temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real;
temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag;
(Y[lower_leg]).real = temp2.real*(w[index]).real
-temp2.imag*(w[index]).imag;
(Y[lower_leg]).imag = temp2.real*(w[index]).imag
+temp2.imag*(w[index]).real;
(Y[upper_leg]).real = temp1.real;
(Y[upper_leg]).imag = temp1.imag;
}
index += step;
}
leg_diff = leg_diff/2;
step *= 2;
}
j = 0;
for (i = 1; i < (N-1); i++) //bit reversal for resequencing data
{
k = N/2;
while (k <= j)
{
j = j - k;
k = k/2;
}
j = j + k;
if (i<j)
{
temp1.real = (Y[j]).real;
temp1.imag = (Y[j]).imag;
(Y[j]).real = (Y[i]).real;
(Y[j]).imag = (Y[i]).imag;
(Y[i]).real = temp1.real;
(Y[i]).imag = temp1.imag;
}
}
return;
}
6.FIR FILTER
2008 Private Engineering College, Affiliated to JNTU, Hyderabad 25/52
AIM: -
To design and implement a low pass FIR filter using windowing technique.
APPARATUS: -
1. TMS320C5416 DSK.
2. USB Cable.
3. Power Cord
4. 5V Adapter.
THEORY: -
A Finite Impulse Response (FIR) filter is a discrete linear time-invariant system whose
output is based on the weighted summation of a finite number of past inputs. An FIR
transversal filter structure can be obtained directly from the equation for discrete-time
convolution.
N −1
y ( n) = ∑ x ( k ) h( n − k ) 0 < n < N − 1 (1)
k =0
In this equation, x(k) and y(n) represent the input to and output from the filter at time
n. h(n-k) is the transversal filter coefficients at time n. These coefficients are
generated by using FDS (Filter Design Software or Digital filter design package).
Windows:
#include <stdio.h>
#include <math.h>
#define pi 3.1415
int N,n;
float h[64];
void main()
{
printf("enter the number of samples\n");
scanf("%d",&N);
for(n=0;n<(N-1);n++)
{
h[n]=0.0;
h[n]= 0.42+0.5*cos(2*pi*n/(N-1))+0.08*cos(4*pi*n/(N-1));
printf("h[%d]=%f\n",n,h[n]);
}
RESULT:
#include <stdio.h>
#include <math.h>
#define pi 3.1415
int N,n;
float h[64];
void main()
{
printf("enter the number of samples\n");
scanf("%d",&N);
for(n=0;n<(N-1);n++)
{
h[n]=0.0;
h[n]=1-(4*n/(float)(n-1)) ;
printf("h[%d]=%f\n",n,h[n]);
}
AIM: -
To design and implement a low pass IIR filter using windowing technique.
APPARATUS: -
1. TMS320C5416 DSK.
2. USB Cable.
3. Power Cord
4. 5V Adapter.
THEORY: -
The IIR filter can realize both the poles and zeroes of a system because it has a
rational transfer function, described by polynomials in z in both the numerator and the
denominator:
M
∑b
k =0
k z −k
H ( z) N (2)
∑a
k =1
k Z −k
LPF:
#include<stdio.h>
#include<math.h>
#define pi 3.1415
float Xmod[64],Xr[64],Xi[64];
float xr[64],xi[64],h[100],y[64];
int n,k,i,N,w,wc;
void main()
{
for(k=0;k<=63;k++)
{
xr[k]=sin((2*pi*10*k)/64)+sin((2*pi*50*k)/64);
xi[k]=0.0;
}
for(k=0;k<=63;k++)
{
Xr[k]=0;
Xi[k]=0;
2008 Private Engineering College, Affiliated to JNTU, Hyderabad 29/52
for(n=0;n<=63;n++)
{
Xr[k]+=xr[n]*cos((2*pi*k*n)/64.0)+xi[n]*sin((2*pi*k*n)/64.0);
Xi[k]+=xi[n]*cos((2*pi*k*n)/64.0)-xr[n]*sin((2*pi*k*n)/64.0);
}
Xmod[k]=sqrt(Xr[k]*Xr[k]+Xi[k]*Xi[k]);
}
printf("enter the order of the filter\n");
scanf("%d",&w);
printf("enter the cutoff frequency\n");
scanf("%d",&wc);
for(w=0;w<100;w++)
{
h[w]=1/sqrt(1+pow(w/(float)wc,2*N));
printf("h[%d]=%f\n",w,h[w]);
}
for(k=0;k<=63;k++)
{
y[k]=Xmod[k]*h[k];
printf("y[%d]=%f\n",k,y[k]);
}}
PROGRAM: -
#include<stdio.h>
#include<math.h>
#define pi 3.1415
float Xmod[64],Xr[64],Xi[64];
float xr[64],xi[64],h[100],y[64];
int n,k,i,N,w,wc;
void main()
{
for(k=0;k<=63;k++)
{
xr[k]=sin((2*pi*10*k)/64)+sin((2*pi*50*k)/64);
xi[k]=0.0;
}
for(k=0;k<=63;k++)
{
Xr[k]=0;
Xi[k]=0;
for(n=0;n<=63;n++)
Xr[k]+=xr[n]*cos((2*pi*k*n)/64.0)+xi[n]*sin((2*pi*k*n)/64.0);
Xi[k]+=xi[n]*cos((2*pi*k*n)/64.0)-xr[n]*sin((2*pi*k*n)/64.0);
}
Xmod[k]=sqrt(Xr[k]*Xr[k]+Xi[k]*Xi[k]);
}
printf("enter the order of the filter\n");
scanf("%d",&w);
printf("enter the cutoff frequency\n");
scanf("%d",&wc);
for(w=0;w<100;w++)
{
h[w]=1/sqrt(1+pow(wc/(float)w,2*N));
printf("h[%d]=%f\n",w,h[w]);
}
for(k=0;k<=63;k++)
{
y[k]=Xmod[k]*h[k];
printf("y[%d]=%f\n",k,y[k]);
}}
RESULT: -
Thus the IIR Low pass filter with cut off frequency 12Hz has been designed.
APPARATUS: -
1. TMS320C6713 DSK.
2. USB Cable.
3. Power Cord
4. 5V Adapter.
PROGRAM: -
#include <math.h>
#define PTS 128 //# of points for FFT
#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n); //FFT prototype
float iobuffer[PTS]; //as input and output buffer
float x1[PTS],x[PTS]; //intermediate buffer
short i; //general purpose index variable
short buffercount = 0; //number of new samples in iobuffer
short flag = 0; //set to 1 by ISR when iobuffer full
float y[128];
COMPLEX w[PTS]; //twiddle constants stored in w
COMPLEX samples[PTS]; //primary working buffer
main()
{
float j,sum=0.0 ;
int n,k,i,a;
for (i = 0 ; i<PTS ; i++) // set up twiddle constants in w
{
w[i].real = cos(2*PI*i/(PTS*2.0)); //Re component of twiddle constants
w[i].imag =-sin(2*PI*i/(PTS*2.0)); /*Im component of twiddle constants*/
}
for(i=0,j=0;i<PTS;i++)
{ x[i] = sin(2*PI*5*i/PTS); // Signal x(Fs)=sin(2*pi*f*i/Fs);
samples[i].real=0.0;
samples[i].imag=0.0;
}
for(n=0;n<PTS;n++)
{
sum=0;
for(k=0;k<PTS-n;k++)
{
sum=sum+(x[k]*x[n+k]); // Auto Correlation R(t)
}
iobuffer[n] = sum;
}
} //end of main
The term offline processing indicates that the programs which you are designing are like
simulation i.e. you are not using the real time inputs and outputs also you are seeing in the
processor registers or memory only.
1. ADDITION
Program: -
.include “5416_IV.asm”
.data
.word 0003h, 0004h // input numbers //
.text
.include “intvect.asm”
Result: - The result of addition operation can be recorded from the memory location.
Program: -
.include “5416_IV.asm”
.data
.word 0005h, 0002h // input numbers //
.text
.include “intvect.asm”
Result: - The result of multiplication operation can be recorded from the memory
location.
Aim: - To perform left shift and right shift operation on a number residing in memory.
Program: -
.include “5416_IV.asm”
.data
.word 0003h, // input number //
.text
.include “intvect.asm”
Result: - Shifting the number left by one bit is equivalent to multiplying number by 2
Shifting the number left by one bit is equivalent to dividing number by 2
Program: -
.include “5416_IV.asm”
.data
.word 0003h,0007h // input numbers //
.text
.include “intvect.asm”
Program: -
.include “5416_IV.asm”
.data
.word 1h,2h,3h,4h,5h // array of numbers //
.text
.include “intvect.asm”
1. SAMPLING
AIM: -
To study the concept of sampling continuous signal with a sampling frequency of
48KHz and reconstruct the same.
APPARATUS: -
1. TMS320C5416 DSK.
2. USB Cable.
3. Power Cord
4. 5V Adapter.
THEORY: -
Sampling is a process by which a continuous-time signal is converted into a discrete-
time signal.
Let x(t) be a continuous time varying signal. The signal x(t) is sampled at regular
interval of time with sampling period T. The sampled signal x(nT) is given by
x(nT) = x(t) | t = nT = x(nT), -∞ < n < ∞
The continuous time signal x(t) is multiplied by the sampling function s(t) which is a
series of impulses. The resultant signal is a discrete time signal x(n).
x(n) = x(t) s(t) | t = nT, -∞ < n < ∞
x(T) x(nT)
T T
T 3T 5T 7T 9T 11T 13T 15T
Continuous Time Signal
nT Discrete Time Signal
nT
PROGRAM: -
;Sampling program
;Starting address : 1000h
;DSPIK output : 1600h
.include "5416_IV.asm"
.data
2008 Private Engineering College, Affiliated to JNTU, Hyderabad 42/52
.text
SSBX INTM
STM SPCR1, McBSP0_SPSA ;SPCR1 reset
STM #0090h,McBSP0_SPSD
NOP
NOP
STM SPCR1,McBSP0_SPSA
STM #0091h,McBSP0_SPSD ;Take 'em out of reset
NOP
NOP
STM SPCR2,McBSP0_SPSA
STM #00A1h,McBSP0_SPSD
;--------------------------McBSP2 Initializations------------------------------
NOP
NOP
STM SPCR1,McBSP2_SPSA
STM #0091h,McBSP2_SPSD ;Take 'em out of reset
NOP
NOP
STM SPCR2,McBSP2_SPSA
STM #00A1h,McBSP2_SPSD
RSBX INTM
LD #02Fh,0,A
STLM A,IMR
STM #0h,McBSP0_DXR1
STM #0h,McBSP0_DXR2
STM #0007h,GPIOCR
STM #0003h,GPIOSR
STM #SPCR2,McBSP2_SPSA
STM #00E1h,McBSP2_SPSD ;Mclk
NOP
STM #0007h,GPIOSR
STM #SPCR2,McBSP0_SPSA
STM #00E1h,McBSP0_SPSD ;Sclk & Fs
;----------------------------------------------------------------------------
STM #128,BK
STM #1600h,AR1
SSBX SXM
WAIT NOP
NOP
NOP
B WAIT
RESULT: -
Thus the continuous time signal is sampled at 48 KHz and the original signal is
reconstructed.
PROGRAM: -
A= [ 1 2 3; 4 5 6; 7 8 9 ];
B= [ 2 3 4; 5 4 7; 1 1 1 ];
C= A * B
D= A’
D1=D+2
E= INV (A)
F= A(3,1:3)
G= A(1:3;1 )
H= G.*G
SUM (H)
PROGRAM: -
Fs = 1000;
T = 1/ Fs;
t = 0:T:1;
y = sin ( 2 * pi * 200 * t ); // generates sine wave of 200Hz //
plot(y)
z = fft(y,1024); // gets 1024 point fft for y //
N = ( 0 :1023 )’ * Fs / 1024;
z1 = abs(z);
plot( N, z1)
title( ‘ FFT Plot ‘ )
z2 = angle (z);
plot( N, z2 )
title( ‘ Phase Plot ‘)
THEORY: - If input is given to any system, output from the system is nothing
but convolution of input time signal and the system impulse response.
Convolution in time domain is same as multiplication in frequency domain.
Correlation is measurement of similarity. Cross correlation gives the similarity
between two different signals whereas autocorrelation gives the similarity of
the signal when the same signal was delayed. Fourier transform of
autocorrelation is power spectral density of the signal (PSD)
PROGRAM: -
x = [ 1 1 -1 1 -1 -1 ];
h = [ -1 -1 1 -1 -1 -1 ];
y = conv( x, h )
cr = xcorr ( x , h )
plot ( cr )
title ( ‘ Plot of Cross correlation ‘ )
ylabel( ‘ Magnitude ‘ )
xlabel( ‘ Lag ‘)
ar = xcorr(x)
plot ( ar )
THEORY: - Filter with coefficients are given. The frequency – magnitude plot
gives the frequency response.
PROGRAM: -
THEORY: - FIR – filter is a finite impulse response filter. Order of the filter
should be specified. Infinite response is truncated to get finite impulse
response. placing a window of finite length does this. Types of windows
available are Rectangular, Barlett, Hamming, Hanning, Blackmann window
etc. This FIR filter is an all zero filter.
PROGRAM: -
n = 20;
fp = 200;
fq = 300;
fs = 1000;
fn = 2 * fp / fs;
window = Blackman ( n+1 );
b= fir1 ( n, fn , window ) // low pass filter //
[ h w ] = freqz( b, 1, 128 );
plot( w/pi , abs(h) )
PROGRAM: -
fs = 1000;
wpn = 2 * wp / fs;
wqn = 2 * wq / fs;
[ n wn ] = buttord( wpn, wqn, rp, sp )
[ b a ] = butter( n, wn )
[ h w ] = freqz( b, a, 128);
plot( (w/pi) * ( fs/2 ), abs(h) )
PROGRAM: -
wp = 200;
wq = 300;
rp = 2;
sp = 40;
fs = 1000;
wpn = 2 * wp / fs;
wqn = 2 *wq / fs ;
[ n wn ] = cheb1ord(wpn, wqn, rp, sp )
[ b a ] =cheby1(n, rp, wn );
[ h w ] = freqz(b, a, 128 );
plot( w/pi, abs(h) )