DSP Implementation Using The TMS320C6711 Demo

Report
DSP Implementation Using The
TMS320C6711 Demo
Texas
Instruments
Slide 1
Learning Objectives





Slide 2
Why process signals digitally?
Definition of a real-time application.
Why use Digital Signal Processing
processors?
What are the typical DSP algorithms?
Parameters to consider when choosing a
DSP processor.
Why go digital?


Digital signal processing techniques are
now so powerful that sometimes it is
extremely difficult, if not impossible, for
analogue signal processing to achieve
similar performance.
Examples:


Slide 3
FIR filter with linear phase.
Adaptive filters.
Why go digital?

Analogue signal processing is achieved
by using analogue components such as:




Slide 4
Resistors.
Capacitors.
Inductors.
The inherent tolerances associated with
these components, temperature, voltage
changes and mechanical vibrations can
dramatically affect the effectiveness of
the analogue circuitry.
Why go digital?

With DSP it is easy to:




Additionally DSP reduces:





Slide 5
Change applications.
Correct applications.
Update applications.
Noise susceptibility.
Chip count.
Development time.
Cost.
Power consumption.
Why NOT go digital?

High frequency signals cannot be
processed digitally because of two
reasons:


Slide 6
Analog to Digital Converters, ADC cannot
work fast enough.
The application can be too complex to be
performed in real-time.
Why do we need DSP processors?

Why not use a General Purpose
Processor (GPP) such as a Pentium
instead of a DSP processor?


Slide 8
What is the power consumption of a
Pentium and a DSP processor?
What is the cost of a Pentium and a DSP
processor?
Why do we need DSP processors?

Use a DSP processor when the following
are required:





Use a GPP processor when the following
are required:


Slide 9
Cost saving.
Smaller size.
Low power consumption.
Processing of many “high” frequency
signals in real-time.
Large memory.
Advanced operating systems.
What are the typical DSP algorithms?

The Sum of Products (SOP) is the key
element in most DSP algorithms:
Algorithm
Equation
M
Finite Impulse Response Filter
a
y(n) 
k
x( n  k )
k 0
M
Infinite Impulse Response Filter
a
y(n) 
N
k
k 0
 b y (n  k )
x ( n  k )
k
k 1
N
Convolution
 x ( k ) h( n  k )
y ( n) 
k 0
N 1
Discrete Fourier Transform
X (k ) 
 x(n) exp[ j(2 / N )nk]
n 0
Discrete Cosine Transform
Slide 10
F u  
N 1


c(u ). f ( x). cos
u2 x  1
 2N

x 0

Floating vs. Fixed point processors

Applications which require:





Need a floating point processor.
Drawback of floating point processors:



Slide 11
High precision.
Wide dynamic range.
High signal-to-noise ratio.
Ease of use.
Higher power consumption.
Can be higher cost.
Can be slower than fixed-point
counterparts and larger in size.
Floating vs. Fixed point processors


Slide 12
It is the application that dictates which
device and platform to use in order to
achieve optimum performance at a low
cost.
For educational purposes, use the
floating-point device (C6711) as it can
support both fixed and floating point
operations.
Learning Objectives



Slide 13
Introduction to Code Composer Studio
(CCS).
Introduction to the DSK.
Laboratory.
Code Composer Studio

The Code Composer Studio (CCS)
application provides an integrated
environment with the following capabilities:






Slide 14
Integrated development environment with an
editor, debugger, project manager, profiler, etc.
‘C/C++’ compiler, assembly optimiser and
linker (code generation tools).
Simulator.
Real-time operating system (DSP/BIOS™).
Real-Time Data Exchange (RTDX™) between
the Host and Target.
Real-time analysis and data visualisation.
Using CCS

Start CCS by either:

Using the desktop icon:

Start -> Programs -> Texas Instruments ->
Code Composer Studio 2 -> Code Composer
Studio.
Run cc_app.exe in c:\ti\cc\bin\

Slide 15
Troubleshooting

If the following window appears on your
screen then:


Slide 16
Check that the DSK is connected properly
and powered up.
Check if the port address and mode is correct
(See Slide 7).
Introduction to the ‘C6711 DSK



Slide 17
The ‘C6711 DSK provides a powerful,
low-cost development environment.
The DSK comes with CCS code
development tools (does not include the
simulator).
A laboratory at the end of this section
takes you through the DSK setup and
shows you how to run the confidence test
to check it is working correctly.
DSK Contents
Hardware (Schematics)



150 MHz ‘C6711 DSP
TI 16-bit A/D Converter (‘AD535)
External Memory





16M Bytes SDRAM
128K Bytes Flash ROM
LED’s
Daughter card expansion
Power Supply & Parallel Port Cable
Software

Code Generation Tools
(C Compiler, Assembler & Linker)

Code Composer Debugger
(256K program limitation)

Example Programs & S/W Utilities





Slide 18
Power-on Self Test
Flash Utility Program
Board Confidence Test
Host access via DLL
Sample Program(s)
Hardware: (1) Overview

The daughter card interface socket provides a
method for accessing most of the C6711 DSP for
hardware extension.
1.8V Power Supply
16M SDRAM
128K FLASH
Daughter Card I/F
(EMIF Connector)
Parallel
Port I/F
TMS320C6711
Power
Jack
D. Card I/F
(Periph Con.)
Power
LED
User DIP
switches
3.3V Power Supply
JTAG Header
Slide 19
‘C6711
DSP
Reset
Emulation
JTAG Header
Three User LEDs
16-bit codec (A/D & D/A)
Line Level Input (microphone)
Line Level Output (speakers)
Hardware: (2) Power On Self Test (POST)


There are three LEDs to provide the user with feedback from the
test procedure.
The test program (stored in the FLASH memory, code available
on the DSK CD-ROM) runs every time DSK is powered on and
reset.
Test
0
1
2
3
4
5
6
7
Slide 20
LED 3 LED 2
0
0
0
0
0
1
0
1
1
0
1
0
1
1
1
1
BLINK ALL
LED 1 Description
0
Start state
1
DSP internal SRAM test
0
External SDRAM test
1
DSP McBSP0 loop back test
0
External codec read/write test
1
External codec tone generation test
0
External LED and DSP timer test
1
Unused – available for future test use
All tests completed successfully
Hardware: (3) Resets
CCS Reset
 Menu selection:
DebugDSP Reset
 Resets ‘C6711 DSP
 Causes bootload
from FLASH which
overwrites internal
memory
TMS320C6711
Absolute Reset
On rare occasions you
might have to:
 Pull power jack
 Pull parallel port
Apply Power
 POST runs
Slide 21
Reset Pushbutton
 Don’t push when CCS
is running
 Does not force FULL
system reset
 To fully reset board,
pull power plug
Power On Self Test (POST)
 Counts 1 - 7
 4:
 mic input  spkr out
 5:
 sinewave  spkr out
 Don’t start CCS until end
(all 3 LEDs flash at the end)
 If switches are set to 0100, a fast version of
POST is run
Software: (1) PC Host Utilities
DSK Loader



Runs on PC host
Downloads .out file to DSK memory map
Stand alone DSK loader for when you want to bypass CCS
FLASH Programming





Slide 22
hex6x.exe
f.out h.cmd
flash.exe
f.hex
First, convert file.out to file.hex
The flash utility downloads the hex file into the on-DSK FLASH
Both programs run on the PC host.
Links\SPRA804.pdf
DSK Confidence Test

dsk6ldr.exe filename.out
dsk6xtst
Run from MSDOS prompt
Command-line utility tests proper installation of the DSK board
Additionally, it tests: Internal SRAM, SDRAM, FLASH, McBSP, Timers,
EDMA, LEDs and Audio codec
Software: (2) CCS DSK Utilities
Quick Test
Confidence Test
1. Unload any gel files already
loaded in CCS
2. Load conftest.gel
3. Run confidence tests from
GEL menu
General Extension Language (GEL):
An interpretive language that enables
you to write functions to configure the
IDE and access the target processor.
Slide 23




Run from CCS GEL menu
Defined in dsk6xinit.gel
Non-intrusive test by reading
and writing:
 LEDs
 Switches
 DSK board revision
Outputs switch values
Software: (3) DSK Help

Slide 24
DSK6711 help is available via the Help menu
in CCS.
Laboratory Exercise: DSK Hardware Setup
(1) Connect the following cables:


Parallel port.
Audio cables.
(2) Connect the power and observe the Power On SelfTest (POST) (Refer to Slide 15).
(3) Run the confidence test for the PC. There are three
methods to run this test:
(a) Run the “dsk6xtst.exe” by double-clicking on the
file in “\Code\Chapter 03 - CCS and DSK\”.
(b) Run the “dsk6xtst.exe” file from windows by
double clicking on the file in
“\ti\c6000\dsk\conftest\Host\Debug”.
(c) Open a DOS window and run the “dsk6xtst.exe”
file located in the directory above.
Slide 25
Laboratory exercise: DSK hardware setup
Notes:
 The SDRAM may take a while due to the large
amount of SDRAM on the ‘C6711 DSK.
 The CODEC test performs two operations: (1) a
1kHz tone output, and (2) an audio input to output
loopback. You must have a speaker connected to the
the output jack to hear the test.
 If the confidence test fails:
(1) Remove the power and parallel cable from the DSK.
(2) Reset your PC.
(3) Reconnect the power and the parallel cable.
(4) Invoke CCS.
Slide 26
Laboratory Exercise: Using CCS
Implement:
N 1
y
a x
i i
i 0
with:
Slide 27
ai = {40, 39, …, 1}
xi = {1, 2, …, 40}
(1) Create a working directory and copy the following
files from \Code\Chapter 03 - CCS and DSK\:
(a) lab3.cdb
(b) lab3.c
(c) lab3cfg.cmd
(2) Create a new project:
(a) Start CCS.
(b) Create a new project as shown on the following
slide.
Laboratory Exercise: Using CCS
Slide 28
Laboratory Exercise: Using CCS
(3) Add files to the project (lab3.c, lab3.cdb,
lab3cfg.cmd).
Slide 29
Laboratory Exercise: Using CCS
(4) Change the build options (compile and link):
Slide 30
Laboratory Exercise: Using CCS
(5) Build the output program (lab3.out):
(a) Build the project by:
(i) Clicking the Rebuild All
toolbar icon.
(ii) Selecting Rebuild All in
the project menu.
(b) Verify that the build output
window is complete with “0
errors, 0 warnings”:
Slide 31
Laboratory Exercise: Using CCS
(6) Load the output file lab3.out into DSP memory:
(a) The program will be automatically loaded
after each project build if the “Program Load
after Build” option is selected as shown below:
Slide 32
Laboratory Exercise: Using CCS
(6) Load the output file lab3.out into DSP memory:
(b) Load the lab3.out by selecting File:Load
Program as shown below:
Slide 33
Laboratory Exercise: Using CCS
(7) Debug and run code:
(a) Go to the beginning of the program, that is
main() by selecting Debug:Go Main.
(b) Watch variables:
(i) Select the variable (to be watched) from the
lab3.c file, right click and select “Add To
Watch Window”. If the variable is y for
instance, the following window will be
shown.
Slide 34
(ii) To add another variable to the watch select
it and then drag and drop it on to the
window.
Laboratory Exercise: Using CCS
(7) Debug and run code:
(c) CCS will automatically add the local variables:
Slide 35
Laboratory Exercise: Using CCS
(7) Debug and run code:
(d) You can run or step through the code by using
the various icons on the toolbar or use the
Debug menu:
Slide 36
Laboratory Exercise: Using CCS
(e) Stop the processor from running and watch the
variable y:
y = 0x2cdb or 11480
(8) Benchmarking and profiling code:
(a) Stop the processor, reload the code or select
Debug:Restart then select Debug:Go Main.
(b) Open a new profiling session and name it
“Session 1” and select “Profile All Functions”
by clicking the following toolbar button:
Slide 37
Laboratory Exercise: Using CCS
(8) Benchmarking and profiling code:
(c) Expand the lab3.c as shown below:
Slide 38
Laboratory Exercise: Using CCS
(8) Benchmarking and profiling code:
(d) Add a breakpoint at “for(;;);”. This can be
done by:
(i) Click the cursor on the highlighted line
below.
(ii) Click the “Add Breakpoint” toolbar
button:
Slide 39
Laboratory Exercise: Using CCS
(8) Benchmarking and profiling code:
(e) Run the program and examine the profile
window:
Slide 40
Part 2
Developing A Simple Program
Slide 41
Learning Objectives



Slide 42
Learn how to create a simple program
Learn basic debug techniques
Understand how CCS facilitates
development
Creating a New Project

Slide 43
Double-click the Code Composer Studio icon
on your desktop.
Creating a New Project





Slide 44
From the Project
menu, choose New.
In the Project Name
field, type volume1.
In the Location field,
browse to the
working folder you
created in step 1.
In the Project Type
field, select
Executable (.out).
In the Target field,
select the target you
have CCS configured
for and click Finish.
Adding Files to a Project


Choose Project→Add Files to Project.
Select volume.c and click Open.
Choose Project→Add Files to Project.



Choose Project→Add Files to Project.


Slide 45
Select Asm Source Files (*.a*, *.s*) in the
Files of type box.
Select vectors.asm and load.asm, and click
Open.
Select Linker Command File (*.cmd) in the
Files of type box.
Select volume.cmd and click Open.
Adding Files to a Project

Choose Project→Add Files to Project.
Go to the compiler library folder
(C:\ti\c6000\cgtools\lib).



In the Project View window, right-click
on volume1.pjt and select Scan All
Dependencies.

Slide 46
Select Object and Library Files (*.o*, *.lib)
in the Files of type box.
Select the rts.lib file for the target you are
configured for and click Open.
volume.h should appear under the Include
folder in the Project View window.
Adding Files to a Project


Slide 47
Expand the Project
list by clicking the +
signs next to
Project,
volume1.pjt,
Libraries, and
Source.
This list is called
the Project View.
Reviewing the Source Code




Slide 48
The processing function multiplies each value
in the input buffer by the gain and puts the
resulting values into the output buffer.
It also calls the assembly load routine, which
consumes instruction cycles based on the
processingLoad value passed to the routine.
The dataIO function in this example does not
perform any actions other than to return.
Rather than using C code to perform I/O, we
will use a Probe Point within Code Composer
Studio to read data from a file on the host into
the inp_buffer location.
Building and Running the Program


Choose Project→Rebuild All or click the
(Rebuild All) toolbar button.
By default, the .out file is built into a debug
directory located under your current project
folder.
 Choose
File→Load Program. Select the program
you just rebuilt, Volume1.out, and click Open.
 Choose View®Mixed Source/ASM.

Slide 49
This allows you to view your c source and the resulting
assembly code at the same time.
Building and Running the Program




Choose Debug→Go Main to begin execution from
the main function. The execution halts at main and
is identified by .
Choose Debug→Run or click the (Run) toolbar
button.
Choose Debug→ Halt to quit running the
program.
From the View menu,

Slide 50
choose Mixed Source/ASM. This allows you to view c
code without the assembly so you can accomplish the
next task: Changing Program Options and Fixing
Syntax errors
Changing Program Options and Fixing
Syntax Errors


Choose
Project→Build
Options.
In the Compiler tab
of the Build
Options window,

Slide 51
select Preprocessor
from the Category
list. Type FILEIO in
the Define Symbols
field. Press the Tab
key.
Changing Program Options and Fixing
Syntax Errors



Slide 52
Click OK to save your new option settings.
Choose Project→Rebuild All or click the (Rebuild
All) toolbar button. You need to rebuild all the files
whenever the project options change.
A build message indicates the program contains
compile errors. Click the Build tab and scroll up in
the Build tab area. You see a syntax error message.
Changing Program Options and Fixing
Syntax Errors

Double-click on the red text that describes the
location of the syntax error (line 68). Notice
that the volume.c source file opens, and your
cursor is on the following line:


Fix the syntax error in the line above the
cursor location (The semicolon is missing.) It
should look like this:



Slide 53
processing(input, output);
puts("begin processing");
Notice that an asterisk (*) appears next to the
filename in the Edit window's title bar,
indicating that the source file has been
modified. The asterisk disappears when the
file is saved.
Choose File→Save or press Ctrl+S to save
your changes to volume.c.
Changing Program Options and Fixing
Syntax Errors





Slide 54
Choose Project→Build or click the (Incre-mental
Build) toolbar button. Code Composer Studio
rebuilds files that have been updated.
Choose File→Load Program and select volume1.out.
Choose Debug→Go Main to begin execution from the
main function. The execution halts at main and is
identified by .
Choose Debug→Run or click the (Run) toolbar
button.
Choose Debug→ Halt to quit running the program.
Adding a Probe Point for File I/O



Slide 55
To transfer input data from a file on the
host PC to a buffer on the target for use
by the algorithm
To transfer output data from a buffer on
the target to a file on the host PC for
analysis
To update a window, such as a graph,
with data
Adding a Probe Point for File I/O



Choose File→Load Program. Select volume1.out,
and click Open.
Double-click on the volume.c file in the Project
View.
Put your cursor in the line of the main function
that says:



Click the
(Toggle Probe Point) toolbar
button. The selection margin indicates that a
probepoint has been set.
From the File menu, choose File I/O.

Slide 56
dataIO();
The File I/O dialog appears so that you can select
input and output files.
Adding a Probe Point for File I/O



Slide 57
In the File Input
tab, click Add File.
Browse to the
volume1 project
folder you created,
select sine.dat and
click Open.
In the File I/O
dialog, change the
Address to
inp_buffer and the
Length to 100. Also,
put a check mark
in the Wrap
Around box.
Adding a Probe Point for File I/O






Slide 58
Click Add Probe Point. The
Probe Points tab of the
Break/Probe Points dialog
appears.
In the Probe Point list,
highlight the line that says
VOLUME.C line 61 --> No
Connection.
In the Connect To field,
click the down arrow and
select the sine.dat file from
the list.
Click Replace. The Probe
Point list changes to show
that this Probe Point is
connected to the sine.dat
file.
Click OK. The File I/O
dialog shows that the file is
now connected to a Probe
Point.
Click OK to close the File
I/O dialog.
Displaying Graphs







Slide 59
Choose
View→Graph→Time/Frequency.
In the Graph Property Dialog,
change some of the variable
properties to the values shown
here.
Click OK. An Input graph
window for the Input Buffer
appears.
Right-click on the Input graph
window and choose Clear Display
from the pop-up menu.
Choose
View→Graph→Time/Frequency
again.
This time, change the Graph Title
to Output and the Start Address
to out_buffer. All the other
settings are correct.
Click OK to display the Output
graph window.
Animating the Program and Graphs





Slide 60
In the volume.c window, put your cursor in the
line that calls dataIO.
Click the (Toggle Breakpoint) toolbar button
or press F9. A red icon is placed in the selection
margin to represent the breakpoint.
Arrange the windows so that you can see both
graphs.
Click the
(Animate) toolbar button or press
F12 to run the program.
Each time the Probe Point is reached, Code
Composer Studio gets 100 values from the
sine.dat file and writes them to the inp_buffer
address.
Animating the Program and Graphs
Choose Debug→Halt to quit running the program.
Slide 61
Adjusting the Gain



Slide 62
Choose View→Watch Window and select the
Watch1 tab.
Click on the expression icon
in the Name
column and type gain as the name of the variable
to watch.
Click on the white space in the watch window to
save the change. The value should immediately
appear as in the following example.
Adjusting the Gain




Slide 63
If you have halted the program, click the
(Animate) toolbar button to restart the program.
Observe the input and output graph you created
earlier.
From the Debug menu, choose Halt.
In the Watch Window, select the value of gain (1)
and change it to 10.
From the Debug menu, choose Animate. Notice
that the amplitude of the signal in the Output
graph changes to reflect the increased gain as in
the following example:
Adjusting the Gain



Slide 64
From the Debug menu, choose Halt.
From the Project menu, choose Close.
Close all other windows and graphs.
Part 3
Finite Impulse Response (FIR) Filters
Slide 65
Learning Objectives

Introduction to the theory behind FIR
filters:




Slide 66
Properties (including aliasing).
Coefficient calculation.
Structure selection.
Implementation in Matlab and C.
Introduction



Slide 67
Amongst all the obvious advantages that
digital filters offer, the FIR filter can
guarantee linear phase characteristics.
Neither analogue or IIR filters can achieve
this.
There are many commercially available
software packages for filter design.
However, without basic theoretical
knowledge of the FIR filter, it will be
difficult to use them.
Properties of an FIR Filter

Filter coefficients:
N 1
yn   bk  xn  k 
k 0
x[n]
bk
y[n]
N
Slide 68
represents the filter input,
represents the filter coefficients,
represents the filter output,
is the number of filter coefficients
(order of the filter).
Properties of an FIR Filter

Filter coefficients:
N 1
yn   bk  xn  k 
k 0
-1
z
x(n)
x
b0
-1
z
x
+
b1
-1
z
x
b2
+
Filter structure
Slide 69
FIR equation
-1
z
x
+
bN -1
y(n)
Properties of an FIR Filter

Filter coefficients:
N 1
yn   bk  xn  k 
k 0

If the signal x[n] is replaced by an impulse
[n] then:
N 1
yn   bk  n  k 
k 0
y0  b0 0  b1  1    bk   N 
Slide 70
Properties of an FIR Filter

Filter coefficients:
N 1
yn   bk  xn  k 
k 0

If the signal x[n] is replaced by an impulse
[n] then:
N 1
yn   bk  n  k 
k 0
yn  b0 n  b1 n  1    bk  n  N 
Slide 71
Properties of an FIR Filter

Filter coefficients:
N 1
yn   bk  xn  k 
k 0

If the signal x[n] is replaced by an impulse
[n] then:
N 1
yn   bk  n  k 
k 0
1 for n  k
 n  k   
0 for n  k
Slide 72
Properties of an FIR Filter

Filter coefficients:
N 1
yn   bk  xn  k 
k 0

Finally:
b0  h0
b1  h1

bk  hk 
Slide 73
Properties of an FIR Filter

Filter coefficients:
N 1
yn   bk  xn  k 
k 0
With:

Slide 74
bk  hk 
The coefficients of a filter are the same as
the impulse response samples of the filter.
Frequency Response of an FIR Filter

By taking the z-transform of h[n], H(z):
N 1
H z    hnz  n
n0

Replacing z by e-j in order to find the
frequency response leads to:
N 1
H z  z  e   H     hne  jn 
j
n0
Slide 75
Frequency Response of an FIR Filter

Since e-j2k = 1 then:
N 1
H   2    hne
n0

 jn   2 
N 1
 hne  jn 
n 0
Therefore:
H   2k   H  

Slide 76
FIR filters have a periodic frequency
response and the period is 2.
Frequency Response of an FIR Filter

Frequency response:
y[n]
y[n]
FIR
x[n]
x[n]
H   2   H  
Freq
Fs/2
Slide 77
Freq
Fs/2
Frequency Response of an FIR Filter

Solution: Use an anti-aliasing filter.
x(t)
ADC
x[n]
FIR
y[n]
x(t)
y[n]
Analogue
Anti-Aliasing
Fs/2
Slide 78
Freq
Fs/2
Freq
Phase Linearity of an FIR Filter

A causal FIR filter whose impulse
response is symmetrical is guaranteed to
have a linear phase response.
h(n)
h(n)
N = 2n + 2
N = 2n + 1
n
0
1
n
n+1
2n 2n+1
Even symmetry
Slide 79
n
0
1
n-1
n
n+1
2n-1 2n
Odd symmetry
Phase Linearity of an FIR Filter

A causal FIR filter whose impulse
response is symmetrical (ie h[n] = h[N-1-n]
for n = 0, 1, …, N-1) is guaranteed to have
a linear phase response.
Condition
hn   hN  n  1
Positive Symmetry
Slide 80


Phase  k  
k
N 1

2 
Phase Property
Filter Type
Odd Symmetry – Type 1
Linear phase
Even Symmetry – Type 2
Phase Linearity of an FIR Filter

Application of 90° linear phase shift:
I
90
o
IH
+
Reverse
Signal
separation
Q
I  A cos f t  B sinr t
Q  A sin f t  B cosr t
Slide 81
delay
+
delay
-
90o
Forward
QH
+




IH  A cos  f t    B sin r t  
2
2


  A sin f t  B cosr t
IH  Q  2 B cosr t
QH  I  2B sin f t
Design Procedure

To fully design and implement a filter five
steps are required:
(1)
(2)
(3)
(4)
(5)
Slide 82
Filter specification.
Coefficient calculation.
Structure selection.
Simulation (optional).
Implementation.
Filter Specification - Step 1
| H(f)|
pass-band
stop-band
1
fc : cut-off frequency
f(norm)
fs/2
(a)
| H(f)|
(dB)
pass-band
transition band
| H(f)|
(linear)
stop-band
p
1  
1  
p
pass-band
ripple
-3
stop-band
ripple
s
fsb : stop-band frequency
fc : cut-off frequency
fpb : pass-band frequency
(b)
Slide 83
p
1
0

fs/2
s
f(norm)
Coefficient Calculation - Step 2

There are several different methods
available, the most popular are:




Slide 84
Window method.
Frequency sampling.
Parks-McClellan.
We will just consider the window method.
Window Method


First stage of this method is to calculate
the coefficients of the ideal filter.
This is calculated as follows:
1
hd n  
2

1
2


H  e jn d

c

1  e jn d
 c
 2 f c sinn c 


n c

2 fc
Slide 85
for n  0
for n  0
Window Method

Second stage of this method is to select a window
function based on the passband or attenuation
specifications, then determine the filter length based on
the required width of the transition band.
Window Type
Rectangular
Hanning
Normalised Transition
Width (f(Hz))
Stopband Attenuation
(dB)
0.7416
21
0.0546
44
0.9
N
3 .1
N
Hamming
3.3
N
0.0194
53
Blackman
5.5
N
0.0017
74
0.0274
50
0.000275
90
Kaiser
2.93
   4.54
N
5.71
   8.96
N
Using the Hamming
Window:
Slide 86
Passband Ripple(dB)
N
3. 3
3 .3

 8kHz  132
1.2  1.4kHz
f
Window Method

The third stage is to calculate the set of
truncated or windowed impulse response
coefficients, h[n]:
hn   hd n   W n 
Where:
Slide 87

for
N 1
N 1
n
for N  odd
2
2
N
N
for N  even
 n
2
2
 2n 
W n   0.54  0.46 cos

 N 
 2n 
 0.54  0.46 cos

 133 
for
66  n  66
Window Method

Matlab code for calculating coefficients:
close all;
clear all;
fc = 8000/44100;
N = 133;
n = -((N-1)/2):((N-1)/2);
n = n+(n==0)*eps;
% cut-off frequency
% number of taps
[h] = sin(n*2*pi*fc)./(n*pi);
[w] = 0.54 + 0.46*cos(2*pi*n/N);
d = h.*w;
% generate sequence of ideal coefficients
% generate window function
% window the ideal coefficients
[g,f] = freqz(d,1,512,44100);
% transform into frequency domain for plotting
figure(1)
plot(f,20*log10(abs(g)));
axis([0 2*10^4 -70 10]);
% plot transfer function
figure(2);
stem(d);
xlabel('Coefficient number');
ylabel ('Value');
title('Truncated Impulse Response');
figure(3)
freqz(d,1,512,44100);
axis([0 2*10^4 -70 10]);
Slide 88
% avoiding division by zero
% plot coefficient values
% use freqz to plot magnitude and phase response
Window Method
Truncated Impulse Response
0.4
0.3
Value
0.2
0.1
0
Magnitude (dB)
-0.1
0
20
40
60
80
Coefficient number
100
120
140
0
-20
-40
-60
0
0.2
0.4
0.6
0.8
1
1.2
Frequency (Hz)
1.4
1.6
1.8
x 10
Phase (degrees)
0
-2000
-4000
-6000
Slide 89
2
4
0
0.5
1
Frequency (Hz)
1.5
2
4
x 10
Realisation Structure Selection - Step 3

Direct form structure for an FIR filter:
N 1
H z    bk z  k
k 0
yn   b0 xn   b1 xn  1  ....  bN 1 xn  N  1
Y z   H z   X z 
x(n)
z
-1
z
b
z
b
0
-1
b
1
+
Slide 90
-1
b
2
+
+
N-1
y(n)
Realisation Structure Selection - Step 3

Direct form structure for an FIR filter:
N 1
H z    bk z  k
k 0

Linear phase structures:

N even:
N
1
2




H z    bk z  k  z N  k 1
k 0

N Odd:
N 1
2
H z    bk z  k  z N  k 1  b N 1 z
k 0
Slide 91
2

N 1
2
Realisation Structure Selection - Step 3
(a) N even.
(b) N odd.
z
-1
z
-1
z
-1
z
-1
z
-1
b0
+
b1
+
b2
+
b N/2-1
+
+
+
+
y(n)
(a)
x(n)
z
-1
z
-1
z
-1
z
-1
z
-1
z
-1
+
+
+
b0
b1
b2
+
+
b(N-1)/2
+
y(n)
+
(b)
Slide 92
b(N-3)/2
+
Realisation Structure Selection - Step 3

Direct form structure for an FIR filter:
N 1
H z    bk z  k
k 0

Cascade structures:
N 1
H z    bk z  k  b0  b1 z 1  b2 z  2  ...  bN 1 z   N 1
k 0
 b1 1 b2  2
bN 1   N 1 
 b0 1  z  z  ... 
z

b
b
b
0
0
0


M

 b0  1  bk ,1 z 1  bk , 2 z  2
k 1
Slide 93

Realisation Structure Selection - Step 3

Direct form structure for an FIR filter:
N 1
H z    bk z  k
k 0

Cascade structures:
x(n)
b0
+
z -1
b 1,1
z -1
z -1
+
b 2,1
z -1
b 1,2
Slide 94
+
+
z -1
b
+
M,1
z -1
b 2,2
b
M,2
+
y(n)
Implementation - Step 5

Implementation procedure in ‘C’ with
fixed-point:

Set up the codec (\Links\CodecSetup.pdf).

Transform:
N 1
yn   bk  xn  k 
to ‘C’ code.
k 0


Slide 95
(\Links\FIRFixed.pdf)
Configure timer 1 to generate an interrupt at
8000Hz (\Links\TimerSetup.pdf).
Set the interrupt generator to generate an
interrupt to invoke the Interrupt Service
Routine (ISR) (\Links\InterruptSetup.pdf).
Implementation - Step 5

Implementation procedure in ‘C’ with
floating-point:
Same set up as fixed-point plus:




Slide 96
Convert the input signal to floating-point
format.
Convert the coefficients to floating-point
format.
With floating-point multiplications there is
no need for the shift required when using
Q15 format.
See \Links\FIRFloat.pdf
Implementation - Step 5

Implementation procedure in assembly:
Same set up as fixed-point, however:

N 1
yn   bk  xn  k 
is written in assembly.
k 0
(\Links\FIRFixedAsm.pdf)

Slide 97
The ISR is now declared as external.

similar documents