addendum-lab4_02_16_..

advertisement
ECE 3551 MICROCOMPUTER SYSTEMS 1
Addendum to Lab 4—Learn to process audio data
There is a hard restriction in VisualDSP++ Run-Library function iir_fr16 requires
“that the value of the A0 coefficient be greater than both A1 and A2 for all the
stages” of the filter. Because of MATLAB’s iir filter design algorithms are not restricted
to by this specification you can not use the library function with the given coefficients.
Thus you are required to implement you own iir_fr16 filter using the following equation
for each stage of the filter. Note that floating point implementation of the filter is not an
issue rather the fixed point implementations (full integer and fractional representations).
Full Integer Implementation:
Note that for full integer implementation to utilize the full range of the afforded precision
(e.g., short or int) you must scale the largest coefficient A0(=1), A1, A2, B0, B1, B2 to be
equal to 215 or 231. This implies the following algorithm given original matlab
coefficients a0(=1), a1, a2, b0, b1, b2, and B number of bits (B=16 for short and B=32 for
int):
AFactor  max absai 
BFactor  max absbi 
ai
2  B 1 , i  0,1,2
AFactor
bi
Bi 
2 B 1 , i  0,1,2
BFactor
AFactor B0  B1 z 1  B2 z 2
H z  
BFactor A0  A1 z 1  A2 z 2
Ai 
d m  xm   A1d m  1  A2 d m  2
d m  A0 d m
ym  B2 d m  2  B1d m  1  B0 d m
ym  BFactor * ym
Note that the last step; multiplication with the BFactor is optional since that operation
only adjusts the gain of filtered signal. Final note, the described procedure will ensure
that the maximal value of the largest absolute value coefficient will be set equal to largest
possible number of the type used (e.g., short or int).
Fractional Integer Implementation:
Fractional integer implementation requires that the floating numbers to be scaled to the
range of [1,-1] as demanded by float_to_fr16 or float_to_fr32 built in functions. This
implies the following algorithm given original matlab coefficients a0(=1), a1, a2, b0, b1,
b2:
AFactor  max absai 
BFactor  max absbi 
ai
, i  0,1,2
AFactor
bi
Bi 
, i  0,1,2
BFactor
AFactor B0  B1 z 1  B2 z 2
H z  
BFactor A0  A1 z 1  A2 z 2
Ai 
d m  xm   A1d m  1  A2 d m  2
d m  A0 d m
ym  B2 d m  2  B1d m  1  B0 d m
ym  BFactor * ym
Compared to full-integer representation the scaling factor of 2(B-1) is not needed
ensuring that the floating point number are in the fractional range of [1, -1]. Note that
1. All operations, that is “+” and “*” in this case, must be performed with built in
function for fractional arithmetic;
2. As in full-integer arithmetic multiplication with the BFactor is optional since that
operation only adjusts the gain of filtered signal.
3. Final note, the described procedure will ensure that the maximal value of the
largest absolute value coefficient will be set equal to largest possible fractional
number that is 1 or -1.
Download