0% found this document useful (0 votes)
84 views

Program - Code Composer Studio (CCS)

The document describes a program that uses an infinite impulse response (IIR) filter to process audio signals from a codec. It includes code to: 1) Initialize the codec and define its configuration settings. 2) Continuously read input samples from the codec, process them through the IIR filter, and write the output back to the codec in a loop. 3) Define the IIR filter coefficients and IIR filtering function to process each input sample.

Uploaded by

syedat619
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

Program - Code Composer Studio (CCS)

The document describes a program that uses an infinite impulse response (IIR) filter to process audio signals from a codec. It includes code to: 1) Initialize the codec and define its configuration settings. 2) Continuously read input samples from the codec, process them through the IIR filter, and write the output back to the codec in a loop. 3) Define the IIR filter coefficients and IIR filtering function to process each input sample.

Uploaded by

syedat619
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Program Code composer Studio(CCS)

#include "IIRcfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
const signed int filter_Coeff[] =
{
//12730,-12730,12730,32767,-18324,21137 /*HP 2500 */
//312,312,312,32767,-27943,24367
/*LP 800 */
//1455,1455,1455,32767,-23140,21735 /*LP 2500 */
//9268,-9268,9268,32767,-7395,18367 /*HP 4000*/
7215,-7215,7215,32767,5039,6171,
/*HP 7000*/
};
/* Codec configuration settings */
DSK6713_AIC23_Config config = { \
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \
0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */
\
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */
\
0x0043, /* 7 DSK6713_AIC23_DIGIF
Digital audio interface format */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */
\
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};
/*
* main() - Main code routine, initializes BSL and generates tone
*/
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
int l_input, r_input, l_output, r_output;
/* Initialize the board support library, must be called first */
DSK6713_init();
/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0, &config);

DSK6713_AIC23_setFreq(hCodec, 3);
while(1)
{ /* Read a sample to the left channel */
while (!DSK6713_AIC23_read(hCodec, &l_input));
/* Read a sample to the right channel */
while (!DSK6713_AIC23_read(hCodec, &r_input));
l_output=IIR_FILTER(&filter_Coeff ,l_input);
r_output=l_output;
/* Send a sample to the left channel */
while (!DSK6713_AIC23_write(hCodec, l_output));
/* Send a sample to the right channel */
while (!DSK6713_AIC23_write(hCodec, r_output));
}
/* Close the codec */
DSK6713_AIC23_closeCodec(hCodec);
}
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);
}

Program: (Matlab)
RLS Program for echo cancellation
clear all
close all
hold off
N=2000;
inp = randn(N,1);
n = randn(N,1);
[b,a] = butter(2,0.25);
Gz = tf(b,a,-1);
sysorder = 10 ;
h=[0.097631 0.287310 0.335965 0.220981 0.096354 0.017183 -0.015917 -0.020735 0.014243 -0.006517 -0.001396 0.000856 0.001272 0.000914 0.000438 0.000108 0.000044 -0.00008 -0.000058 -0.000029];
h=h(1:sysorder);
y = lsim(Gz,inp);
n = n * std(y)/(10*std(n));
d = y + n;
totallength=size(d,1);
N=80 ;
lamda = 0.9995 ;
delta = 1e10 ;
P = delta * eye (sysorder ) ;
w = zeros ( sysorder , 1 ) ;
for n = sysorder : N

u = inp(n:-1:n-sysorder+1) ;
phi = u' * P ;
k = phi'/(lamda + phi * u );
y(n)=w' * u;
e(n) = d(n) - y(n) ;
w = w + k * e(n) ;
P = ( P - k * phi ) / lamda ;
Recordedw(1:sysorder,n)=w;
end
for n = N+1 : totallength
u = inp(n:-1:n-sysorder+1) ;
y(n) = w' * u ;
e(n) = d(n) - y(n) ;
end
hold on
plot(d)
plot(y,'r');
title('System output') ;
xlabel('Samples')
ylabel('True and estimated output')
figure
semilogy((abs(e))) ;
title('Error curve') ;
xlabel('Samples');
ylabel('Error value');
figure
plot(h, 'r+')
hold on
plot(w, '.')
legend('filter weights','Estimated filter weights');
title('Comparison of the filter weights and estimated weights') ;
figure
plot(Recordedw(1:sysorder,sysorder:N)');
title('Estimated weights convergence') ;
xlabel('Samples');
ylabel('Weights value');
axis([1 N-sysorder min(min(Recordedw(1:sysorder,sysorder:N)'))
max(max(Recordedw(1:sysorder,sysorder:N)')) ]);
hold off

Output of RLS Program

LMS Program for Noise Cancellation:


randn('state',sum(100*clock));
rand('state',sum(100*clock));
numpoints=5000;
numtaps=10;
Mu=0.01;
x=randn(numpoints,1)+i*randn(numpoints,1);
h=rand(numtaps,1);
h=h/max(h);
d=filter(h,1,x);

w=[];
y=[];
in=[];
e=[];
w=zeros(numtaps+1,1)+i*zeros(numtaps+1,1);
for n=numtaps+1:numpoints
in=x(n:-1:n-numtaps);
y(n)=w'*in;
e(n)=d(n)-y(n);
w=w+Mu*(real(e(n)*conj(in))-i*imag(real(e(n)*conj(in))));
end
figure(10);
semilogy(abs(e));
title(['LMS Adaptation Learning Curve Using Mu = ', num2str(Mu)]);
xlabel('Iteration Number');
ylabel('Output Estimation Error in dB');

Output for LMS:

You might also like