114 7. ADAPTIVE FILTERING
80
60
40
20
0
0 500 1000 1500 2000 2500 3000 3500 4000
Frequency (Hz)
0 500 1000 1500 2000 2500 3000 3500 4000
Frequency (Hz)
Magnitude
80
60
40
20
0
Magnitude
Figure L7.2: Filtered response.
for( i = 0; i < FIRorder; i++) {
coefficients[i] += weight*xf[FIRorder-i];
}
return firOutput;
}
When this method is initially called, the FIR filter uses a null set of filter coefficients. As each
sample of a frame is filtered, the FIR coefficients get updated.
L7.3 LAB EXERCISES
1. Use MATLAB to design an 8-order order bandpass IIR filter based on the following
specifications:
L7. LAB 7: IIR FILTERING AND ADAPTIVE FIR FILTERING 115
f=[0 0.2 0.4 0.41 1]; %frequency bands
m=[0 1 1 0 0]; %desired gain
Study the round-off error between the direct form and the second-order cascade form
using MATLAB. Use the MATLAB function tf2sos to convert the transfer function into
cascade form and then apply the filter sos as indicated below:
Z = x;
for i=1:size(sos);
Z = filter(sos(i,1:3),sos(i,4:6), Z);
end
Examine the effect of various word lengths on the output and report your observations.
Recall that you can quantize the filter by using the MATLAB fixed-point toolbox function
sfi() . For example, if coeffs denotes double precision filter coefficients, the expres-
sion 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 frac-
tional bits. Although this issue did not arise during the exercise involving FIR coefficient
quantization, it needs to be noted that the number of integer bits must be sufficient to
accommodate IIR filter coefficients whose magnitude is greater than 1.
First, compare the frequency spectra of the filtered outputs of the direct form filter based
on the quantized and unquantized coefficients. en, compare the frequency spectra of the
filtered outputs based on the direct form quantized coefficients and the quantized second-
order sections coefficients.
2. Over time, the output of the FIR filter should converge to that of the IIR filter. Confirm
this by comparing the output of the two filters or by examining the decline in the error
term. Experiment with different step size ı and filter length N and report your observa-
tions.
Next, add a delay to the adaptive FIR filtering pipeline to make the real-time processing
fail on purpose. A possible solution to address the real-time processing aspect is to up-
date only a fraction of the coefficients using the LMS equation during each iteration. For
example, you may update all even coefficients during the first iteration, and then all odd
coefficients during the second iteration. Implement such a coefficient update scheme and
report the results in terms of the tradeoff between convergence rate, convergence accuracy,
and processing time.
Hints (Android target) e function clock_gettime with CLOCK_MONOTONIC as the
time source can be used to obtain high-resolution timing. An implementation of this function
116 7. ADAPTIVE FILTERING
is provided in the Android lab source code in the form of a separate C object (Timer.c) that can
be placed within your code to provide the necessary benchmark timing. Also, the AndroidPlot
graphing library is used to display the filtering error term in real-time as an audio signal is
getting processed. e AChartEngine library is also used to display the initial N -frame error
term as shown in Figure L7.3. Graphing implementations are found in AdaptiveFilter.java and
ErrorGraphActivity.java and the dependencies are specified in the build.gradle file.
Figure L7.3: Adaptive FIR app.
Hints (iOS target) To measure the execution time taken by the signal processing pipeline,
the header file mach_time.h can be used. is header measures time in the form of a tick count,
which can be easily converted to nanoseconds. You can use this to find the execution time of
your code in Objective-C and C. To measure the execution time taken by a C code, the time.h
header file can be utilized. e function clock() defined in time.h can be used to calculate the
execution time between any two places of the code.
..................Content has been hidden....................

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