Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual
DIGITAL SIGNAL
PROCESSING
LAB MANUAL
DEPARTMENT OF ECE
LORDS INSTITUTE OF ENGINEERING &TECHNOLOGY
Page 1
DEPARTMENT OF ECE
LIST OF EXPERIMENTS:
1. To study the architecture of DSP chips TMS 320C SX/6X Instructions.
2. To verify linear convolution.
3. To verify the circular convolution
4. To design FIR filter (LP/HP) using windowing technique.
a) Using rectangular window
b) Using triangular window
c) Using Kaiser window
5. To implement IIR filter (LP/HP) on DSP processors.
6. N-point FET algorithm.
7. MATLAB program to generate sum of sinusoidal signals.
8. MATLAB program to find frequency response of analog LP/HP filters.
9. To compute power density spectrum of a sequence.
10. To find the FFT of given 1-D signal and plot.
Page 2
DEPARTMENT OF ECE
INDEX
S.No.
1
Description
To study the architecture of DSP chips TMS 320C
Page No.
1-30
SX/6X Instructions.
2
31-38
39-45
46-55
technique.
a) Using rectangular window
b) Using triangular window
c) Using Kaiser window
5
56-63
64-75
76-80
81-86
LP/HP filters.
87-90
10.
91-95
11
ADD ON EXPERIMENTS
Design of FIR filter using Hamming window
96-99
DESIGN EXPERIMENT
12
100-104
Page 3
DEPARTMENT OF ECE
DSP CHIP-TMS320C6713
FEATURES OF HIGHEST-PERFORMANCE FLOATING POINT DIGITAL SIGNAL
PROCESSOR TMS320C6713
Page 4
DEPARTMENT OF ECE
11 C6000 OVERVIEW
Internal
Memory
P
E
R
I
P
H
E
R
A
L
S
External
Memory
CPU
C6000 OVERVIEW
Memory
A0
B0
.D1
.D2
.M1
.M2
.L1
.L2
.S1
.S2
A15
8 functional units
.D (data) 32-bit operands
.L (ALU) 32-or-40-bit operands
.S (shift) 32-or-40 bit operands
.M (multiply) 16x16bit integer
or 32x32 bit floating point
2 register files (32-bit)
All 6 units can be used in parallel
each cycle
B15
Controller / Decoder
Page 5
DEPARTMENT OF ECE
Page 6
DEPARTMENT OF ECE
TMS320C6713 ARCHITECTURE
Page 7
DEPARTMENT OF ECE
Page 8
DEPARTMENT OF ECE
Page 9
DEPARTMENT OF ECE
Page 10
DEPARTMENT OF ECE
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
Page 11
DEPARTMENT OF ECE
Page 12
DEPARTMENT OF ECE
EXPT.NO.2
y[ii] =
k-w
x[k]h[n k]
Page 13
DEPARTMENT OF ECE
x [n] = {1, 2, 3, 4}
H [k] = {, 2, 3, 4}
r = n+k-1
r=
0
______
n = o (x[0]h[0]
x[0]h[1]
x[0]h[2]
x[0]h[3]
x[1]h[1]
x[1]h[2]
x[1]h[3]
x[2]h[0]
x[2]h[1]
x[2]h[2]
x[2]h[3]
x[3]h[0]
x[3]h[1]
x[3]h[2]
x[3]h[3]
x[1]h[0]
Output :
Page 14
DEPARTMENT OF ECE
.half 1,2,3,4,0,0,0,0
;input1, M =4
.half 1,2,3,4,0,0,0,0
;input2, N =4
.bss y,14,2
;OUTUT, R=M+N-1
;POINTER TO X
;POINTER TO H
;POINTER TO Y
;R=M+N-1
A7
ZERO .L1
A3
;I=0
LL2:
ZERO .L1 A2
ZERO .L1 A8
LDH
.d1*a4[a8],a6
;for(j=0;j<=i;j++)
MV
.s2x A8,B5
; y[i]+=x[j]*h[i-j];
SUB
.l2 a3,b5,b7
LL1:
Page 15
DEPARTMENT OF ECE
LDH
.D2*B4[B7],B6
NOP4
[B0]
[A2]
MP5
ADD
.L1 A8, A8
ADD
CMPLT
B
NOP 5
.S2
STH .D1
ADD
CMPLT
A2,*A5[A3]
.L1 A3, 1,A3
.L1X A3, B2, A2
LL1
.S1 LL2
NOP 5
B
B3
NOP 5
Page 16
DEPARTMENT OF ECE
int m=4;
Int n=4;
Int i=0,j;
int x[10]={1,2,3,4,0,0,0,0}; /*input signal samples*/
int h[10]={1,2,3,4,0,0,0,0}; /*input response co-efficients*/
/* at the end of input sequences pad m and n no. of zeros*/
int y[10];
for (i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=I;j++)
y[i]+=x{j}*h[i-j};
}
for(i=0;i<m+n-1;i++)
print(%d/n,y[i]);
}
Page 17
DEPARTMENT OF ECE
PROCEDURE :
Open code composer studio, make sure the dsp kit is turned on.
Start a new project using project-new pull down menu, save it in a separate directory
(c:\ti\myprojects) with name iconv.pjt.
Add the source files conv.asm.
To the project using project->add files to project pull down menu.
Add the linker command file hello.cmd.
(path:c\ti\tutorial\dsk6713\hello1\hello.cmd)
Add the run time support library file rts6700.lib.
9path: c:\ti\c6000\cgtools\lib\rts6700.lib)
Compile the program using the project-compile pull down menu or by clicking the
shortcut icon on the left side of program window.
Build the program using the project-build pull down menu or by clicking the shortcut
icon on the left side of program window.
Load the program (iconv.out) in program memory of dsp chip using the file-load
program pull down menu.
To view output graphically
Select view -> graph -> time and frequency
Page 18
DEPARTMENT OF ECE
RESULT :
Configure the graphical window as shown below
INPUT
x[n] = {1, 2, 3, 4,0,0,0,0}
h[k] = {1, 2, 3, 4,0,0,0,0}
OUTPUT :
NOTE :
1. To execute the above program follow procedure to work on code composer studio
2. To view graphical output follow the above procedure.
Page 19
DEPARTMENT OF ECE
6. Write the expressions for LTI system convolution formula and causal LTI system
convolution formula.
7. What us the length of linear convolution if length of input and impulse responses are N1
and N2 respectively?
8. What is the difference between continuous and discrete convolution?
Page 20
DEPARTMENT OF ECE
EXPT.NO.3
ALGORITHM:
Steps for circular convolution
Steps for circular convolution are the same as the usual convolution, expect all index calculations
are down mod N = on the wheel
Steps for cyclic convolution
Step1:plot f[m] and h[-m]
f[I}
h [N-I}
f[0}
f[N-I}
h[0}
h[I}
Figure 2 : step2
Page 21
DEPARTMENT OF ECE
Step 3 : Pointwise multiply the [m] wheel and the h[n-m] wheel. Sum=y[n]
Step 4: Repeat for all 0 < n < N-1
Example 1 : convolve (n = 4)
f[n}
h[n}
1
1
0
n
Subfigure 3.1
1
0
Subfigure 3.2
h[-m] =
h[((-m))N]
1
n
Figure 4
h[1-m]
h[((1-m))N]
1
n
Figure 5
Page 22
DEPARTMENT OF ECE
h[2-m]
h[((2-m))N]
1
n
Figure 6
h[3-m]
h[((3-m))N]
1
n
Figure 7
Multiple [m] and sum to yield : y[3] = 1
Page 23
DEPARTMENT OF ECE
{
If(m>n)
{
for(i=n;i<m;i++)
h[i]=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
Page 24
DEPARTMENT OF ECE
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++)
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];
}
}
/*displaying the result*/
printf( the circular convolution is\n);
for(i=0;i<n;i++)
printf(%d\t,y[i]);
}
Page 25
DEPARTMENT OF ECE
PROCEDURE :
Open code computer studio, make sure the DSK kit is turned on.
Start a new project using project-new pull down menu, save it in a separate directory
(c:\ti\myprojects) with name cir conv.pjt.
Add the source files circular convolution.C.
To the project using project-> add files to project pull down menu.
Add the linker command file hello.cmd.
(path:c:\ti\tutorial\dsk6713\hello1\hello.cmd)
Add the run time support library file rts6700.lib
(path: c:\ti\c6000\cgtools\lib\rts6700.lib)
Compile the program using the project-compile pull down menu or by clicking the
shortcut icon on the left side of program window.
Build the program using the project-build pull down menu or by clicking the shortcut
icon on the left side of program window.
Load the program (iconv.out) in program memory of dsp chip using the file-load
program pull down menu.
RESULT:
IN PUT:
Eg:
OUTPUT:
x[4]={3, 2, 10}
h[4]=(1, 1, 0,0}
y[4]=(3, 5, 3, 0}
Page 26
DEPARTMENT OF ECE
Page 27
DEPARTMENT OF ECE
II.
III.
IV.
Page 28
DEPARTMENT OF ECE
Initialize Counter = 0
Initialize Output = 0, i=0
Output += coeff[N-i]*val[i]
Shift the input value by one
No
Is the loop
Cnt=order
Poll the ready bit,
When asserted
Output += coeff[0]*data
Put the data in vil arrav.
Page 29
DEPARTMENT OF ECE
Page 30
DEPARTMENT OF ECE
,-
Page 31
DEPARTMENT OF ECE
0.006489,-0.000000,0.002212,0.001345,0.000198,-0.000138,-0.00005};
Coefficients for FIR High Pass Rectangular filter:
Cutoff-400Hz
float b_rct1[31]=(0.021665,0.022076,0.020224,0.015918,0.009129,-0.000000,0.011158,
-0.023877,-0.037558,-0.051511,-0.064994,-0.077266,-0.087636,-0.095507,.100422,0.918834,
-0.100422,-0.095507,-0.087636,-0.077266,-0.0694994,-0.051511,-0.037558,-0.023877,
-0.011158,-0.00000,0.009129,0.015918,0.020224,0.022076,0.0216665};
Cutoff-800Hz
float b_rect2[31]={0.000000,-0.013457,-0.023448,-0.025402,-0.017127,0.000000,0.020933,
0.038103,0.043547,0.031399,0.000000,-0.047098,0.101609,-0.152414,0.188394,0.805541,
0.188394,-0.152414,-0.101609,0.047098,0.000000,0.031399,0.043547,0.038103,0.020933,
-0.000000,-0.017127,-0.025402,-0.023448,-0.013457,0.00000};
Cutoff-1200Hz
float b_recti3[31]={-0.020798,-0.013098,0.007416,0.024725,0.022944,-0.000000,0.028043,
-0.037087,-0.013772,0.030562,0.062393,0.045842,-0.032134,-0.148349,0.252386,0.686050,
-0.252386,-0.148349,-0.032134,0.045842,0.062393,0.030562,-0.013772,-0.037087,0.028043,
-0.000000,0.022944,0.024725,0.007416,-0.013098,-0.020798};
Coefficients for FIR High Pass Triangular filter:
Cutoff-400Hz
float b_tri1[31]=(0.000000,0.001445,0.002648,0.003127,0.002391,-0.000000,0.004383,
-0.010943,-0.019672,-0.030353,-0.042554,-0.055647,-0.068853,-0.081290,-0.092048,
0.902380,-0.092048,-0.081290,-0.068853,-0.055647,-0.042554,-0.030353,-0.019672,
-0.01943,-0.004383,-0.000000,0.002391,0.003127,0.002648,0.001445,0.000000};
Cutoff-800Hz
float b_tri2[31]={0.000000,-0.000897,-0.003126,-0.005080,-0.004567,0.000000,0.008373
0.017782,0.023225,0.018839,0.000000,-0.034539,-0.081287,-0.132092,0.175834,0.805541,
-0.175834,-0.132092,-0.081287
0.034539,0.000000,0.018839,0.023225,0.017782,0.008373,
-0.000000,-0.004567,-0.005080,-0.003126,-0.000897,0.000000};
Cutoff-1200Hz
float b_tri3[31]={0.00000,-0.00904,0.001021,0.005105,0.006317,-0.000000,0.011581,-0.017868,-0.007583,0.018931,0.042944,0.034707,-0.026541,-0.132736,0.24196,0.0708287,
-0.243196,0.132736,-0.026541,0.034704,0.042944,0.018931,-0.007583,-0.017868,-
Page 32
DEPARTMENT OF ECE
0.011581,-0.000000,0.006317,0.005105,0.001021,-0.000901,0.000000};
C PROGRAM TO IMPLEMENT FIR FILTER:
fir.c
#include filtercfg.h
#include dsk6713.h
#include dsk6713_aic23.h
float filter_Coeff[] = {0.000000,-0.001591,-0.002423,0.000000,0.005728,
0.011139,0.010502,-0.000000,-0.018003,-0.033416,-0.031505,0.00000,
0.063010,0.144802,0.220534,0.262448,0.220534,0.144802,0.063010,0.000000,
-0.031505,-0.033416,-0.018003,-0.000000,0.010502,0.011139,0.005728,
0.000000,-0.002423,-0.001591,0.000000};
static short in_buffer[100];
DSK6713_AIC23_Coding config = {\
0x0017, /*0 dsk6713_aic23_leftinvol leftline 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;
Uint32|_input, r_input,1_output, r_output;
/* Initialize the board support library, must be called first */
DSK6713_init();
Page 33
DEPARTMENT OF ECE
Page 34
DEPARTMENT OF ECE
PROCEDURE:
Switch on the DSP board.
Open the Code Composer Studio.
Create a new project
Project -> New (File Name. pjt, Eg: FIR.pjt)
Initialize on board codec.
Kindly refer the Topic Configuration of 6713 Codec using BSL
Add the given above C source file to the current project (remove codec.c source file from
the project if your have already added).
Connect the speaker jack to the input of the CRO.
Build the program.
Load the generated object file (*.out) on to Target board.
Run the program using F5.
Observe the waveform that appears on the CRO screen.
Page 35
DEPARTMENT OF ECE
RESULT:
FREQUENCY RESPONSE
High Pass FIR filter (Fc=800Hz). t
Page 36
DEPARTMENT OF ECE
Frequency in Hertz
Page 37
DEPARTMENT OF ECE
Page 38
DEPARTMENT OF ECE
EXPT.NO.4.2.a
Page 39
DEPARTMENT OF ECE
window=
1
0
1
1
b = -0.0000
-0.0352
-0.4181
-0.3164
-0.0000
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1 1 1
-0.0244 0.0279 0.0527 -0.0000 -0.0791 -0.0652 0.0978 0.3164
-0.0978 -0.0791 -0.0000 0.0527 0.0279 -0.0244 -0.0352
Page 40
DEPARTMENT OF ECE
EXPT.NO.4.2.b
Page 41
DEPARTMENT OF ECE
window= 0.0909 0.1818 0.2727 0.3636 0.4545 0.5455 0.6364 0.7273 0.8182
0.9091 1.0000 0.9091 0.8182 0.7273 0.6364 0.5455 0.4545 0.3636 0.2727
0.1818 0.0909
b = -0.0000
-0.4181
-0.0000
-0.0064
-0.2876
-0.0503
0.0102
Page 42
DEPARTMENT OF ECE
EXPT.NO.4.2.c
The implementation of narrow transition band FIR filters are very costly, as it requires
considerably more arithmetic operations and hardware components such as multipliers,
address and delay elements.
Page 43
DEPARTMENT OF ECE
H (z) =
n=0 h(n) z
-n
jw
H (e ) =
n=0 h(n) e
-jwn
15
30
45
60
75
0.9428
-0.5
90
16
-15.9
1.0067
0.058
105
0.0516
-25.7
1.08
0.67
120
0.529
-5.53
0.9426
-0.513
135
0.9426
-0.513
0.529
-5.53
150
1.08
0.67
0.0516
-25.7
165
1.0067
0.058
180
0.9428
-0.5
The magnitude vs plot of a lowpass filter is shown in figure. We find that there are ripples in
the passband and in stopband. These ripples are due to truncation of the infinite series into a finite
one. This effect known as Gibbs phenomenon, discussed in detail in section.
Design of FIR filters using windows:
The design frequency response Hd (ejw) of a filter is periodic in frequency and can be expanded in
a Fourier series. The resultant series is given by
jw
Hd (e ) =
hd (n) e-jwn
n=-
Page 44
DEPARTMENT OF ECE
where
1
hd(n) =2
H(ejw)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
N-1
Page 45
DEPARTMENT OF ECE
Page 46
DEPARTMENT OF ECE
wc
wc
hd (0) =
w cn
hd (n) =sinn
|n| > 0
hd(n) =
(n-)
=
2. Highpass filter with cutoff
frequency c
hd (n) = 1 -
|n| > 0
wc2 - wc1
3. Bandpass filter with cutoff
hd (0)=
frequencies c1 and c2
= (n -)
wc2 - wc1
hd(n) =
for n =
- sin wcn
hd(n) =
for n
wc
wc
hd (0) 1 = c
hd (n) =
for n =
for n =
= (n - )
[sin c2 (n ) sin c1 (n )]
wc2 - wc1
wc2 - wc1
hd(n) = 1 -
=n
for n =
(n - )
[sin c1 (n ) sin c2 (n )]
After multiplying window sequence w(n) with hd(n), we get a finite duration sequence h(n) that satisfies the desired magnitude
response.
LORDS INSTITUTE OF ENGINEERING & TECHNOLOGY
Page 47
DEPARTMENT OF ECE
Page 48
DEPARTMENT OF ECE
N-1
h(n) = hd(n)w(n) for all |n| <
2
N-1
= 0 for |n| >
2
The frequency response H(ejw) so the filter can be obtained by convolution of Hd(ejw) and W (ejw)
given by
1
jw
H(e ) =
2
Hd(ej)W (ej(w-))d
= Hd(ejw) * W (ejw)
Page 49
DEPARTMENT OF ECE
Because both Hd(ejw) and Wd(ejw) are periodic function, the operation often called as periodic
convolution.
The window technique is shown in figure. The desired frequency response and its Fourier
coefficients are shown in figure
shows
finite
window
sequence w(n) and its Fourier transform W(ejw). The Fourier transform of a window consists of a
central lobe and side lobes. The central lobe contains most of the energy of the window. To get
an FIR filter, the sequence h d(n) and w(n) are multiplied and a finite length non-causal sequence
shows h(n) and its Fourier transform H(ejw). The frequency
response H(ejw) is obtained using Eq. . The realizable sequence g(n) in Fig
can
be
we find that the frequency response of the filter H(ejw) depends on the frequency
response of window W(ejw). Therefore, the window, chosen for truncating the infinite impulse
response should have some desirable characteristics. They are
1.
The central lobe of the frequency response of the window should contain most of the
energy and should be narrow.
2. The highest side lobe level of the frequency response should be small.
3. The side lobes of the frequency response should decrease in energy rapidly as w tends to
Rectangular window
The rectangular window sequence is given by
wR(N) = 1 FOR (n-1) / 2 < N < (n 1) / 2
= 0 otherwise
An example is shown in figure
for N = 25
N = 25
-12
-10
-8
-6
-4
-2
10
12
Rectangular window
LORDS INSTITUTE OF ENGINEERING & TECHNOLOGY
Page 50
DEPARTMENT OF ECE
WR (ejw) =
e -jwn
n = -N 1
2
= ejw(N-1)/2 + ..+ejw + 1 + e-jw + .. + e-jw(N-1)/2
= ejw(N-1)/2 [1+e-jw ++ e-jw(N-1]
=e
jw(N-2) / 2
1 ejwN
1- e-jw
1 + + .
N-1
1 - N
= 1-
ejwN/2 (1 - e-jwN/2)
=
ejw/2 (1 - e-jw)
ejwN/2 - e-jwN/2
=
ejw/2 1 - e-jw/2
wN_
sin 2
=
sin
w_
2
Page 51
DEPARTMENT OF ECE
Nw_
2
2k_
= k or w = N where k is an
integer
2_
2_
and - N
is called the main lobe and the other lobes
N
are known as side lobes. The main lobe of the response is the portion that lies between the first
2_
two zero crossings. The side lobes are defined as the portion of the response for w < - N
2_
or
w >
. As the window is made longer the main lobe becomes narrower and
N
higher, and the side lobe become more concentrated around w = 0. The main lobe width for the
4_
rectangular window is equal toN
. The higher side lobe level is equal to approximately 22% of
the main lobe amplitude or 13dB relative to the maximum value at w = 0.
The response for w between
Page 52
DEPARTMENT OF ECE
(a) Frequency response of rectangular window N = 51 (b) log magnitude response of rectangular
window for N = 51.
Page 53
DEPARTMENT OF ECE
and
figure respectively. To get a finite impulse response filter we multiply hd(n) with a rectangular
window, i.e.,
h(n) = hd (b) wR(n)
The frequency response off the truncated filter can be obtained by periodic convolution.
1
jw
H(e ) =
2
Hd(e-jw) WR(ej(w-))d
-
From we find that the frequency response differs from the desired response in many ways. It does
not follow quick transitions in the desired response. The desired response of a lowpass filter
changes abruptly from passband to stopband, but the frequency response changes slowly. This
region of gradual change is called filters transition region, which is due to the convolution of the
desired response with the window responses main lobe. The width of the transition region
depends on width of the main lobe. As the filter length N increases, the main lobe becomes
narrower decreasing the width of the transition region.
The convolution of the desired response and the window responses sidelobes gives rise to the
ripples in both passband and stopband. The amplitude of the ripples is dictated by the amplitude
of the sidelobes. The amplitude of the ripples is dictated by the amplitude of the sidelobes. For
the rectangular window, the amplitude of the sidelobes is unaffected by the length of the window.
So increase in length N will not reduce the ripples, but increase its frequency. J.W.Gibbs showed
that a finite length lowpass filter will posses an 8.9% maximum ripple no matter how long the
filter is made. This effect where maximum ripple occurs just before and after the transition band
is known as Gibbs phenomenon.
Page 54
DEPARTMENT OF ECE
The Gibbs phenomenon can be reduced by using a less abrupt truncation of filter coefficients.
This can be achieved using a window function that tapers smoothly towards zero at both ends.
One such type of window is triangular window.
The Triangular or Barlett window
The N-point triangular window is given by
2|n|
wT(n) = 1 -
WT(ejw) =
N - 1_
sin 4
2
w
w_
sin 2
Page 55
DEPARTMENT OF ECE
From the figure we can find that triangular window produces a smooth magnitude
response in both passband and stopband. But it has the following disadvantages, when compared
to magnitude response obtained by using rectangular window.
1. The transition region is more.
2. The attenuation in stopband is less
(a) Frequency response of triangular window N = 25 (b) Log magnitude response of triangular
window for N = 25.
Page 56
DEPARTMENT OF ECE
(a) Frequency response of triangular window N = 51 (b) Log magnitude response of triangular
window for N = 51.
Page 57
DEPARTMENT OF ECE
Because of these characteristics, the triangular window is not usually a good choice.
Raised cosine window
The raised cosine window multiplies the central Fourier coefficients by approximately unity and
smoothly truncate the Fourier coefficients toward the ends of the filter.
The window sequence is of the form
2n
w(n) = + (1 ) cos
= 0 otherwise
The frequency response w(n) is given by
N-1
2
(ejw) =
n=-
N-1
+ (1 ) cos
n= -
e-jwn
2
N-1
2
2n__
N-1
N-1
2
N-1
e-jwn +
(1 )__
e-j(w-2/N-1)n
2
n = - N-1
2
(1 - )__
2 n=-
B
N-1
2
e-j(w+2/N-1)n
N-1
2
C
Page 58
DEPARTMENT OF ECE
ejw(N-1)/2 [1-e-jwN]
=
1 e-jw
ejwN/2 -e-jwN/2
=
ejwN/2 -e-jwN/2
=
e-jw/2 e-jw/2
wN
sin 2
=
w
sin2
2j
.
2j
ejw/2 e-jw/2
(1 )
[ej(w-2/(N-1)(N-1)/2 + ..+ej(w-2/(N-1) + 1
B=
2
+ e-j(w-2/(N-1))(N-1)/2 [ 1-e-j(w-2/(N-1))(N-1/2]
1
=
2
1 e-j(w-2/(n-1))
ej(w-N/2-/N((N-1)) [1 ej(w-2/(N-1))N]
=
2
1
ej(w/2-/(N-1)) [1-e-j(w-2/(N-1))]
ej(wN/2-/N((N-1)) e -j(wN/2-N/(N-1))]
=
2
ej(w/2-/(N-1)) e-j(w/2-/(N-1))]
=
2
Page 59
DEPARTMENT OF ECE
similarly
1
C=
2
sin(w/2 + / (N 1))
sin wN/2
jw
W (e ) =
+
2
(1 )
+
2
Hanning window:
The Hanning window sequence can be obtained by substituting = 0.5 in Eq.
WHn (n) = 0.5 + 0.5 cos 2n / (N-1) for (N 1)/2 < n < (N 1) / 2
The frequency response of Hanning window is
sin wN/2
jw
WHn (e ) = 0.5
2 w/2
Page 60
DEPARTMENT OF ECE
(a) Frequency response of Hanning window for N = 25 (b) Log magnitude response of Hanning
window for N = 25
Ripples in both passband and stopband of the lowpass filter designed using Hanning window.
The maximum stopband attenuation of the filter is 44 dB which is 23 dB lower than the filter
designed using rectangular window. At higher frequencies of the stopband attenuation is even
greater.
Hamming window
The equation for Hamming window can be obtained by substituting = 0.54 in Eq.
WH
(n) = 0.54 + 0.46 cos (2n / N-1 for (N 1)/2 < n < (N 1) / 2
=
0 otherwise
Page 61
DEPARTMENT OF ECE
Page 62
DEPARTMENT OF ECE
and figure
respectively. The peak side lobe level is down about 41 dB from the main lobe peak, an
improvement of 10 dB relative to the Hanning window. The magnitude and log magnitude
response of lowpass filter designed using Hamming window are shown in figure and
respectively. The first side lobe peak is -53dB, an improvement
Page 63
DEPARTMENT OF ECE
(a) Frequency response of Hamming window for N = 25 (b) Log magnitude response of
Hamming window for N = 25
of 9 dB with respect to Hanning window filter. However, at higher frequencies the stopband
attenuation is low when compared to that of Hanning window.
Page 64
DEPARTMENT OF ECE
PROGRAM:
LORDS INSTITUTE OF ENGINEERING & TECHNOLOGY
Page 65
DEPARTMENT OF ECE
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)
gain=abs(H);
an=angle(H);
subplot(2,1,1);
plot(w/pi,gain);
title(magnitude response of lpf);
xlabel(gain in db------->);
ylabel(gain in db------->);
subplot(2,1,2);
plot(w/pi,an);
title(phase response of lpf);
x-label(normalized frequency----->);
ylabel(angle-------->);
RESULT:
The magnitude and the phase response of FIR low pass filter using Blackman window is observed
& waveforms are plotted.
Page 66
DEPARTMENT OF ECE
window=
-0.0000 0.0092
0.8492
0.9602
0.2008
0.1014
b =
0.0000
-0.0000
0.3999
-0.0000
0.0000
0.0402
1.0000
0.0402
-0.0003
-0.0386
0.2906
0.0101
0.1014
0.9602
0.0092
0.2008
0.8492
-0.0000
-0.0009
-0.0430
0.0794
0.0027
0.3400
0.6892
0.0027
0.0794
-0.0430
-0.0009
0.5098
0.5098
0.6892
0.3400
0.0101
0.2906
-0.0386
-0.0003
Page 67
DEPARTMENT OF ECE
EXPT.NO.4.2.d
Page 68
DEPARTMENT OF ECE
window= 0.0800
1.0000 0.9775
0.1025 0.0800
b = -0.0000
-0.4008
-0.0000
-0.0035
-0.2695
-0.0517
0.0072
Page 69
DEPARTMENT OF ECE
EXPT.NO.4.2.e
Page 70
DEPARTMENT OF ECE
window= 0.0800 0.1025 0.1679 0.2696 0.3979 0.5400 0.6821 0.8104 0.9121
0.9775 1.0000 0.9775 0.9121 0.8104 0.6821 0.5400 0.3979 0.2696
0.1679 0.1025 0.0800
b = -0.0000
-0.4008
-0.0000
-0.0035
-0.2965
-0.0000
-0.0000
-0.0517
0.0201
Page 71
DEPARTMENT OF ECE
EXPT.NO.4.2.f
Page 72
DEPARTMENT OF ECE
window=
-0.0000 0.0092
0.8492
0.9602
-0.2008 0.1014
b = 0.0000
-0.0000
0.3999
-0.0000
0.0000
0.0402
1.0000
0.0402
-0.0003
-0.0386
0.2906
0.0101
0.1014
0.9602
0.0092
-0.0009
-0.0430
0.0794
0.0027
0.2008
0.8492
-0.0000
0.0027
0.0794
-0.0430
-0.0009
0.3400
0.6892
0.5098
0.5098
0.6892
0.3400
0.0101
0.2906
-0.0386
-0.0003
Page 73
DEPARTMENT OF ECE
INTRODUCTION:
GENERAL CONSIDERATIONS:
In the design of frequency selective filters, the desired filter characteristics are specified in the
frequency domain in terms of the desired magnitude and phase response of the filter. In the filter
design process, we determine the coefficients of a causal IIR filter that closely approximates the
desired frequency response specifications.
IMPLEMENTATION OF DISCRETE-TIME SYSTEMS:
Discrete time Linear Time-Invariant (LTI) systems can be described completely by constant
coefficient linear difference equations. Representing a system in terms of constant coefficient
linear difference equation is its time domain characterization.
frequency-selective filter, we would take help of some basic implementation methods for
realizations of LTI systems described by linear constant coefficient difference equation.
Page 74
DEPARTMENT OF ECE
BACKGROUND CONCEPTS:
An infinite impulse response (IIR) filter possesses an output response to an impulse which is of an
infinite duration. The impulse response is infinite since there is feedback in the filter, that is if
you put in an impulse, then its output must produced for infinite duration of time.
ALGORITHM TO IMPLEMENT:
We need to realize the butter worth band pass IIR filter by implementing the difference equation
y[n] = bo[n]+b1x[n-1]+ b2x[n-2]-a1y[n-1]-a2y[n-2] where b0 b2 a0 a2 are feed forward and
feedback word coefficients respectively [Assume 2nd order of filter]. These coefficients are
calculated using MATLAB.A direct form I implementation approach is taken.
Step 1 Initialize the McBSP, the DSP board and the on board codec.
Kindly refer the Topic Configuration of 6713Codec using BSL
Step 2 Initialize the discrete time system, that is, specify the initial conditions.
Generally zero initial conditions are assumed.
Step 3 Take sampled data from codec while input is fed to DSP kit from the signal
generator. Since Codec is stereo, take average of input data read from left and right
channel. Store sampled data at a memory location.
Step 4 Perform filter operation using above said difference equation and store filter
Output at a memory location.
Step 5 Output the value to codec (left channel and right channel) and view the output at
Oscilloscope.
Step 6 Go to step 3.
Page 75
DEPARTMENT OF ECE
Output = x[0]b0+x[-1]b1+
X[-2]b2 y[-1]a1 y[-2]a2
x[-1]= x[0]
poll for ready bit
Write output to analog i/o
Stop
Page 76
DEPARTMENT OF ECE
Page 77
DEPARTMENT OF ECE
DSK6713_int();
/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0,&config);
DSK6713_AIC23_setFreq(hCodec, 3);
while(1)
{
}
/* Close the codec */
DSK6713_AIC23_closeCodec(hCodec);
}
signed int IIR_FILTER(const signed int*h, signed int x 1)
{
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) x 1; /* 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) */
LORDS INSTITUTE OF ENGINEERING & TECHNOLOGY
Page 78
DEPARTMENT OF ECE
Page 79
DEPARTMENT OF ECE
Page 80
DEPARTMENT OF ECE
Page 81
DEPARTMENT OF ECE
Page 82