Professional Documents
Culture Documents
DSP Hardware
DSP Hardware
DSP Hardware
Experiment – 8
%Architecture of TMS320C6748
Digital Signal Processing BVRIT, Narsapur
Digital Signal Processing BVRIT, Narsapur
Experiment - 9
%Convolution%
Linear Convolution
AIM:
To perform linear convolution of two signals using Code Composer Studio (CCS).
#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);
printf("Enter values for i/p x(n):\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("Enter Values for i/p h(n) \n");
for(i=0;i<n; i++)
scanf("%d",&h[i]);
// padding of zeors
for(i=m;i<=m+n-1;i++)
x[i]=0;
for(i=n;i<=m+n-1;i++)
h[i]=0;
/* convolution operation */
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]);
}
Digital Signal Processing BVRIT, Narsapur
OUTPUT:
Console output:
enter value for m 5
enter value for n 5
Enter values for i/p
12345
Enter Values for h
12345
The Value of output y[0]=1
The Value of output y[1]=4
The Value of output y[2]=10
The Value of output y[3]=20
The Value of output y[4]=35
The Value of output y[5]=44
The Value of output y[6]=46
The Value of output y[7]=40
The Value of output y[8]=25
Digital Signal Processing BVRIT, Narsapur
Circular Convolution
}
printf("]\n");
if(f>s)
{
for(i=0;i<f;i++)
{
a[i]=c[i];
}
frst=f;
for(i=0;i<frst;i++)
{
pad[i]=d2[i];
}
}
else
{
for(i=0;i<s;i++)
{
a[i]=d2[i];
}
frst=s;
for(i=0;i<frst;i++)
{
pad[i]=c[i];
}
}
printf("\n Both the Matrix After padding : \n\t1st Matrix\t 2nd Matrix ");
for(i=0;i<frst;i++)
{
printf("\n\t %d\t\t ",c[i]);
printf("%d",d2[i]);
}
for(j=0;j<frst;j++)
{
last=frst-1;
frst_ele=a[0];
last_ele=a[last];
if(j>0)
{
for(k=0;k<frst;k++)
{
if(k>0 && k<frst)
Digital Signal Processing BVRIT, Narsapur
{
prev=k-1;
b[k]=a[prev];
final[k][j]=b[k];
}
else
{
b[0]=last_ele;
final[k][j]=b[k];
}
}
for(d=0;d<frst;d++)
{
a[d]=b[d];
}
}
else
{
for(k=0;k<frst;k++)
{
final[k][j]=a[k];
}
}
}
printf("\n\n ******* Final Matrix *****\n");
for(i=0;i<frst;i++)
{
for(j=0;j<frst;j++)
{
printf("\t%d",final[i][j]);
}
printf("\n");
}
printf("\n ******* Circular Convulated Matrix *****\n");
printf("\n[ ");
for(i=0;i<frst;i++)
{
sum=0;
for(j=0;j<frst;j++)
{
rslt=final[i][j]*pad[j];
Digital Signal Processing BVRIT, Narsapur
sum=sum+rslt;
}
result[j]=sum;
printf("%d\t",result[j]);
}
printf("]\n");
return 0;
}
OUTPUT:
Experiment - 10
FAST FOURIER TRANSFORM OF A GIVEN SEQUENCE
#include<math.h>
#define PTS 64
#define PI 3.14159265358979
typedef struct{float real,imag;} COMPLEX;
void FFT(COMPLEX*Y,int n);
float iobuffer[PTS];
float x1[PTS];
short i;
short buffercount=0;
short flag=0;
COMPLEX w[PTS];
COMPLEX samples[PTS];
main()
{
for(i=0;i<PTS;i++)
{
w[i].real=cos(2*PI*i/(PTS*2.0));
w[i].imag=-sin(2*PI*i/(PTS*2.0));
}
for(i=0;i<PTS;i++)
{
iobuffer[i]=sin(2*PI*10*i/64.0);
samples[i].real=0.0;
samples[i].imag=0.0;
}
for(i=0;i<PTS;i++)
{
samples[i].real=iobuffer[i];
}
for(i=0;i<PTS;i++)
samples[i].imag=0.0;
FFT(samples,PTS);
for(i=0;i<PTS;i++)
{
x1[i]=sqrt(samples[i].real*samples[i].real+ samples[i].imag*samples[i].imag);
}
}
//**FFT Function:
void FFT(COMPLEX*Y, int N)
{
COMPLEX temp1,temp2;
int i,j,k;
int upper_leg,lower_leg;
Digital Signal Processing BVRIT, Narsapur
int leg_diff;
int num_stages=0;
int index,step;
i=1;
do
{
num_stages+=1;
i=i*2;
}while(i!=N);
leg_diff=N/2;
step=(PTS*2)/N;
for(i=0;i<num_stages;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=(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]).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++)
{
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[j]).real=temp1.real;
(Y[j]).imag=temp1.imag;
}}
return;
}
Digital Signal Processing BVRIT, Narsapur
Result:
OUTPUT: FFT
Digital Signal Processing BVRIT, Narsapur
Experiment - 11
% Digital IIR Filter Design%
Aim: To design Infinite Impulse Response (IIR) filters and analyze their responses
C Program:
#include<stdio.h>
#include<math.h>
int i,w,wc,c,N;
float H[100];
float mul(float, int);
void main()
{
printf("\n enter order of filter ");
scanf("%d",&N);
printf("\n enter the cutoff freq ");
scanf("%d",& wc);
printf("\n enter the choice for IIR filter 1. LPF 2.HPF ");
scanf("%d",&c);
switch(c)
{
case 1:
for(w=0;w<100;w++)
{
H[w]=1/sqrt(1+mul((w/(float)wc),2*N));
printf("H[%d]=%f\n",w,H[w]);
}
break;
case 2:
for(w=0;w<=100;w++)
{
H[w]=1/sqrt(1+mul((float)wc/w,2*N));
printf("H[%d]=%f\n",w,H[w]);
}
break;
}
}
float mul(float a,int x)
{
for(i=0;i<x-1;i++)
a*=a;
return(a);
}
Digital Signal Processing BVRIT, Narsapur
CONSOLE OUTPUT:
[C674X_0]
enter order of filter 2
Start address: h
Magnitude Response
Phase Response
Digital Signal Processing BVRIT, Narsapur
Experiment - 12
% Digital FIR Filter Design%
Aim: To design Finite Impulse Response (FIR) filters and analyze their responses
C Program:
#include<stdio.h>
#include<math.h>
#define pi 3.1415
int n,N,c;
float wr[64],wt[64];
void main()
{
printf("\n enter no. of samples,N= :");
scanf("%d",&N);
printf("\n enter choice of window function\n 1.rect \n 2. triang\n c= :");
scanf("%d",&c);
printf("\n elements of window function are:");
switch(c)
{
case 1:
for(n=0;n<=N;n++)
{
wr[n]=1;
printf(" \n wr[%d]=%f",n,wr[n]);
}
break;
case 2:
for(n=0;n<=N-1;n++)
{
wt[n]=1-(2*(float)n/(N-1));
printf("\n wt[%d]=%f",n,wt[n]);
}
break;
}
}
Digital Signal Processing BVRIT, Narsapur
OUTPUT:
Magnitude Response
Phase Response