DSP Manual PDF DD
DSP Manual PDF DD
MATLAB :
The name MATLAB stands for matrix laboratory. MATLAB was originally written
to provide easy access to matrix software developed by the LINPACK and EISPACK
projects. Today, MATLAB engines incorporate the LAPACK and BLAS libraries,
embedding the state of the art in software for matrix computation.
MATLAB has evolved over a period of years with input from many users. In
university environments, it is the standard instructional tool for introductory and
advanced courses in mathematics, engineering, and science. In industry, MATLAB is the
tool of choice for high-productivity research, development, and analysis.
Aim:
Determination of Power Spectrum of a given signal.
Software:
MATLAB
Theory:
The power spectrum describes the distribution of signal power over a frequency
spectrum. The most common way of generating a power spectrum is by using a discrete
Fourier transform, but other techniques such as the maximum entropy method can also be
used. The power spectrum can also be defined as the Fourier transform of auto correlation
function.
Algorithm:
Flow Chart:
PROGRAM:
Clc;
clear all;
close all;
N=1024;
fs=8000;
f=input('enter the frequency[1 to 5000]:');
n=0:N-1;
x=sin(2*pi*(f/fs)*n)
pxx=spectrum(x,N);
specplot(pxx,fs);
grid on
xlabel('freq(hz)');
ylabel('magnitude(db)');
title('power spectrum of x(n)');
INPUT:
Enter the frequency [1 to 5000]: 3000
Output Waveform:
RESULT:
EXP.NO: 2 IMPLEMENTATION OF LP FIR FILTER
AIM:
To implement LP FIR filter for a given sequence.
Software:
MATLAB
THEORY:
FIR filters are digital filters with finite impulse response. They are also
knownas non-recursive digital filters as they do not have the feedback.
Firstly, there is no feedback loop in the structure of an FIR filter. Due to not
having a feedback loop, an FIR filter is inherently stable. Meanwhile, for an IIR
filter, we need to check the stability.
An FIR filter is designed by finding the coefficients and filter order that meet
certain specifications, which can be in the time-domain (e.g. a matched filter) and/or the
frequency domain (most common). Matched filters perform a cross-correlation between
the input signal and a known pulse-shape. The FIR convolution is a cross-correlation
between the input signal and a time-reversed copy of the impulse-response. Therefore, the
matched-filter's impulse response is "designed" by sampling the known pulse-shape and
using those samples in reverse order as the coefficients of the filter.
When a particular frequency response is desired, several different design methods are
common:
FIR1(N,Wn,blackman
Algorithm:
Step I : Enter the pass band frequency (fp) and stop band frequency (fq).
Step II : Get the sampling frequency (fs), length of window (n).
Step III : Calculate the cut off frequency, fn
Step IV : Use boxcar, hamming, blackman Commands to design window.
Step V : Design filter by using above parameters.
Step VI : Find frequency response of the filter using matlab command freqz.
Step VII : Plot the magnitude response and phase response of the filter.
Flow Chart:
PROGRAM:
clc;
clear all;
close all;
n=20;
fp=200;
fq=300;
fs=1000;
fn=2*fp/fs;
window=blackman(n+1);
b=fir1(n,fn,window);
[H W]=freqz(b,1,128);
subplot(2,1,1);
plot(W/pi,abs(H));
title('magnitude response of lpf');
ylabel('gain in db ----- >');
xlabel('normalized frequency ---- >')
subplot(2,1,2);
plot(W/pi,angle(H));
title('phase response of lpf');
ylabel('angle ---->');
xlabel('normalized frequency ---- >');
RESULT:
EXP. NO: 3 IMPLEMENTATION OF HP FIR FILTER
Algorithm:
Step I : Enter the pass band frequency (fp) and stop band frequency (fq).
Step II : Get the sampling frequency (fs), length of window (n).
Step III : Calculate cut off frequency
Step IV : Use boxcar, hamming, Blackman Commands to design window.
Step V : Design filter by using above parameters.
Step VI : Find frequency response of the filter using matlab command freqz.
Step VII : Plot the magnitude response and phase response of the filter.
Flow Chart:
PROGRAM:
clc;
clear all;
close all;
n=20;
fp=300;
fq=200;
fs=1000;
fn=2*fp/fs;
window=blackman(n+1);
b=fir1(n,fn,'high',window);
[H W]=freqz(b,1,128);
subplot(2,1,1);
plot(W/pi,abs(H));
title('mag res of lpf');
ylabel('gain in db ----- >');
xlabel('normalized frequency ---- >');
subplot(2,1,2);
plot(W/pi,angle(H));
title('phase res of lpf');
ylabel('angle ---->');
xlabel('normalized frequency ---- >');
Output Waveforms:
RESULT:
EXPNO:4 IMPLEMENTATION OF LP IIR FILTER
There is one problem known as a potential instability that is typical of IIR filters only.
FIR filters do not have such a problem as they do not have the feedback. For this reason,
it is always necessary to check after the design process whether the resulting IIR filter is
stable or not.
For the given specifications to Design a digital IIR filter, first we need to design
analog filter (Butterworth or chebyshev). The resultant analog filter is transformed to
digital filter by using either “Bilinear transformation or Impulse Invariant
transformation”.
Algorithm:
Step I : Enter the pass band ripple (rp) and stop band ripple (rs).
Step II : Enter the pass band frequency (wp) and stop band frequency (ws).
Step III : Get the sampling frequency (fs).
Step IV : Calculate normalized pass band frequency, and normalized stop band
frequency w1 and w2 respectively. w1 = 2 * wp /fs w2 = 2 * ws /fs
Step V : Make use of the following function to calculate order of filter
Butterworth filter order
[n,wn]=buttord(w1,w2,rp,rs )
Chebyshev filter order
[n,wn]=cheb1ord(w1,w2,rp,rs)
Step VI : Design an nth order digital low pass Butterworth or Chebyshev filter
using the following statements.
Butterworth filter
[b, a]=butter (n, wn)
Chebyshev filter
[b,a]=cheby1 (n, 0.5, wn)
Step VII : Find the digital frequency response of the filter by using ‘freqz( )’
function
Step VIII : Calculate the magnitude of the frequency response in decibels (dB)
mag=20*log10 (abs (H))
Step IX : Plot the magnitude response [magnitude in dB Vs normalized frequency]
Step X : Calculate the phase response using angle (H)
Step XI : Plot the phase response [phase in radians Vs normalized frequency (Hz)].
Flow Chart:
PROGRAM:
clc;
clear all;
close all;
disp('enter the IIR filter design specifications');
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]=buttord(w1,w2,rp,rs,'s');
disp('Frequency response of IIR LPF is:');
[b,a]=butter(n,wn,'low','s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure,subplot(2,1,1);plot(om/pi,m);
title('magnitude response of IIR filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
subplot(2,1,2);plot(om/pi,an);
title('phase response of IIR filter is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');
INPUT:
enter the IIR filter design specifications
enter the passband ripple:15
enter the stopband ripple:60
enter the passband freq:1500
enter the stopband freq:3000
enter the sampling freq:7000
Output waveforms:
RESULT:
EXP. NO: 5 IMPLEMENTATION OF HP IIR FILTER
Algorithm:
Step I : Enter the pass band ripple (rp) and stop band ripple (rs).
Step II : the pass band frequency (wp) and stop band frequency (ws).
Step III : Get the sampling frequency (fs).
Step IV : Calculate normalized pass band frequency, and normalized stop band
frequency w1 and w2 respectively. w1 = 2 * wp /fs w2 = 2 * ws /fs
PROGRAM:
clc;
clear all;
close all;
disp('enter the IIR filter design specifications');
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]=buttord(w1,w2,rp,rs,'s');
disp('Frequency response of IIR HPF is:');
[b,a]=butter(n,wn,'high','s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure,subplot(2,1,1);plot(om/pi,m);
title('magnitude response of IIR filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
subplot(2,1,2);plot(om/pi,an);
title('phase response of IIR filter is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');
INPUT:
enter the IIR filter design specifications
enter the passband ripple15
enter the stopband ripple60
enter the passband freq1500
enter the stopband freq3000
enter the sampling freq7000
Output Waveforms:
RESULT:
EXP.NO: 6 LINEAR CONVOLUTION OF TWO SEQUENCES
Discrete Convolution
y(n)=x(n)∗h(n)
Algorithm:
PROGRAM:
clc;
clear all;
close all;
x1=input('Enter the first sequence x1(n) = ');
x2=input('Enter the second sequence x2(n) = ');
L=length(x1);
M=length(x2);
N=L+M-1;
yn=conv(x1,x2);
disp(‘The values of yn are= ‘);
disp(yn);
n1=0:L-1;
subplot(311);
stem(n1,x1);
grid on;
xlabel('n1--->');
ylabel('amplitude--->');
title('First sequence');
n2=0:M-1;
subplot(312);
stem(n2,x2);
grid on;
xlabel('n2--->');
ylabel('amplitude--->');
title('Second sequence');
n3=0:N-1;
subplot(313); stem(n3,yn);
grid on; xlabel('n3--->');
ylabel('amplitude--->'); title('Convolved
output');
Output:
Enter the first sequence x1(n) = [1 2 3 4 5]
Enter the second sequence x2(n) = [5 8 3 5 4 6]The values of
yn are=
5 18 34 55 80 81 59 59 44 30
OUTPUT WAVEFORMS:
RESULT:
EXP.NO: 7 ANALYSIS OF FINITE WORD-LENGTH EFFECTS
% Program
% Coefficient Quantization Effects on Cascade
% Realization of an IIR Transfer Function
clf;
[z,p,k] = ellip(6,0.05,60,0.4);
[b,a] = zp2tf(z,p,k);
[g,w] = gain(b,a);
sos = zp2sos(z,p,k);
sosq = a2dT(sos,6);
R1 = sosq(1,:);R2 = sosq(2,:);R3 = sosq(3,:);
b1 = conv(R1(1:3),R2(1:3));bq = conv(R3(1:3),b1);
a1 = conv(R1(4:6),R2(4:6));aq = conv(R3(4:6),a1);
[gq,w] = gain(bq,aq);
plot(w/pi,g,’b’, w/pi,gq,’r--’);
axis([0 1 -80 1]);grid
xlabel(’\omega /\pi’);ylabel(’Gain, dB’);
title(’original - solid line; quantized - dashed line’);
pause
zplane(b,a);
hold on;
pzplot(bq,aq);
title(’Original pole-zero locations: x, o; New pole-zero locations: +, *’)
The above two programs can be modified easily to investigate the multiplier coefficient
effects on an FIR transfer function, as illustrated by Program P9 3 given below for the
direct-form realization.
% Program
% Coefficient Quantization Effects on Direct Form
% Realization of an FIR Transfer Function
%
clf;
f = [0 0.4 0.45 1];
m = [1 1 0 0];
b = firpm(19, f, m);
[g,w] = gain(b,1);
bq = a2dT(b,5);
[gq,w] = gain(bq, 1);
plot(w/pi,g,’b-’,w/pi,gq,’r--’);
\axis([0 1 -60 10]);grid
xlabel(’\omega /\pi’); ylabel(’Gain, dB’);
legend(’original’, ’quantized’);
pause zplane(b);
hold on
pzplot(bq);
hold off
title(’Original pole-zero locations: x, o; New pole-zero locations: +, *’)
to investigate the propagation of input quantization-noise to the output of a causal, stable LTI digital filter,
the function noisepwr1 given below can be employed
for m = 1:R,
integral = r(k)*conj(r(m))/(1-p(k)*conj(p(m)));
nvar = nvar + integral;
end
end
disp(’Output Noise Variance = ’);disp(real(nvar))}
EXP.NO:8 CONSTRUCTION OF SIGNALS
AIM:
APPARATUS REQUIRED:
System with MATLAB 7.0.
ALGORITHM:
1. Get the number of samples.
2. Generate the unit impulse, unit step using ‘ones’, ‘zeros’ matrix
command.
3. Generate ramp, sine, cosine and exponential signals using corresponding
general formula.
4. Plot the graph.
PROGRAM:
% 1. UNIT IMPULSE SIGNAL
clc;
clear all;
close all;
N=input('Number of Samples');
n=-N:1:N
x=[zeros(1,N) 1 zeros(1,N)]
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Impulse Response'
% 2. UNIT STEP SIGNAL
clc;
clear all;
close all;
N=input('Number of Samples = ');
n=-N:1:N
x=[zeros(1,N) 1 ones(1,N)]
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Unit Step
Response');
% 6. COSINE SIGNAL
clc;
clear all;
close all;
disp('COSINE SIGNAL');
N=input('Number of Samples = ');
n=0:.1:N
x=cos(n)
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Cosine Signal');
% 7. SINE SIGNAL
clc;
clear all;
close all;
disp('SINE SIGNAL');
N=input('Number of Samples = ');
n=0:.1:N
x=sin(n)
stem(n,x);
xlabel('Time'); ylabel('Amplitude');title('sine Signal');
RESULT:
EXP.NO: 9
RECONSTRUCT OF SIGNAL FROM SAMPLES AND STUDY
THE EFFECT OF ALAISING
AIM:
To reconstruct the signals from samples.
MATLAB PROGRAM:
%% Parameters
F = 30; % frequency of signal [Hz]
Fs = 2*F; % sampling rate [Hz]
Ts = 1/Fs; % sampling period [sec]
%progress display
xr_progress=zeros(size(tc)); %initialization
for n = 0:N-1
clf;hold on;grid on;
current_sinc=xd(n+1)*sinc_train(n+1,:);
stem(td(1:n+1),xd(1:n+1),'k','linewidth',2)
plot(tc,xd(1:n+1)'.*sinc_train(1:n+1,:))
xr_progress=xr_progress+current_sinc;
plot(tc,xr_progress,'r','linewidth',2)
xlabel('Time [sec]')
ylabel('Amplitude')
title(['Step ',num2str(n+1),' (Having ',num2str(n+1),' Sincs)'])
sleep(5)
end
RESULT:
EXP.NO: 10
MATLAB PROGRAM:
downsample
upsample¶
decimate
import numpy
import pylab
from sp import multirate
t = numpy.arange(0, 1, 0.00025)
x = numpy.sin(2*numpy.pi*30*t) + numpy.sin(2*numpy.pi*60*t)
y = multirate.decimate(x,4)
pylab.figure()
pylab.subplot(2, 1, 1)
pylab.title('Original Signal')
pylab.stem(numpy.arange(len(x[0:120])), x[0:120])
pylab.subplot(2, 1, 2)
pylab.title('Decimated Signal')
pylab.stem(numpy.arange(len(y[0:30])), y[0:30])
pylab.show()
import numpy
import pylab
from sp import multirate
t = numpy.arange(0, 1, 0.001)
x = numpy.sin(2*numpy.pi*30*t) + numpy.sin(2*numpy.pi*60*t)
y = interp(x,4)
pylab.figure()
pylab.subplot(2, 1, 1)
pylab.title('Original Signal')
pylab.stem(numpy.arange(len(x[0:30])), x[0:30])
pylab.subplot(2, 1, 2)
pylab.title('Interpolated Signal')
pylab.stem(numpy.arange(len(y[0:120])), y[0:120])
pylab.show()
import numpy
import pylab
from sp import multirate
L = 147.0
M = 160.0
N = 24.0*L
h = signal.firwin(N-1, 1/M, window=('kaiser', 7.8562))
h = L*h
Fs = 48000.0
n = numpy.arange(0, 10239)
x = numpy.sin(2*numpy.pi*1000/Fs*n)
y = multirate.upfirdn(x, h, L, M)
pylab.figure()
pylab.stem(n[1:49]/Fs, x[1:49])
pylab.stem(n[1:45]/(Fs*L/M), y[13:57], 'r', markerfmt='ro',)
pylab.xlabel('Time (sec)')
pylab.ylabel('Signal value')
pylab.show()
AIM:-
To obtain stability analysis of a system using bode plot, root locus, and pole-zero
gain representation.
THEORY:-
Root locus analysis is a graphical method for examining how the roots of a system
change with variation of a certain system parameter, commonly a gain within a
feedback system. This is a technique used as a stability criterion in the field of classical
control theory developed by Walter R. Evans which can determine stability of the
system. The root locus plots the poles of the closed loop transfer function in the
complex s-plane as a function of a gain parameter. The root locus of a feedback system
is the graphical representation in the complex s-plane of the possible locations of its
closed-loop poles for varying values of a certain system parameter. The points that are
part of the root locus satisfy the angle condition. The value of the parameter for a
certain point of the root locus can be obtained using the magnitude condition. Bode
plot is the graphical tool for drawing the frequency response of a system. It is
represented by two separate plots, one is the magnitude vs frequency and the other one
is phase vs frequency.The magnitude is expressed in dB and the frequency is generally
plotted in log scale. One of the advantages of the Bode plot in s- domain is that the
magnitude curve can be approximated by straight lines which allow the sketching of
the magnitude plot without exact computation. A pole–zero plots is a graphical
representation of a rational transfer function in the complex plane which helps to
convey certain properties of the system such as: Stability, Causal system / anticausal
system, Region of convergence (ROC), Minimum phase / non minimum
phase. A pole zero plot shows the location in the complex plane of the poles and
zeros of the transfer function of a dynamic system, such as a controller, compensator,
sensor, equalizer, filter, or communications channel. By convention, the poles of the
system are indicated in the plot by an X while the zeros are indicated by a circle or O.
A pole-zero plots can represent either a continuous-time (CT) or a discrete-time (DT)
system. For a CT system, the plane in which the poles and zeros appear is the s plane
of the Laplace transform. In this context, the parameter s represents the complex
angular frequency, which is the domain of the CT transfer function. For a DT system,
the plane is the z plane, where z represents the domain of the Z-transform.
Steps:-
3. Find Gain Margin, Phase Margin, Gain Cross over Frequency, Phase Cross over
Frequency, Resonant Peak, Resonant Frequency, Bandwidth
Use MATLAB Help to familiarise basic functions: clc, clear all, close all, input,
figure, rlocus, title, grid, logspace, title, grid, bode, margin, tf(num,den), pzmap(g).
MATLAB CODE:
Bode plot
h = bodeplot(sys)
h = bodeplot(sys1,sys2,...,sysN)
h = bodeplot(sys1,LineSpec1,...,sysN,LineSpecN)
h = bodeplot(AX,___)
h = bodeplot(___,plotoptions)
h = bodeplot(___,w)
rng("default")
sys = rss(5);
h = bodeplot(sys);
setoptions(h,'FreqUnits','Hz','PhaseVisible','off');
p = bodeoptions('cstprefs');
p.FreqUnits = 'Hz';
p.PhaseVisible = 'off';
bodeplot(sys,p);
opts = bodeoptions;
opts.Title.FontSize = 15;
opts.Title.Color = [1 0 0];
opts.FreqUnits = 'Hz';
bodeplot(tf(1,[1,1]),opts);
J = [8 -3 -3; -3 8 -3; -3 -3 8];
F = 0.2*eye(3);
A = -J\F;
B = inv(J);
C = eye(3);
D = 0;
sys_mimo = ss(A,B,C,D);
size(sys_mimo)
h = bodeplot(sys_mimo);
p = getoptions(h)
Root Locus:
rlocus(sys)
rlocus(sys1,sys2,...)
[r,k] = rlocus(sys)
r = rlocus(sys,k)
sys = tf([2 5 1],[1 2 3]);
rlocus(sys)
load('sisoModels.mat','sys1','sys2','sys3');
rlocus(sys1,'b',sys2,'k',sys3,'r')
hold on
legend('sys1','sys2','sys3')
hold off
Pole and Zero location:
rlocus(sys)
rlocus(sys1,sys2,...)
[r,k] = rlocus(sys)
r = rlocus(sys,k)
sys = tf([2 5 1],[1 2 3]);
rlocus(sys)
load('sisoModels.mat','sys1','sys2','sys3');
rlocus(sys1,'b',sys2,'k',sys3,'r')
hold on
legend('sys1','sys2','sys3')
hold off
sys = tf([3 1],[9 7 5 6]);
[r,k] = rlocus(sys)
sys = tf([0.5 -1],[4 0 3 0 2]);
k = (1:0.5:5);
r = rlocus(sys,k);
size(r)
EXPECTED RESULTS:-
ROOT LOCUS: - Typical plot for Root locus of the transfer function G(s)= 1/
(S^3+8S^2+17S)
BODE PLOT:- Typical plot forfor the given transfer function G(S)=1/S(S^2+2S+3)
PART B - LIST OF EXPERIMENTS USING DSP PROCESSOR
ARCHITECTURE AND INSTRUCTION SET OF
DSPCHIP-TMS320C5515
Introduction to the TMS320C55x:
The TMS320C55x digital signal processor (DSP) represents the latest generation
of ’C5000 DSPs from Texas Instruments. The ’C55x is built on the proven legacy of the
’C54x and is source code compatible with the ’C54x, protecting the customer’s software
investment. Following the trends set by the ’C54x, the ’C55x is optimized for power
efficiency, low system cost, and best-in-class performance for tight power budgets. With
core power dissipation as low as 0.05 mW/MIPS at 0.9V, and performance up to 800
MIPS (400 MHz), the TMS320C55x offers a cost-effective solution to the toughest
challenges in personal and portable processing applications as well as digital
communications infrastructure with restrictive power budgets. Compared to a 120-MHz
’C54x, a 300-MHz ’C55x will deliver approximately 5X higher performance and
dissipate one-sixth the core power dissipation of the ’C54x. The ’C55x core’s ultra-low
power dissipation of 0.05mW/MIPS is achieved through intense attention to low-power
design and advanced power management techniques. The ’C55x designers have
implemented an unparalleled level of power-down configurability and granularity coupled
with unprecedented power management that occurs automatically and is transparent to the
user.
The ’C55x core delivers twice the cycle efficiency of the ’C54x through a dual-
MAC (multiply-accumulate) architecture with parallel instructions, additional
accumulators, ALUs, and data registers. An advanced instruction set, a superset to that of
the ’C54x, combined with expanded busing structure complements the new hardware
execution units. The ’C55x continues the standard set by the ’C54x in code density
leadership for lower system cost. The ’C55x instructions are variable byte lengths ranging
in size from 8 bits to 48 bits. With this scalable instruction word length, the ’C55x can
reduce control code size per function by up to 40% more than ’C54x. Reduced control
code size means reduced memory requirements and lower system cost
EXP.NO: 1
IMPLEMENTATION OF FFT OF GIVEN SEQUENCE
#include "usbstk5515.h"
#include <math.h>
#include <stdio.h>
#define PTS 64 //no 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]; //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
}
} //end of main
fft.c
#define PTS 64 //# of points for FFT
typedef struct {float real,imag;} COMPLEX;
extern COMPLEX w[PTS]; //twiddle constants stored in w
void FFT(COMPLEX *Y, int N) //input sample array, # of points
{
COMPLEX temp1,temp2; //temporary storage variables
int i,j,k; //loop counter variables
int upper_leg, lower_leg; //index of upper/lower butterfly leg
int leg_diff; //difference between upper/lower leg
int num_stages = 0; //number of FFT stages (iterations)
int index, step; //index/step through twiddle constant
i = 1; //log(base2) of N points= # of stages
do
{
num_stages +=1;
i = i*2;
}while (i!=N);
leg_diff = N/2; //difference between upper&lower legs
step = (PTS*2)/N; //step between values in twiddle.h
for (i = 0;i < num_stages; i++) //for N-point FFT
{
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;
}
Code Flow:
• Step 1 - Select no. of points for FFT(Eg: 64)
• Step 2 – Generate a sine wave of frequency ‘f ‘ (eg: 10 Hz with a sampling rate = No. of
Points of FFT(eg. 64)) using math library function.
• Step 3 - Take sampled data and apply FFT algorithm.
Execution Procedure:
Open CCstudio setup
Go to File Menu , select Import option.
In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.
In Select root Directory Browse for project file where it is located.
Select FFT Project folder and Finish it.
Now Connect the DSP Kit to PC and Launch it.(Follow the above given manual
procedure from Step 46 to 51)
Give Right Click on Your fft.out file under Binaries and select Load program
Option.
Now Go to Target select Run.
From Tools select Graph(Dual Time) , give properties and select OK.
Input Signal:
Output Signal:
RESULT:
EXP.NO: 2 POWER SPECTRUM
#include "usbstk5515.h"
#include <math.h>
#include <stdio.h>
#define PTS 64 //# of points for FFT
#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n); //FFT prototype
void apply_fft(void);
float iobuffer[PTS]; //as input and output buffer
float x1[PTS]; //intermediate buffer
float x[PTS];
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
COMPLEX w[PTS]; //twiddle constants stored in w
COMPLEX samples[PTS]; //primary working buffer
void main(void)
{
float sum=0.0 ;
int n,k,i;
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*/
}
/****************Input Signal X(n) *************************/
for(i=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;
}
/********************Auto Correlation of X(n)=R(t) ***********/
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;
}
/********************** FFT of R(t) ***********************/
for (i = 0 ; i < PTS ; i++) //swap buffers
{
samples[i].real=iobuffer[i]; //buffer with new data
}
for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0; //imag components = 0
FFT(samples,PTS); //call function FFT.c
/******************** PSD ********************/
for (i = 0 ; i < PTS ; i++) //compute magnitude
{
x1[i] = sqrt(samples[i].real*samples[i].real + samples[i].imag*samples[i].imag);
}
}
FFT.c
Refer previous FFT experiment
Code Flow:
• Step 1 - Select no. of points for FFT(E.g.: 64)
• Step 2 – Generate a sine wave of frequency ‘f ‘(e.g.: 10 Hz with a sampling rate = No.
of Points of FFT (e.g. 64)) using math library function.
• Step 3 - Compute the Auto Correlation of Sine wave
• Step4 - Take output of auto correlation, apply FFT algorithm.
Execution Procedure:
_ Open CCstudio setup
_ Go to File Menu, select Import option.
_ In the Import Window under CCs choose Existing CCS/CCE Eclipse project then next.
_ In Select root Directory Browse for project file where it is located.
_ Select PSD Project folder and Finish it.
_ Now Connect the DSP Kit to PC and Launch it.(Follow the above given manual
procedure from Step 46 to 51)
_ Give Right Click on Your psd.out file under Binaries and select Load program Option.
_ Now Go to Target select Run.
_ From Tools select Graph(Dual Time and single Time) , give properties and select OK.
Output:
EXP.NO: 3 IMPLEMENTATION OF LP FIR FILTER FOR GIVEN SEQUENCE
&IMPLEMENTATION OF HP FIR FILTER FOR GIVEN SEQUENCE
Aim: The aim of this laboratory exercise is to design and implement a Digital FIR Filter
& observe its frequency response. In this experiment we design a simple FIR filter so as
to stop or attenuate required band of frequencies components and pass the frequency
components, which are outside the required band.
EQUIPMENTS:
Host (PC) with windows(95/98/Me/XP/NT/2000).
TMS320C5515 DSP Starter Kit (DSK).
Finite Impulse Response (FIR) Filter: The FIR filters are of non-recursive type, where
by the present output sample is depending on the present input sample and previous input
samples.
The desired frequency response Hd(ejw) of a filter is periodic in frequency and can be
expanded in Fourier series. The resultant series is given by,
And known as Fourier coefficients having infinite length. One possible way of obtaining
FIR filter is to truncate the infinite Fourier series at n = ± [(N-1)/2]
short h[N]= { 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 2, -2, 0, 2, -2, 0, 2, -2,
0, 3, -3, 0, 4, -4, 0, 5, -6, 0, 10, -14, 0, 70, 70, 0, -14, 10, 0, -6, 5, 0, -4, 4, 0, -3, 3, 0, -2, 2,
0, -2, 2, 0, -2, 2, 0, -1, 1, 0, -1, 1, 0, -1, 1, 0, -1, 1, 0, -1, 1, 0, -1, 1, 0 };
Coefficients for FIR Low Pass triangular filter:
Cutoff freq: 8khz, sampling freq: 24khz
#define N 82 //length of filter
short h[N]= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -2, 0, 2,
-2, 0, 3, -3, 0, 5, -6, 0, 9, -13, 0, 70, 70, 0, -13, 9, 0, -6, 5, 0, -3, 3, 0, -2, 2, 0, -2, 1, 0, -1, 1,
0, -1, 1, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Coefficients for FIR high Pass Kaiser filter:
Cutoff freq: 4khz, sampling freq: 12khz
#define N 82 //length of filter
short h[N]= { 1, 0, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 2, -1, -1, 2, -1, -1, 2, -1, -1, 2, -
1, -1, 3, -2, -2, 4, -2, -2, 5, -3, -4, 9, -6, -8, 27, -41, 41, -27, 8, 6, -9, 4, 3, -5, 2, 2, -4, 2, 2, -
3, 1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 0, -1 };
Coefficients for FIR high Pass rectangular filter:
Cutoff freq: 4khz, sampling freq: 12khz
#define N 82 //length of filter
short h[N]= { 1, -1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 2, -1, -1, 2, -1, -1, 2, -1, -1, 2,
-1, -1, 3, -2, -2, 4, -2, -2, 5, -3, -4, 9, -6, -8, 27, -41, 41, -27, 8, 6, -9, 4, 3, -5, 2, 2, -4, 2, 2,
-3, 1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1 };
Coefficients for FIR high Pass triangular filter:
Cutoff freq: 4khz, sampling freq: 12khz
#define N 82 //length of filter
short h[N]= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, -1, 1, -1, -1, 1, -1, -1, 2, -
1, -1, 3, -2, -2, 5, -3, -3, 8, -5, -8, 27, -41, 41, -27, 8, 5, -8, 3, 3, -5, 2, 2, -3, 1, 1, -2, 1, 1, -
1, 1, 1, -1, 1, 0, -1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
C-Program:
Main.c
#include "stdio.h"
#include "usbstk5515.h"
void main( void )
{
/* Initialize BSL */
USBSTK5515_init();
printf( "playing audio ::::: \n" );
while(1)
{
aic3204_test( );
}
}
Aic3204_test.c:
#define AIC3204_I2C_ADDR 0x18
#include "usbstk5515.h"
#include "usbstk5515_gpio.h"
#include "usbstk5515_i2c.h"
#include "stdio.h"
extern Int16 aic3204_tone_headphone( );
extern Int16 aic3204_loop_stereo_in1( );
Int16 AIC3204_rget( Uint16 regnum, Uint16* regval )
{
Int16 retcode = 0;
Uint8 cmd[2];
cmd[0] = regnum & 0x007F; // 7-bit Register Address
cmd[1] = 0;
retcode |= USBSTK5515_I2C_write( AIC3204_I2C_ADDR, cmd, 1 );
retcode |= USBSTK5515_I2C_read( AIC3204_I2C_ADDR, cmd, 1 );
*regval = cmd[0];
USBSTK5515_wait( 10 );
return retcode;
}
Int16 AIC3204_rset( Uint16 regnum, Uint16 regval )
{
Uint8 cmd[2];
cmd[0] = regnum & 0x007F; // 7-bit Register Address
cmd[1] = regval; // 8-bit Register Data
return USBSTK5515_I2C_write( AIC3204_I2C_ADDR, cmd, 2 );
}
Int16 aic3204_test( )
{
SYS_EXBUSSEL = 0x6100; // Enable I2C bus
USBSTK5515_I2C_init( ); // Initialize I2C
USBSTK5515_wait( 100 ); // Wait
if ( aic3204_loop_stereo_in1( ) )
return 1;
return 0;
}
aic3204_loop_stereo_in1.c:
#include "stdio.h"
#include "usbstk5515.h"
extern Int16 AIC3204_rset( Uint16 regnum, Uint16 regval);
#define Rcv 0x08
#define Xmit 0x20
#define N 82
Int16 data1, data2, data3, data4;
int sample,n,k,l;
Int16 dly0[N];
Int32 lyn,ryn;
/*//hpkaiser12-4
Int16 h[N]= {1, 0, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 2, -1, -1, 2, -1, -1, 2, -1, -1,
2, -1, -1, 3, -2, -2, 4, -2, -2, 5, -3, -4, 9, -6, -8, 27, -41, 41, -27, 8, 6, -9, 4, 3, -5, 2, 2, -4, 2,
2, -3, 1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 0, -1 };*/
/*//hprect12-4
Int16 h[N]= { 1, -1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 2, -1, -1, 2, -1, -1, 2, -1, -1,
2, -1, -1, 3, -2, -2, 4, -2, -2, 5, -3, -4, 9, -6, -8, 27, -41, 41, -27, 8, 6, -9, 4, 3, -5, 2, 2, -4, 2,
2, -3, 1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -2, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1 };*/
/*//hptrig12-4
Int16 h[N]= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, -1, 1, -1, -1, 1, -1, -1, 2, -
1, -1, 3, -2, -2, 5, -3, -3, 8, -5, -8, 27, -41, 41, -27, 8, 5, -8, 3, 3, -5, 2, 2, -3, 1, 1, -2, 1, 1, -
1, 1, 1,-1, 1, 0, -1, 0, 0, -1, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0};*/
/*//lpkaiser24-8
Int16 h[N]= {0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1,0, 1, -1, 0, 1, -1, 0, 2, -2, 0, 2, -2,0, 2, -2, 0,
3, -3, 0, 4, -4, 0, 5, -6, 0, 10, -14, 0, 70, 70, 0, -14, 10, 0, -6, 5, 0, -4, 4, 0, -3, 3, 0, -2, 2, 0,
-2, 2,0, -2, 2, 0, -1, 1, 0, -1, 1, 0, -1, 1,0, -1, 1, 0, -1, 1, 0, -1, 1, 0 };*/
/*//lprect24-8
short h[N]= {0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1,0, 1, -1, 0, 1, -1, 0, 2, -2, 0, 2, -2,0, 2, -2, 0,
3, -3, 0, 4, -4, 0, 5, -6,0, 10, -14, 0, 70, 70, 0, -14, 10, 0, -6, 5, 0, -4, 4, 0, -3, 3, 0, -2, 2, 0, -
2, 2,0, -2, 2, 0, -1, 1, 0, -1, 1, 0, -1, 1,0, -1, 1, 0, -1, 1, 0, -1, 1, 0 };*/
/*//lptrig24-8
Int16 h[N]= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -2, 0, 2,
-2, 0, 3, -3, 0, 5, -6,0, 9, -13, 0, 70, 70, 0, -13, 9, 0, -6, 5,0, -3, 3, 0, -2, 2, 0, -2, 1, 0, -1, 1,
0, -1, 1, 0, -1, 1, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0};*/
//lpkaiser48-8
Int16 h[N]= {-1, 0, 1, 1, 1, -1, -1, -1, 1, 1, 1, -1,-1, -1, 1, 2, 1, -1, -2, -1, 1, 2, 1, -1, -2, -1,
1, 3, 2, -2, -4, -2, 2, 5, 3, -4,-9, -6, 8, 27, 41, 41, 27, 8, -6, -9, -4, 3,5, 2, -2, -4, -2, 2, 3, 1, -
1, -2, -1, 1,2, 1, -1, -2, -1, 1, 2, 1, -1, -1, -1, 1,1, 1, -1, -1, -1, 1, 1, 1, 0, -1};
Int16 aic3204_loop_stereo_in1( )
{
Int16 j, i = 0;
/* Configure AIC3204 */
AIC3204_rset( 0, 0 ); // Select page 0
AIC3204_rset( 1, 1 ); // Reset codec
AIC3204_rset( 0, 1 ); // Point to page 1
AIC3204_rset( 1, 8 ); // Disable crude AVDD generation from DVDD
AIC3204_rset( 2, 1 ); // Enable Analog Blocks, use LDO power
AIC3204_rset( 0, 0 ); // Select page 0
/* PLL and Clocks config and Power Up */
AIC3204_rset( 27, 0x0d ); // BCLK and WCLK is set as o/p to AIC3204(Master)
AIC3204_rset( 28, 0x00 ); // Data ofset = 0
AIC3204_rset( 4, 3 ); // PLL setting: PLLCLK <- MCLK, CODEC_CLKIN <-PLL CLK
AIC3204_rset( 6, 8 ); // PLL setting: J=8
AIC3204_rset( 7, 15 ); // PLL setting: HI_BYTE(D)
AIC3204_rset( 8, 0xdc ); // PLL setting: LO_BYTE(D)
AIC3204_rset( 30, 0x88 ); // For 32 bit clocks per frame in Master mode ONLY
// BCLK=DAC_CLK/N =(12288000/8) = 1.536MHz = 32*fs
#include "stdio.h"
#include "usbstk5515.h"
void main( void )
{
/* Initialize BSL */
USBSTK5515_init();
printf( "playing audio ::::: \n" );
while(1)
{
aic3204_test( );
}
}
Aic3204_test.c:
#define AIC3204_I2C_ADDR 0x18
#include "usbstk5515.h"
#include "usbstk5515_gpio.h"
#include "usbstk5515_i2c.h"
#include "stdio.h"
extern Int16 aic3204_tone_headphone( );
extern Int16 aic3204_loop_stereo_in1( );
Int16 AIC3204_rget( Uint16 regnum, Uint16* regval )
{
Int16 retcode = 0;
Uint8 cmd[2];
cmd[0] = regnum & 0x007F; // 7-bit Register Address
cmd[1] = 0;
retcode |= USBSTK5515_I2C_write( AIC3204_I2C_ADDR, cmd, 1 );
retcode |= USBSTK5515_I2C_read( AIC3204_I2C_ADDR, cmd, 1 );
*regval = cmd[0];
USBSTK5515_wait( 10 );
return retcode;
}
Int16 AIC3204_rset( Uint16 regnum, Uint16 regval )
{
Uint8 cmd[2];
cmd[0] = regnum & 0x007F; // 7-bit Register Address
cmd[1] = regval; // 8-bit Register Data
return USBSTK5515_I2C_write( AIC3204_I2C_ADDR, cmd, 2 );
}
Int16 aic3204_test( )
{
SYS_EXBUSSEL = 0x6100; // Enable I2C bus
USBSTK5515_I2C_init( ); // Initialize I2C
USBSTK5515_wait( 100 ); // Wait
if ( aic3204_loop_stereo_in1( ) )
return 1;
return 0;
}
aic3204_loop_stereo_in1.c:
#include "stdio.h"
#include "usbstk5515.h"
extern Int16 AIC3204_rset( Uint16 regnum, Uint16 regval);
#define Rcv 0x08
#define Xmit 0x20
#define N 83
Int16 data1, data2, data3, data4;
int sample, n, k, l;
Int16 dly0[N];
Int16 dly1[N];
Int32 lyn,lyn0,lyn1;
Int16 h[N]={1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,
3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1, 3,1,3,1,3,1,3,1,3,1,2,1
};
Int16 aic3204_loop_stereo_in1 ( )
{
/* Pre-generated sine wave data, 16-bit signed samples */
Int16 j, i = 0;
/* Configure AIC3204 */
AIC3204_rset( 0, 0 ); // Select page 0
AIC3204_rset( 1, 1 ); // Reset codec
AIC3204_rset( 0, 1 ); // Point to page 1
AIC3204_rset( 1, 8 ); // Disable crude AVDD generation from DVDD
AIC3204_rset( 2, 1 ); // Enable Analog Blocks, use LDO power
AIC3204_rset( 0, 0 ); // Select page 0
/* PLL and Clocks config and Power Up */
AIC3204_rset( 27, 0x0d ); // BCLK and WCLK is set as o/p to AIC3204(Master)
AIC3204_rset( 28, 0x00 ); // Data ofset = 0
AIC3204_rset( 4, 3 ); // PLL setting: PLLCLK <- MCLK, CODEC_CLKIN <-PLL
CLK
AIC3204_rset( 6, 8 ); // PLL setting: J=8
AIC3204_rset( 7, 15 ); // PLL setting: HI_BYTE(D)
AIC3204_rset( 8, 0xdc ); // PLL setting: LO_BYTE(D)
AIC3204_rset( 30, 0x88 ); // For 32 bit clocks per frame in Master mode ONLY
// BCLK=DAC_CLK/N =(12288000/8) = 1.536MHz = 32*fs
AIC3204_rset( 5, 0x91 ); // PLL setting: Power up PLL, P=1 and R=1
AIC3204_rset( 13, 0 ); // Hi_Byte(DOSR) for DOSR = 128 decimal or 0x0080 DAC
oversamppling
AIC3204_rset( 14, 0x80 ); // Lo_Byte(DOSR) for DOSR = 128 decimal or 0x0080
AIC3204_rset( 20, 0x80 ); // AOSR for AOSR = 128 decimal or 0x0080 for decimation
filters 1 to 6
AIC3204_rset( 11, 0x88 ); // Power up NDAC and set NDAC value to 8
AIC3204_rset( 12, 0x82 ); // Power up MDAC and set MDAC value to 2
AIC3204_rset( 18, 0x88 ); // Power up NADC and set NADC value to 8
AIC3204_rset( 19, 0x82 ); // Power up MADC and set MADC value to 2
/* DAC ROUTING and Power Up */
AIC3204_rset( 0, 0x01 ); // Select page 1
AIC3204_rset( 12, 0x08 ); // LDAC AFIR routed to HPL
AIC3204_rset( 13, 0x08 ); // RDAC AFIR routed to HPR
AIC3204_rset( 0, 0x00 ); // Select page 0
AIC3204_rset( 64, 0x02 ); // Left vol=right vol
AIC3204_rset( 65, 0x00 ); // Left DAC gain to 0dB VOL; Right tracks Left
AIC3204_rset( 63, 0xd4 ); // Power up left,right data paths and set channel
AIC3204_rset( 0, 0x01 ); // Select page 1
AIC3204_rset( 16, 0x06 ); // Unmute HPL , 6dB gain
AIC3204_rset( 17, 0x06 ); // Unmute HPR , 6dB gain
AIC3204_rset( 9, 0x30 ); // Power up HPL,HPR
AIC3204_rset( 0, 0x00 ); // Select page 0
USBSTK5515_wait( 500 ); // Wait
/* ADC ROUTING and Power Up */
AIC3204_rset( 0, 1 ); // Select page 1
AIC3204_rset( 0x34, 0x30 ); // STEREO 1 Jack
// IN2_L to LADC_P through 40 kohm
AIC3204_rset( 0x37, 0x30 ); // IN2_R to RADC_P through 40 kohmm
AIC3204_rset( 0x36, 3 ); // CM_1 (common mode) to LADC_M through 40 kohm
AIC3204_rset( 0x39, 0xc0 ); // CM_1 (common mode) to RADC_M through 40 kohm
AIC3204_rset( 0x3b, 0 ); // MIC_PGA_L unmute
AIC3204_rset( 0x3c, 0 ); // MIC_PGA_R unmute
AIC3204_rset( 0, 0 ); // Select page 0
AIC3204_rset( 0x51, 0xc0 ); // Powerup Left and Right ADC
AIC3204_rset( 0x52, 0 ); // Unmute Left and Right ADC
AIC3204_rset( 0, 0 );
USBSTK5515_wait( 200 ); // Wait
/* I2S settings */
I2S0_SRGR = 0x0;
I2S0_CR = 0x8010; // 16-bit word, slave, enable I2C
I2S0_ICMR = 0x3f; // Enable interrupts
/* Play Tone */
for(l=0;l<N;l++)
{
dly0[l]=0;
dly1[l]=0;
}
for ( i = 0 ; i < 5 ; i++ )
{
for ( j = 0 ; j < 1000 ; j++ )
{
for ( sample = 0 ; sample < N ; sample++ )
{
/* Read Digital audio input */
data3 = I2S0_W0_MSW_R; // 16 bit left channel received audio data
data1 = I2S0_W0_LSW_R;
data4 = I2S0_W1_MSW_R; // 16 bit right channel received audio data
data2 = I2S0_W1_LSW_R;
while((Rcv & I2S0_IR) == 0); // Wait for interrupt pending flag
dly0[sample]=data3;
lyn0=0;
lyn1=0;
for(k=0;k<=sample;k++)
lyn0+=((h[k])*dly0[sample-k]); //fir low pass filter
for(k=1;k<=sample;k++)
lyn1+=((h[k])*dly1[sample-k]); //fir low pass filter
lyn=lyn0-lyn1;
dly1[sample]=lyn;
data1=lyn<<1;
data2=lyn<<1;
/* Write Digital audio input */
I2S0_W0_MSW_W = data1; // 16 bit left channel transmit audio data
I2S0_W0_LSW_W = 0;
I2S0_W1_MSW_W = data2; // 16 bit right channel transmit audio data
I2S0_W1_LSW_W = 0;
while((Xmit & I2S0_IR) == 0); // Wait for interrupt pending flag
}
}
}
/* Disble I2S */
I2S0_CR = 0x00;
return 0;
}
Execution Procedure:
Open CCstudio setup
Go to File Menu , select Import option.
In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.
In Select root Directory Browse for project file where it is located.
Select FIR Project folder and Finish it.
Now Connect the DSP Kit to PC and Launch it.(Follow the above given manual
procedure from Step 46 to 51)
Give Right Click on Your fir.out file under Binaries and select Load program
Option.
Now Go to Target select Run.
Observe the audio (Give Input from Stereo in and listen Filtered Output from
Stereo Out).