106 6. REAL-TIME FILTERING
printf("A: %d,B: %d,C: %d,Status: %#010x ", A, B, result, status);
A = 10;
B = 11;
status = addGetStatus(A, B, &result);
printf("A: %d,B: %d,C: %d,Status: %#010x ", A, B, result, status);
A = -10;
B = -10;
status = addGetStatus(A, B, &result);
printf("A: %d,B: %d,C: %d,Status: %#010x ", A, B, result, status);
A = 100;
B = -1000;
status = addGetStatus(A, B, &result);
printf("A: %d,B: %d,C: %d,Status: %#010x ", A, B, result, status);
A = -100;
B = -32768;
status = addGetStatus(A, B, &result);
printf("A: %d,B: %d,C: %d,Status: %#010x ", A, B, result, status);
A = 32767;
B = 1000;
status = addGetStatus(A, B, &result);
printf("A: %d,B: %d,C: %d,Status: %#010x ", A, B, result, status);
e first half-byte of the status word copied from the APSR contains the NZCV (negative,
zero, carry, and overflow) bit flags. e outcome from the test cases is shown in Figures L6.2 and
L6.3. e first hexadecimal character corresponds to the bits of the NZCV flags. For the case
of 2
15
1 C 2
15
1 (the largest positive value represented by Q15 numbers), one can see the
resulting status of 0x9 or binary 1001. is means that the result became negative and produced
an overflow.
L6.3 LAB EXERCISES
1. Use the MATLAB code below to design an FIR filter based on the specifications noted.
is filter is obtained using a different design method than the one mentioned above via
the fir2() function of MATLAB. Refer to the MATLAB documentation on how to use
this function.
L6. LAB 6: REAL-TIME FIR FILTERING, QUANTIZATION EFFECT, AND OVERFLOW 107
Figure L6.2: LogCat screen.
Figure L6.3: Output values.
f = [0 600 1000 1400 2000 4000]; %frequencies (0 to nyquist)
a = [1.25 2 1 .25 0.1 0]; %desired amplitude response
order = 31;
%filter order N
Next, quantize the filter by using the MATLAB fixed-point toolbox func-
tion sfi(). For example, if coeffs denotes double precision filter coefficients,
ficoeffs = sfi(coeffs,bits,bits-intgr-1) can be used to convert to quan-
tized values with bits denoting wordlength, intgr integer bits, and intgr-1
fractional bits. If the magnitude of any of the coefficients is greater than or equal to 1, an
108 6. REAL-TIME FILTERING
appropriate amount of integer bits needs to be used. To retrieve quantized coefficients,
the function ficoeffs.data can be used.
Test your filter using the signal: chirp(t,0,ts*ns,fs/2) with ns equal to 256 sam-
ples. Determine the minimum number of bits needed to represent the coefficients such
that the maximum absolute error of the filter in the frequency domain is less than five per-
cent, i.e., the comparison should be between the frequency spectrum of the filtered output
based on the quantized filter output and the double precision unquantized filter output.
2. Implement the filter designed above in C using 16-bit short values for the coefficients
as well as for the input samples. All computations are to be performed using fixed-point
representation.
e filter output may get overflowed due to the multiplications and summations involved
in the FIR filtering equation. Develop a scheme to detect such overflows and implement
a prevention measure. e most effective way to avoid overflows is by scaling down the
input signal magnitude before filtering and then reversing the scaling when the output is
returned. Keep scaling the input signal samples by a scaling factor less than one (a scaling
factor of 1/2 can be achieved simply by right shifting) until the overflow disappears.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.206.169