Documente Academic
Documente Profesional
Documente Cultură
By:
Subhajit Banerjee Purnapatra (9674),
&
Siddharth Kumar (9663),
VIIIth Semester,
B.Tech, Electronics Engineering.
Batch 2010. ISM Dhanbad. 1
ABSTRACT:
An attempt was made to implement a digital filter on an 8-bit RISC
architecture based processor (Atmega-16). In this course, problems particularly
regarding the time intensiveness of floating point multiplications on such processors
(lacking specialized hardware multipliers unlike DSPs) were encountered. To solve
this, we designed an algorithm which reduces each such multiplication to an addition
and a product of character variables, thereby significantly reducing calculation related
delay and hence increasing the maximum achievable sampling frequency. The filter
characteristics obtained, however, exhibited significant deviation from ideal behavior.
This report presents a discussion on the optimization algorithm used, along with a
detailed analysis drawing a comparison between the optimized and ideal filter
responses under different parameters.
2
INTRODUCTION:
The concept for developing this project originated from a scrutiny of the
hardware components of the TSK 320C-6711 DSK kit. It clearly revealed that most of
the hardware used on the board is in fact superfluous with respect to the Laboratory
Assignments of the course EIC-15205. Provision for the 80 pin PCM 3003 daughter
card is an example.
In addition, the software required to operate the kit has elaborate and detailed
support for advanced implementations, again irrelevant with respect to the course. An
easier software on the other hand, can assist in a more direct approach towards
implementation, obviating the necessity for programming skills.
Put together, they present a formidable impression for the Kit and students
generally refrain from indulging into the joy of the much essential hardware
implementation of the theory of such a rich subject as DSP.
This project proposes a simple hardware based on an AVR microcontroller
(~Rs. 150) core instead of the C6711 DSP ($ 28,~Rs.1400). Using a microcontroller
instead of a microprocessor also removes the necessity of external RAM/ROM chips,
thereby minimizing hardware.
BENEFITS:
Low cost. (Rs. 1500 estimated).
Simple hardware required only for implementation of basic DSP systems. This
removes the use of superfluous hardware like special purpose chips which
often interferes with the sense of “complete understanding” of students.
Simple and user friendly software which removes the prior knowledge of even
fundamental level programming. This will help students concentrate on the
theoretical fundamentals of DSP rather than complicacy of programming.
DISADVANTAGES:
Low speed. Preliminary expectation for maximum sampling frequency =20
kHz.
Lack of actual programming support renders lesser control over hardware.
Limited to implementation of FIR and IIR filters. No provision for
implementation of advanced digital systems.
3
IMPLEMENTATION:
Control signal for
enabling sampling
ADC DAC
Microcontroller Data
Data
I O
Analog Analog
Input Output
4
Master clock input frequency up to 20 MHz
8 Kb of In System Self Programmable Flash ROM.
512 Bytes Internal SRAM.
Cost ~ Rs. 150
DAC: Converts the digital signal back to the desired filtered analog output.
Proposed implementation is through resistor ladder since it provides the fastest
conversion.
8-bit
Cost ~ Rs. 80
PC Software: A customized application is to be developed which would help
the user interface the hardware.
SPI- 3 wire “Null-Modem” configuration to be used for serial
port interface (via MAX-232 chip ~ Rs. 30).
Proposed features:
Let user choose between FIR and IIR filter modes.
Read the filter coefficients given as input. These coefficients can
be generated by MATLAB.
Read the initial condition coefficients.
Read the sampling frequency.
Inform the user if the given sampling frequency combined with
the given order, exceeds the hardware capabilities. Otherwise,
feed the above given information to the MPU for processing via
serial port interfacing (SPI).
The following algorithm implemented on the processor shall give us the filtered
output:
5
4. Perform:
y=(b[0]*x + b[1]*x_[1] + b[2]*x_[2] + … + b[m]x_[M]) - (a[1]*y_[1] +
a[2]*y_[2] + … + a[n]*y_[N])
by the following code:
y=b[0]*x;
for i=1 to max(M,N)
{
if(i<M)
y= y + b[i]*x_[i];
if(i<N)
y= y - a[i]*y_[i];
}// analogous to Direct Form-II algorithm, using one loop for
both variables
x_[1]=x; y_[1]=y;
The above algorithm was implemented on the said processor which resulted in an
extremely low sampling frequency (order of Hz). The cause was identified as follows:
1. Time consuming floating point multiplications:
While each (integer x integer) type operation required only about 3.7 µs*,
each operation of the type (float x float) required approximately 28.5 ms*.
2. Introducing each ‘if’, ‘while’ or any other branching statement produced an
unacceptably large delay of about 1 ms*.
6
3. The analog smoothing filter to be designed after the DAC, to yield the final
filtered output required its cut-off frequency to closely match that of the
implemented digital filter. Such frequent variations of analog components
become highly inconvenient.
PROPOSED SOLUTIONS:
1. Implement an alternative algorithm which requires (char × char) type
multiplication and (char + char) type addition to substitute a (float × float) type
operation.
2. Avoid using arrays, which would require usage of loops for indexing purpose. The
resulting code becomes voluminous but manages to avoid branching statements.
7
OPTIMIZATION ALGORITHM:
Our algorithm fundamentally suggests representing each filter coefficient as an
exponent of 2.
Let ……. (0≤ |M|< 10; Ex
I ), be any floating point
number. This is a familiar representation for any general value that a filter coefficient
might have.
Our objective is to first represent this number in the form of :
…… (0≤ |m|< 2; ex
I). The numbers ‘m’ and ‘ex’ can then be represented as an 8-
bit value in a character variable representation.
A similar operation is performed with the input values, thus resulting in a pair
of similar values which represents the sampled value at a particular instant of time:
(subscripts ‘b’ and ‘x’ denotes the corresponding variables they are
representing).
Now, the multiplication of two floating point values: p = b × x is reduced to
the pair of operation: p1= mb × mx and p2= exm + exx . The following example
outlines the steps involved to execute this desired conversion.
2. Let b’ = log2 |b| and s = sgn(b). Therefore, b’= 11.3240 and s=1 in this case.
3. The integral part of b’ directly gives the value of exb while the fractional part of b’
raised to the power of 2 gives the absolute value of mb. Thus:
exb = [b’]* and mb= s × 2{b’}# . In this case, exb= 11 and mb= 1.248.
5. We must consider the possibility that both exb and mb can be positive or negative.
Hence we must have provision for a sign bit when we intend to represent these
values in 8-bits. This effectively leaves us with 7-bits to perform the desired
representation.
6. Through calculations, we find that the typical values of the filter coefficients
necessary to implement a filter of 100 orders result in maximum |exb| values of
approximately 65. Hence, it can be directly represented as a signed character value
which has a range of -128≤ c < 127.
Thus, the 8-bit quantized value of exb is simply q_exb=exb .
7. In order to represent mb as an 8-bit value, we multiply it with 2(8-1) = 128 and store
the integral part of the result. Thus, q_mb= [mb × 128]* . In this case, q_mb=79.
8. We can now perform all necessary mathematical operations using the different
values of q_exb and q_mb (and similarly q_exx and q_mx) for the various
coefficients (and inputs).
PERFORMANCE ANALYSIS:
The above algorithm helps us to reduce calculation delay considerably. This is
due not only to the fact that 8-bit addition/multiplications are involved instead of
resource intensive 32-bit addition/multiplication; but also to the fact that the chosen
base of 2 enables the processor to perform multiplication faster (only involving bit
shifting).
The aspect to be analyzed now is the accuracy of the filter being implemented
itself. In a bid to improve the processing speed with limited architecture support, we
have made a trade-off by losing precision. This loss manifests itself as the
quantization error when we approximate the value of q_mb from mb, where the
fractional part of the coefficient is lost completely.
In order to study the effect of this loss on the nature of the implemented filter,
we use MATLAB to simulate the frequency response of a filter having its defining
coefficients as apx_b and apx_a (for approximate values of original zeroes ‘b’ and
poles ‘a’ respectively). They are defined as follows:
Obviously, the original filter coefficients only differ from the above,
approximated ones by the values inside the 1st bracket.
For a fixed sampling frequency, 9600 Hz, various frequency responses for a
Butterworth LPF, are plotted by altering 3 different parameters:
• Quantization bits (8, 16 and 32 corresponding to the popular architecture).
• Cutoff frequency (1.5 kHz, 2.5 kHz and 3.5 kHz).
• Order of filter (5, 15 and 25).
The graphs are presented here as follows:
9
Fig.1. Bits = 8, fc = 1.5 kHz, Order = 5 Fig.2. Bits = 8, fc = 1.5 kHz, Order = 15
Fig.3. Bits = 8, fc = 1.5 kHz, Order = 25 Fig.4. Bits = 8, fc = 2.5 kHz, Order = 5
Fig.5. Bits = 8, fc = 2.5 kHz, Order = 15 Fig.6. Bits = 8, fc = 2.5 kHz, Order = 25
10
Fig.7. Bits = 8, fc = 3.5 kHz, Order = 5 Fig.8. Bits = 8, fc = 3.5 kHz, Order = 15
Fig.9. Bits = 8, fc = 3.5 kHz, Order = 25 Fig.10. Bits = 16, fc = 1.5 kHz, Order = 5
Fig.11. Bits = 16, fc = 1.5 kHz, Order = 15 Fig.12. Bits = 16, fc = 1.5 kHz, Order = 25
11
Fig.13. Bits = 16, fc = 2.5 kHz, Order = 5 Fig.14. Bits = 16, fc = 2.5 kHz, Order = 15
Fig.15. Bits = 16, fc = 2.5 kHz, Order = 25 Fig.16. Bits = 16, fc = 3.5 kHz, Order = 5
Fig.17. Bits = 16, fc = 3.5 kHz, Order = 15 Fig.18. Bits = 16, fc = 3.5 kHz, Order = 25
12
Fig.19. Bits = 32, fc = 1.5 kHz, Order = 5 Fig.20. Bits = 32, fc = 1.5 kHz, Order = 15
Fig.21. Bits = 32, fc = 1.5 kHz, Order = 25 Fig.22. Bits = 32, fc = 2.5 kHz, Order = 5
Fig.23. Bits = 32, fc = 2.5 kHz, Order = 15 Fig.24. Bits = 32, fc = 2.5 kHz, Order = 25
13
Fig.25. Bits = 32, fc = 3.5 kHz, Order = 5 Fig.26. Bits = 32, fc = 3.5 kHz, Order = 15
14
CONCLUSION:
From the above graphs, we find that in some situations, our approximation
algorithm yields unacceptable level of deviation from the ideal filter behavior yet in
other situations, our algorithm works quite efficiently.
This inconsistent behavior of the approximated filter can be viewed as being
correlated with the three variable parameters mentioned before viz. quantization bits,
filter order and cutoff frequency. The relation is summarized below:
15