Академический Документы
Профессиональный Документы
Культура Документы
DEPARTMENT OF ELECTRONICS
AND COMMUNICATION
ENGINEERING
PART-A:INRODUCTION
MATLAB
Graphics
2-D graphics
3-D graphics
Animation
Computations
Linear algebra
Signal processing
Polynomials & interpolation
Quadrature
Solution of ODEs
External interface
Interface with C and
Fortran programs
Toolbox
Signal processing
Statistics
Neural networks
Image processing
Control system
Communications
Dept of ECE
VITAE
Dept of ECE
VITAE
0000
0000
6. ones (5,2)
The above instruction creates a vector of five rows and two columns
Output =
Dept of ECE
11
3
VITAE
if C= [2 2 2]
b.*C results in [8 10 12]
9. plot (t, x)
Ifx = [6 7 8 9]
t = [1 2 3 4]
This instruction will display a figure window which indicates the plot of x versus t
9
8
7
6
1
2`
Dept of ECE
VITAE
9
8
7
6
11. Subplot: This function divides the figure window into rows and columns
Subplot (2 2 1) divides the figure window into 2 rows and 2 columns 1
represent number of the figure
1
(2 2 1)
2
(2,2,2)
3
(2 2 3)
4
( 2 2 4)
Subplot(3, 1, 3)
1 (3, 1, 1)
2 (3, 1, 2)
3 (3, 1, 3)
12 Filter
Syntax:
y = filter(b,a,X)
Description: y = filter(b,a,X) filters the data in vector X with the filter described by
numerator coefficient vector b and denominator coefficient vector a.If a(1) is not equal to
1, filter normalizes the filter coefficients by a(1). If a(1) equals 0, filter returns an error.
Dept of ECE
VITAE
13. Impz
Syntax: [h,t] = impz(b,a,n)
Description: [h,t] = impz(b,a,n) computes the impulse response of the filter with
numerator coefficients b and denominator coefficients a and computes n samples of the
impulse response when n is
computes the impulse response at those integer locations, starting the response
computation from 0 (and t = n or t = [0 n]).If, instead of n, you include the empty vector
[] for the second argument, the number of samples is computed automatically by default.
14. Fliplr
Syntax: B = fliplr(A)
Description: B = fliplr(A) returns A with columns flipped in the left-right direction, that
is, about a vertical axis.If A is a row vector, then fliplr(A) returns a vector of the same
length with the order of its elements reversed. If A is a column vector, then fliplr(A)
simply returns A.
15. Conv
Syntax: w = conv(u,v)
Description: w = conv(u,v) convolves vectors u and v. Algebraically, convolution is the
same operation as multiplying the polynomials whose coefficients are the elements of u
and v.
16.Disp
Syntax: disp(X)
Description: disp(X) displays an array, without printing the array name. If X contains a
text string, the string is displayed.Another way to display an array on the screen is to type
its name, but this prints a leading "X=," which is not always desirable.Note that disp does
not display empty arrays.
17.xlabel
Syntax: xlabel('string')
Description: xlabel('string') labels the x-axis of the current axes.
Dept of ECE
VITAE
18. ylabel
Syntax : ylabel('string')
Description: ylabel('string') labels the y-axis of the current axes.
19.Title
Syntax : title('string')
Description: title('string')
outputs the string at the top and in the center of the current
axes.
20.grid on
Syntax : grid on
Description: grid on adds major grid lines to the current axes.
Dept of ECE
VITAE
Aperiodic-Continuous
This includes, decaying exponentials and the Gaussian curve. These signals extend to
both positive and negative infinity without repeating in a periodic pattern. The Fourier
Transform for this type of signal is simply called the Fourier Transform.
Periodic-Continuous
This includes: sine waves, square waves, and any waveform that repeats itself in a regular
pattern from negative to positive infinity. This version of the Fourier transform is called
the Fourier series.
Aperiodic-Discrete
These signals are only defined at discrete points between positive and negative
infinity,and do not repeat themselves in a periodic fashion. This type of Fourier transform
is called the Discrete Time Fourier Transform.
Periodic-Discrete
These are discrete signals that repeat themselves in a periodic fashion from negative to
positive infinity. This class of Fourier Transform is sometimes called the Discrete Fourier
Series, but is most often called the Discrete Fourier Transform.
Dept of ECE
VITAE
Matlab Code
clf;
a=[1 1 2 2];
x=fft(a,4);
n=0:3;
subplot(2,1,1);
stem(n,abs(x));
xlabel('time index n');ylabel('Amplitude');
title('amplitude obtained by dft');
grid;
subplot(2,1,2);stem(n,angle(x));
xlabel('time index n'); ylabel('Amplitude');
title('Phase obtained by dft');
Dept of ECE
VITAE
Dept of ECE
10
VITAE
Output
freqresp
numerator coefficiuents b = [2 1]
denominator coefficients a = [1 -0.6]
Dept of ECE
11
VITAE
Dept of ECE
12
VITAE
EXPERIMENT NO 3:
Aim:
To find the impulse response h(n) of the given LTI system whose response y(n) to an
input x(n) is given.
Theory:
A discrete time LTI system (also called digital filters) as shown in Fig.2.1 is
represented by
o A linear constant coefficient difference equation, for example,
y[n] a1 y[n 1] a 2 y[n 2] b0 x[n] b1 x[n 1] b2 x[n 2];
o A system function H(z) (obtained by applying Z transform to the
H (z)
difference equation).
Y ( z ) b0 b1 z 1 b2 z 2
X ( z ) 1 a1 z 1 a 2 z 2
Given the difference equation or H(z), the impulse response of the LTI system is
found using filter or impz MATLAB functions.
MATLAB Programs:
Program 1
b=input('numerator coefficiuents b = ');
a=input('denominator coefficients a = ');
n=input('enter length n = ');
[h,t] = impz(b,a,n);
Dept of ECE
13
VITAE
0.5000
0.2500
0.1250
0.0625
0.0313
0.0156
0.0078
0.0039
0.0020
0.0010
0.0005
0.0002
0.0001
0.0001
0.0000
0.0000
0.0000
0.0000
0.0000
Dept of ECE
14
VITAE
The N point DFT of discrete time signal x[n] is given by the equation
N -1
X (k ) x[n]e
j 2kn
N
; k 0,1,2,....N - 1
n 0
The inverse DFT allows us to recover the sequence x[n] from the frequency
samples.
x[n]
1
N
N 1
x[n]e
j 2kn
N
; n 0,1,2,....N - 1
k 0
Since N L , increasing N to 8 from 80 for the same x[n] implies x[n] is still the
same sequence (<8), the rest of x[n] is padded with zeros. This implies that there
is no further information in time domain, but the resulting spectrum has higher
frequency resolution. This spectrum is known as high density spectrum
Dept of ECE
15
VITAE
Dept of ECE
16
VITAE
Dept of ECE
17
VITAE
Dept of ECE
18
VITAE
y(n) =
x ( k ) x ( k n)
Dept of ECE
19
VITAE
Output
Dept of ECE
20
VITAE
Step 1: Compute the digital cut-off frequency Wc (in the range - < Wc < , with
fs=8000Hz
Wc = 2** fc / fs = 2* * 400/8000 = 0.1* radians
For MATLAB the Normalized cut-off frequency is in the range 0 and 1, where 1
corresponds to fs/2 (i.e.,fmax)). Hence to use the MATLAB commands
wc = fc / (fs/2) = 400/(8000/2) = 0.1
Note: if the cut off frequency is in radians then the normalized frequency is
computed as wc = Wc /
Step 2: Compute the Impulse Response h(n) of the required FIR filter using the
given Window type and the response type (lowpass, bandpass, etc). For example
given a rectangular window, order N=20, and a high pass response, the
coefficients (i.e., h[n] samples) of the filter are computed using the MATLAB
inbuilt command fir1 as
21
VITAE
Wc=(wp+ws)/2
Now compute the normalized frequency in the range 0 to 1 for MATLAB
as
wc=Wc/pi;
Note: In step 2 if frequencies are in Hz, then obtain radian frequencies (for computation
of tb and N)
Step 4: Compute the Impulse Response h(n) of the required FIR filter using N,
selected window, type of response(low/high, etc) using fir1 as in step 2 of
method 1.
MATLAB IMPLEMENTATION
Dept of ECE
22
VITAE
frequency response
is evaluated at N points equally spaced around the upper half of the unit circle. If N isn't
specified, it defaults to 512.
For FIR filter enter A=1 and B = h[n] coefficients. Appropriately choose N as 128, 256,
etc
Width
Window
Transition
Name
Matlab
Attenuation
Command
Rectangular
4
M
1.8
M
21db
B= FIR1(N,Wn,boxcar)
Bartlett
8
M
6.1
M
25db
B = FIR1(N,Wn,bartlett)
Hanning
8
M
6.2
M
44db
B = FIR1(N,Wn,hanning)
Hamming
8
M
6.6
M
53db
B= FIR1(N,Wn,hamming)
Blackman
12
M
11
M
Dept of ECE
74db
23
B = FIR1(N,Wn,blackman)
VITAE
Dept of ECE
24
VITAE
Dept of ECE
25
VITAE
Dept of ECE
26
VITAE
Fig.11.1
Fig.11.2
Dept of ECE
27
VITAE
0.7523
0.7854
0.8166
0.8457
0.8727
0.8973
0.9195
0.9392
0.9563
0.9706
0.9822
0.9909
0.9967
0.9996
0.9996
0.9967
0.9909
0.9822
0.9706
0.9563
0.9392
0.9195
0.8973
0.8727
0.8457
0.8166
0.7854
0.7523
0.7175
Columns 6 through 10
Dept of ECE
28
VITAE
0.0333
Columns 11 through 15
-0.0614 -0.0140
0.0895
0.2097
0.2900
Columns 16 through 20
0.2900
0.2097
Columns 21 through 25
-0.0495 -0.0072
0.0277
0.0333
0.0133
0.0028
0.0141
Columns 26 through 30
-0.0117 -0.0224 -0.0142
Dept of ECE
29
VITAE
Step 1: Compute the digital cut-off frequency Wc (in the range - < Wc < , with
corresponding to fs/2) for fc and fs in Hz. For example let fc=400Hz, fs=8000Hz
Step 2: Compute the Impulse Response [b,a] coefficients of the required IIR filter
and the response type (lowpass, bandpass, etc) using the appropriate butter, cheby1,
cheby2 command. For example given a butterworth filter, order N=2, and a high pass
response, the coefficients [b,a] of the filter are computed using the MATLAB inbuilt
command butter as [b,a] =butter(N, wc , 'high');
Method 2:
Given the pass band (Wp in radians) and Stop band edge (Ws in radians) frequencies,
Pass band ripple Rp and stopband attenuation As.
Dept of ECE
30
VITAE
Step 3: Compute the Impulse Response [b,a] coefficients of the required IIR filter
and the response type as [b,a] =butter(N, wc , 'high');
Ws = .2
Highpass: Wp = .2,
Ws = .1
Bandpass: Wp = [.2 .7], Ws = [.1 .8] Bandstop: Wp = [.1 .8], Ws = [.2 .7]
BUTTORD also returns Wn, the Butterworth natural frequency (or, the "3 dB
frequency") to use with BUTTER to achieve the specifications.
[N, Wn] = BUTTORD(Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in
which case Wp and Ws are in radians/second.
When Rp is chosen as 3 dB, the Wn in BUTTER is equal to Wp in BUTTORD.
BUTTER Butterworth digital and analog filter design.
Dept of ECE
31
VITAE
Dept of ECE
32
VITAE
33
VITAE
Dept of ECE
34
VITAE
Result: rp = 1 rs = 40
w1 = 800
w2 = 1200
Dept of ECE
35
VITAE
ws = 360
Dept of ECE
36
VITAE
The difference equation of the second order filter shown in Figure 1 will be:
Dept of ECE
37
VITAE
Where F0 is the frequency, Fs is the sampling frequency and A is the amplitude of the
sine wave.
Matlab Program
% Generation of sine wave using recursive difference equation or IIR filter
%fs = sampling rate
% t = time in sec
%f0 = frequency
% A = amplitude
A = 2;
t=0.1;
fs = 5000;
f0=50;
length = fs*t;
y = zeros(1,length);
impulse = zeros(1,length);
impulse(1) = 1;
% frequency coefficients
% difference equation of form y[n]= -a1 y[n-1] -a2 y[n-2] + b0 impulse[n]
Dept of ECE
38
VITAE
y(1)= 0;
y(2)= b0;
for i=3:length
y(i)= b0* impulse(i)- a1*y(i-1) - a2* y(i-2);
end
plot (y);
title('Sinusoidal waveform')
xlabel('samples n');
ylabel('y(n)');
Result :
Dept of ECE
39
VITAE
697Hz
770 Hz
852Hz
941 Hz
Dept of ECE
1209Hz
1336Hz
ABC
1477 Hz
DEF
1
GHI
2
JKL
3
MNO
4
PQRS
5
TUV
6
WXYZ
40
VITAE
We will right the program to generate and visualize the DTMF tones for all 12 Symbols.
Also we will estimate its energy content using Gortzets Algorithm
The minimum duration of a DTMF signal defined by the ITU standard is 40 ms.
Therefore, there are at most 0.04 x 8000 = 320 samples available for estimation and
detection. The DTMF decoder needs to estimate the frequencies contained in these short
signals.
One common approach to this estimation problem is to compute the Discrete-Time
Fourier Transform (DFT) samples close to the seven fundamental tones. For a DFT-based
solution, it has been shown that using 205 samples in the frequency domain minimizes
the error between the original frequencies and the points at which the DFT is estimated.
At this point we could use the Fast Fourier Transform (FFT) algorithm to calculate the
DFT. However, the popularity of the Goertzel algorithm in this context lies in the small
number of points at which the DFT is estimated. In this case, the Goertzel algorithm is
more efficient than the FFT algorithm.
Plot Goertzel's DFT magnitude estimate of each tone on a grid corresponding to the
telephone pad.
MATLAB Program
% generating all 12 frequencies
symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; % Low frequency group
hfg = [1209 1336 1477]; % High frequency group
f = [];
for c=1:4,
for r=1:3,
f = [ f [lfg(c);hfg(r)] ];
Dept of ECE
41
VITAE
N = 800;
% Tones of 100 ms
"',
symbol{toneChoice},'":
[',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'Xlim', [0 25]);
ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
end
set(gcf, 'Color', [1 1 1], 'Position', [1 1 1280 1024])
annotation(gcf,'textbox', 'Position',[0.38 0.96 0.45 0.026],...
'EdgeColor',[1 1 1],...
'String', '\bf Time response of each tone of the telephone pad', ...
'FitHeightToText', 'on');
% estimation of DTMF tone using Gortzel's Algorithm
Nt = 205;
original_f = [lfg(:);hfg(:)] % Original frequencies
k = round(original_f/Fs*Nt); % Indices of the DFT
estim_f = round(k*Fs/Nt)
Dept of ECE
42
VITAE
"',
symbol{toneChoice},'":
[',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']'])
set(gca, 'XTick', estim_f, 'XTickLabel', estim_f, 'Xlim', [650 1550]);
ylabel('DFT Magnitude');
if toneChoice>9, xlabel('Frequency (Hz)'); end
end
set(gcf, 'Color', [1 1 1], 'Position', [1 1 1280 1024])
annotation(gcf,'textbox', 'Position',[0.28 0.96 0.45 0.026],...
'EdgeColor',[1 1 1],...
'String', '\bf Estimation of the frequencies contained in each tone of the telephone pad
using Goertzel', ...
'FitHeightToText','on');
Output:
Dept of ECE
43
VITAE
Dept of ECE
44
VITAE
Dept of ECE
45
VITAE
Dept of ECE
46
VITAE
Dept of ECE
47
VITAE
Dept of ECE
48
VITAE
Dept of ECE
49
VITAE
Dept of ECE
50
VITAE
(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.
Dept of ECE
51
VITAE
Dept of ECE
52
VITAE
Dept of ECE
53
VITAE
Dept of ECE
54
VITAE
Dept of ECE
55
VITAE
Features
Debugger
CCStudio's integrated debugger has several capabilities and advanced breakpoints
to simplify development. Conditional or hardware breakpoints are based on full C
expressions, local variables or registers. The advanced memory window allows you to
inspect each level of memory so that you can debug complex cache coherency issues.
CCStudio supports the development of complex systems with multiple processors or
cores. Global breakpoints and synchronous operations provide control over multiple
processors and cores.
Profiling
CCStudio's interactive profiler makes it easy to quickly measure code
performance and ensure the efficient use of the target's resources during debug and
development sessions. The profiler allows developers to easily profile all C/C++
functions in their application for instruction cycles or other events such as cache
misses/hits, pipeline stalls and branches.
Dept of ECE
56
VITAE
Dept of ECE
57
VITAE
Dept of ECE
58
VITAE
Dept of ECE
59
VITAE
Step 2:
Project windows overview
Dept of ECE
60
VITAE
Dept of ECE
61
VITAE
12. You can notice the input signal of 500 Hz. appearing on the CRO verifying the
codec configuration.
13. You can also pass an audio input and hear the output signal through the
speakers.
14. You
can
also
vary
the
sampling
frequency
using
the
DSK6713_AIC23_setFreq Function in the codec.c file and repeat the
above steps.
5.0 Conclusion:
The codec TLV320AIC23 successfully configured using the board support
library
and verified.
Dept of ECE
62
VITAE
codec.c
#include "filtercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
/* 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;
Dept of ECE
63
VITAE
EXP.NO: 15
COMPUTATION OF N- POINT DFT OF A GIVEN SEQUENCE
Aim: To compute the N (=4/8/16) point DFT of the given sequence
EQUIPMENTS:
Theory:
The N point DFT of discrete time signal x[n] is given by the equation
N -1
X (k ) x[n]e
j 2kn
N
; k 0,1,2,....N - 1
n 0
Dept of ECE
64
VITAE
j 2kn
N
2kn
2kn
j sin
N
N and allot memory
cos
Dept of ECE
65
VITAE
Dept of ECE
66
VITAE
In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.
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 Dft.out file under Binaries and select Load program
Option.
From Tools select Graph(Dual Time) , give properties and select OK.
Result:
Input Signal:
Output Signal :
Dept of ECE
67
VITAE
Graph Properties:
Dept of ECE
68
VITAE
EXP.NO: 16
IMPLEMENTATION OF FFT OF GIVEN SEQUENCE
AIM: To compute the FFT of the given sequence
EQUIPMENTS:
1. Host (PC) with windows (95/98/Me/XP/NT/2000).
2. TMS320C5515 DSP Starter Kit (DSK).
FFT Algorithm
The FFT has a fairly easy algorithm to implement, and it is shown step by step in the list
below. This version of the FFT is the Decimation in Time Method
1. Pad input sequence, of N samples, with Zeros until the number of samples is the
nearest power of two.
e.g. 500 samples are padded to 512 (2^9)
2. Bit reverse the input sequence.
e.g. 3 = 011 goes to 110 = 6
3. Compute (N / 2) two sample DFT's from the shuffled inputs. See "Shuffled Inputs"
4. Compute (N / 4) four sample DFT's from the two sample DFT's. See "Shuffled Inputs"
5. Compute (N / 2) eight sample DFT's from the four sample DFT's. See "Shuffled
Inputs"
6. Until the all the samples combine into one N-sample DFT
PROGRAM:
Main.c
#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
Dept of ECE
69
VITAE
Dept of ECE
70
VITAE
Dept of ECE
71
VITAE
Dept of ECE
72
VITAE
In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.
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.
From Tools select Graph(Dual Time) , give properties and select OK.
Dept of ECE
73
VITAE
Output Signal:
Dept of ECE
74
VITAE
EXP.NO: 17
POWER SPECTRUM
Aim: To verify the power spectrum using DSP processor.
Equipments required:
1. Host (PC) with windows (95/98/Me/XP/NT/2000).
2. TMS320C5515 DSP Starter Kit (DSK).
Program:
Main.c
#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*/
Dept of ECE
75
VITAE
Dept of ECE
76
VITAE
Dept of ECE
77
VITAE
Dept of ECE
78
VITAE
EXP.NO: 18
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:
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 transfer function of a FIR causal filter is given by,
N 1
H ( z )= h ( n ) Z
n=0
H ( e jw ) = h ( n ) e jwn
n=0
In the design of FIR filters most commonly used approach is using windows.
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,
hd ( n )=(1 /2 ) H (e jw )e jwn dw
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]
Where N is the length of the desired sequence.
The Fourier coefficients of the filter are modified by multiplying the infinite impulse
response with a finite weighing sequence w(n) called a window.
Dept of ECE
79
VITAE
H ( e ) =(1 /2 ) H d (e j )e jw d
jw
Dept of ECE
80
VITAE
Dept of ECE
81
VITAE
Dept of ECE
82
VITAE
Dept of ECE
83
VITAE
Dept of ECE
84
VITAE
Dept of ECE
85
VITAE
Dept of ECE
86
VITAE
Dept of ECE
87
VITAE
Dept of ECE
88
VITAE
In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.
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.
Observe the audio (Give Input from Stereo in and listen Filtered Output from
Stereo Out).
Dept of ECE
89
VITAE
EXP.NO: 19
IMPLEMENTATION OF LP IIR FILTER FOR GIVEN SEQUENCE &
IMPLEMENTATION OF HP IIR FILTER FOR GIVEN SEQUENCE
Aim: The aim of this laboratory exercise is to design and implement a Digital IIR Filter
& observe its frequency response. In this experiment we design a simple IIR filter so as
to stop or attenuate required band of frequencies components and pass the frequency
components which are outside the required band
EQUIPMENTS NEEDED:
Dept of ECE
90
VITAE
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,
1,3,1,3,1,3,1,3,1,2,1};
IIR low pass filter coefficients:
#define N 83 //length of filter
Shorth[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 };
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( );
Dept of ECE
91
VITAE
Dept of ECE
92
VITAE
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)
Dept of ECE
93
VITAE
Dept of ECE
94
VITAE
Dept of ECE
95
VITAE
In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.
Dept of ECE
96
VITAE
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.
Observe the audio (Give Input from Stereo in and listen Filtered Output from
Stereo Out).
Dept of ECE
97
VITAE
EXP.NO: 20
GENERATION OF SINUSOIDAL SIGNAL THROUGH FILTERING
Program:
Main.c
#include <usbstk5515.h>
#include<stdio.h>
#include <math.h>
#define PTS 40 //no of points for FFT
#define PI 3.14159265358979
float output;
float y[40];
void main()
{
int n;
for (n=0; n<PTS; n++)
{
/*y[n]=Ay[n1]+By[n2] A=1.9754 and B=1. Examining the behavior
of this IIR filter by its transfer function as below:
//y[n] = 1.9754y[n1] y[n2] */
if(n<2)
y[n]=sin(2*PI*n/PTS);
else
y[n]=(1.9754*y[n-1])-(y[n-2]);
printf("%f,",y[n]);
}
}
Execution Procedure:
In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.
Dept of ECE
98
VITAE
Now Connect the DSP Kit to PC and Launch it.(Follow the above given manual
Give Right Click on Your sin.out file under Binaries and select Load program
Option.
In Tools menu select Graph (single Time) set the properties and watch.
Result:
Graph Proeprties:
Dept of ECE
99
VITAE
Dept of ECE
100
VITAE
EXP.NO: 21
GENERATION OF DTMF SIGNALS
Program:
#include <usbstk5515.h>
#include<stdio.h>
#include <math.h>
#define PTS 256
#define FS 8000 //sampling frequency of 8khz
#define pi 3.14159265358979
int lfg[ ]={697,770,852,941}; // Low frequency group
int hfg[ ]={1209,1336,1477}; // High frequency group
float num[12][PTS];
float t[PTS];
void main()
{
int n,tone_select=0,r=0,c=0;
printf("DTMF Signal Generation:");
for(n=0;n<PTS;n++) {
t[n] = 2*pi*n/FS; }
tone_select=0;
for(r=0;r<4;r++) //loop for selection lfg index
{
for(c=0;c<3;c++) //loop for selection hfg index
{
for(n=0;n<PTS;n++)
{
num[tone_select][n]=sin(lfg[r]*t[n])+sin(hfg[c]*t[n]);
//printf("%d %f \n",n,t[n],num[tone_select][n]);
}
tone_select++;
}
Dept of ECE
101
VITAE
In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.
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 dtmf.out file under Binaries and select Load program
Option.
In Tools menu select Graph (single Time) set the properties and watch.
Result:
DTMF 1:
DTMF 2:
Dept of ECE
102
VITAE
Dept of ECE
103
VITAE
EXP.NO: 22
IMPLEMENTATION OF DECIMATION PROCESS
Program:
#include <usbstk5515.h>
#include<stdio.h>
#include <math.h>
#define PTS 256 //no of points for FFT
#define PI 3.14159265358979
float y1[PTS],y2[PTS],y3[PTS];
main()
{
int n,m;
printf("Enter Vaue for Decimation Factor\n");
scanf("%d",&m);
printf("Original signal samples:\n");
for(n=0;n<=PTS;n++) //original signal
{
y1[n]=sin(2*PI*10*(n)/(PTS));
printf("%d, %f\n",n,y1[n]);
}
printf("Decimated signal samples:\n");
for(n=0;n<=PTS;n++) //intrpol
{
y2[n]=sin(2*PI*10*n/(m*PTS));
printf("%d, %f\n",n,y2[n]);
}
} //end of main
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.
Dept of ECE
104
VITAE
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 decimation.out file under Binaries and select Load program
Option.
In Tools menu select Graph (Dual Time) set the properties and watch input signal and
decimated signal.
Result:
Input signal:
Output Signal:
Graph Properties:
Dept of ECE
105
VITAE
EXP.NO: 23
IMPLEMENTATION OF INTERPOLATION PROCESS
Program:
#include <usbstk5515.h>
#include<stdio.h>
#include <math.h>
#define PTS 256 //no of points for FFT
#define PI 3.14159265358979
float y1[PTS],y2[PTS],y3[PTS];
main()
{
int n,m;
printf("Enter Vaue for Interpolation Factor\n");
scanf("%d",&m);
printf("Original signal samples:\n");
for(n=0;n<=PTS;n++) //original signal
{
y1[n]=sin(2*PI*10*(n)/(PTS));
printf("%d, %f\n",n,y1[n]);
}
printf("Interpolated signal samples:\n");
for(n=0;n<=PTS;n++) //intrpol
Dept of ECE
106
VITAE
In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.
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 interpolation.out file under Binaries and select Load
program Option.
In Tools menu select Graph (Dual Time) set the properties and watch input signal and
decimated signal.
Result :
Input Signal:
Dept of ECE
107
VITAE
Dept of ECE
108
VITAE
Graph Properties:
Dept of ECE
109
VITAE
EXP.NO: 24
IMPULSE RESPONSE OF FIRST ORDER AND SECOND ORDER
SYSTEMS
Program:
#include<stdio.h>
#define Order 2
#define Len 5
float h[Len] = {0.0,0.0,0.0,0.0,0.0},sum;
void main()
{
int j, k;
float a[Order+1] = {0.1311, 0.2622, 0.1311};
float b[Order+1] = {1, -0.7478, 0.2722};
for(j=0; j<Len; j++)
{
sum = 0.0;
for(k=1; k<=Order; k++)
{
if ((j-k) >= 0)
sum = sum+(b[k]*h[j-k]);
}
if (j <= Order)
h[j] = a[j]-sum;
else
h[j] = -sum;
printf (" %f ",h[j]);
}
}
Output:
0.131100 0.360237 0.364799 0.174741 0.031373
Dept of ECE
110
VITAE
Dept of ECE
111
VITAE
Dept of ECE
112
VITAE
Graph Properties:
Dept of ECE
113
VITAE
EXP. NO 25
AUDIO APPLICATIONS
Aim: Audio applications such as to plot a time and frequency display of
microphone plus a cosine using DSP. Read a wav file and match with their
respective spectrograms.
Program:
#include <math.h>
#include <stdio.h>
#include "usbstk5515.h"
#define PTS 64
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n);
void cosine_plot(void);
Int16 aic3204_test( );
extern Int16 dly0[PTS];
COMPLEX data[PTS],samples[PTS];
COMPLEX w[PTS];
#define PI 3.14159265358979
float x1[PTS],y1[PTS],iobuffer[PTS];
int i;
void main( void )
{
/* Initialize BSL */
USBSTK5515_init();
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
}
printf( "Cosine Plot ::::: \n" );
cosine_plot();
Dept of ECE
114
VITAE
Dept of ECE
115
VITAE
#include "stdio.h"
#include "usbstk5515.h"
extern Int16 AIC3204_rset( Uint16 regnum, Uint16 regval);
#define Rcv 0x08
#define Xmit 0x20
#define N 64
Int16 data1, data2, data3, data4;
int sample,n,k,l;
Int16 dly0[N];
Int32 lyn,ryn;
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
Dept of ECE
116
VITAE
Dept of ECE
117
VITAE
Dept of ECE
118
VITAE
Dept of ECE
119
VITAE
In the Import Window under CCs choose Existing CCS/CCE Eclipse project then
next.
Dept of ECE
120
VITAE
Now Connect the DSP Kit to PC and Launch it.(Follow the above given manual
procedure
Give Right Click on Your Audio.out file under Binaries and select Load program
Option.
Observe the audio (Give Input from Stereo in and listen Filtered Output
In Tools menu select Graph (Dual Time) set the properties and watch.
Result:
Cosine time plot
Dept of ECE
121
VITAE
Frequency plot
Dept of ECE
122
VITAE
Dept of ECE
123
VITAE
EXP. NO.26
NOISE REMOVAL
Noise removal programs:
(i)
Add noise above 3kHz and then remove (using adaptive filters)
(ii)
Program code:
Main.c
#include<usbstk5515.h>
#include<stdio.h>
Int16 aic3204_test( );
void main()
{
USBSTK5515_init();
while(1)
{
aic3204_test();
}
}
aic3204_loop_stereo_in1.c
#include "stdio.h"
#include "usbstk5515.h"
#include<math.h>
extern Int16 AIC3204_rset( Uint16 regnum, Uint16 regval);
#define Rcv 0x08
#define Xmit 0x20
#define beta 1.5E-8 /*rate of convergence */
#define N1 30 /*# of coefficients */
#define NS 128 /*# of output sample points*/
#define Fs 8000 /*sampling frequency */
#define pi 3.1415926
//#define DESIRED 1000*sin(2*pi*T*1000/Fs) /*desired signal */
Dept of ECE
124
VITAE
Dept of ECE
125
VITAE
Dept of ECE
126
VITAE
Dept of ECE
127
VITAE
Dept of ECE
128
VITAE
IDE
Debug IDE
Advanced watch windows
Integrated editor
File I/O, Probe Points, and graphical algorithm scope probes
Advanced graphical signal analysis
Interactive profiling
Automated testing and customization via scripting
Visual project management system
Compile in the background while editing and debugging
Multi-processor debugging
Help on the target DSP
Dept of ECE
129
VITAE
130
VITAE
sum.c
# include<stdio.h>
main()
{
int i=0;
i++;
printf("%d",i);
}
To Perform Single Step Debugging:
1. Keep the cursor on the on to the line from where u want to start single
step debugging.(eg: set a break point on to first line int i=0; of your
project.)
To set break point select
Dept of ECE
131
VITAE
Additional Programs:
EXP. NO.:27 LINEAR CONVOLUTION
To Verify Linear Convolution:
Linear Convolution Involves the following operations.
1. Folding
2. Multiplication
3. Addition
4. Shifting
These operations can be represented by a Mathematical Expression as follows:
x[n] = {1, 2, 3, 4}
h[k] = {1, 2, 3, 4}
r=
n= 0
1
2
3
0
1
2
x[0]h[0] x[0]h[1] x[0]h[2] x[0]h[3]
x[1]h[0] x[1]h[1] x[1]h[2]
x[2]h[0] x[2]h[1]
x[3]h[0]
Dept of ECE
x[1]h[3]
x[2]h[2] x[2]h[3]
x[3]h[1] x[3]h[2]
132
x[3]h[3]
VITAE
Output:
OUTPUT:
Dept of ECE
133
VITAE
134
VITAE
Subfigure 1.1
Subfigure 1.2
Step 2: "Spin" h[m] n times Anti Clock Wise (counter-clockwise) to get h[n-m]
(i.e. Simply rotate the sequence, h[n], clockwise by n steps)
Figure 2: Step 2
Step 3: Pointwise multiply the f[m] wheel and the h[nm] wheel. sum=y[n]
Step 4: Repeat for all 0nN1
Example 1: Convolve (n = 4)
Subfigure 3.1
Subfigure 3.2
Figure 3: Two discrete-time signals to be
convolved.
h[m] =
Dept of ECE
135
VITAE
Figure 4
Multiply f[m] and sum to yield: y[0] =3
h[1m]
Figure 5
Multiply f[m] and sum to yield: y[1] =5
h[2m]
Figure 6
Multiply f[m] and sum to yield: y[2] =3
h[3m]
Figure 7
Multiply f[m] and sum to yield: y[3] =1
Dept of ECE
136
VITAE
Dept of ECE
137
VITAE
Dept of ECE
y[4]={3, 5, 3,0}
138
VITAE