Instructions
Do Adaptive notches filter using MATLAB
It will be MATLAB based right, without using filter functions
Please check attached file
........................................................................................................................................................................
Attachment 1;
Page 1 of 3
ECE 529, Spring 2019
Mini-Project #1: Adaptive Filtering
Due Thu. Nov. 14 at 5:00 p.m. MST
Do not use any existing adaptive filtering functions for this assignment. Instead, write your own
source code.
Part 1: Adaptive Notch Filter
Implement an adaptive notch filter to reduce additive, sinusoidal noise that is interfering with a
desired signal. Assume the frequency of the sinusoidal noise is unknown and slowly varying. A
second-order IIR notch filter (a.k.a. bandstop filter) has transfer function,
π»π»(π§π§) = οΏ½1 β ππππππ0π§π§β1οΏ½οΏ½1 β ππβππππ0π§π§β1οΏ½
(1 β ππππππππ0π§π§β1)(1 β ππππβππππ0π§π§β1) = 1 + πππ§π§β1 + π§π§β2
1 + πππππ§π§β1 + ππ2π§π§β2
where ππ = β2 cos ππ0 and 0 β€ ππ β€ 1. The corresponding difference equation is
π¦π¦(ππ) = π₯π₯(ππ) + ππ π₯π₯(ππ β 1) + π₯π₯(ππ β 2) β ππ ππ π¦π¦(ππ β 1) β ππ2 π¦π¦(ππ β 2) (Eq. 1)
The notch is centered at digital frequency ππ0. The notch becomes sharper as ππ approaches 1.
We can adapt the notch frequency automatically by solving for the value of ππ0 that minimizes
the power in the output signal. (If the frequency is selected correctly, then the sinusoidal noise
will be canceled, thereby minimizing the output power.) Set ππ to a fixed value. If the noise
frequency varies over a narrow range, then ππ should be set closer to 1 in order to generate a
sharper notch. If the frequency varies over a larger range, then ππ should be set to a smaller
value.
Define the error signal to be ππ(ππ) = π¦π¦(ππ) β π π (ππ). We want to adapt the filter in order to
minimize the power in the error signal. Assuming that the signal and noise are uncorrelated, we
can equivalently adapt the filter to minimize the total output power, π¦π¦2(ππ). The traditional
gradient descent method requires knowing the derivative of the output power, which we
calculate as 2π¦π¦(ππ)
ππππ(ππ)
ππππ . And ππππ(ππ)
ππππ can be obtained by differentiating Eq. 1, which gives us
ππππ(ππ)
ππππ β π₯π₯(ππ β 1) β ππ π¦π¦(ππ β 1)
If we use this in a gradient descent iteration to update the value of ππ, then we have
ππ(ππ + 1) = ππ(ππ) β ππ π¦π¦(ππ)
ππππ(ππ)
ππππ
ππ(ππ + 1) = ππ(ππ) β ππ π¦π¦(ππ) [π₯π₯(ππ β 1) β ππ π¦π¦(ππ β 1)] (Eq. 4)
Page 2 of 3
where ππ is a very small constant that serves as a convergence factor. Since ππ = β2 cos ππ0, we
should impose a constraint that β2 β€ ππ β€ 2. Initialize the value to be ππ = β2 cos(ππβ2) = 0. If
the update equation yields |ππ| > 2, then we should reset ππ(ππ) = 0.
(a) Implement a computer simulation of an adaptive notch filter, using Eq. 1 to perform the
filtering and using Eq. 4 to update the value of ππ at each iteration. Add some sinusoidal
interference π£π£(ππ) to a desired signal π π (ππ) to obtain an input signal π₯π₯(ππ) to experiment
with. Here are some helpful MATLAB functions:
rng(1); % set the seed for the random number generator
v = randn(N,1); % generate N samples of pseudorandom white Gaussian noise
To convert white Gaussian noise to βcoloredβ noise having a limited bandwidth, one
method is to send the white Gaussian noise through a lowpass filter, such as
π»π»(π§π§) = 1 + π§π§β1
1 β ππ1π§π§β1
where β1 < ππ1 < 1. For example, ππ1 = 0.9 does lots of smoothing and ππ1 = β0.9 does
very little. Note: filtering the signal will affect the signal power.
Scale the signal components to achieve a reasonable signal-to-noise ratio (e.g., 0 dB to
30 dB):
SNR = 20 log10( var(π π (ππ)) / var(π£π£(ππ) )
However, for debugging purposes, you may want to try omitting π π (ππ) to see if the filter
can cancel the sinusoidal interference for the noise-only case. Try various fixed values of
ππ (e.g., 0.0005 to 0.05) and ππ (e. g. , 0.85 to 0.98). Investigate whether the bandwidth of
π₯π₯(ππ) (i.e., the amount of high-frequency components) affects the effectiveness of the
filtering. Plot βππ versus ππβ and βππ2(ππ) versus ππβ, where ππ(ππ) = π¦π¦(ππ) β π π (ππ). Show how
the plots are affected if you change the value of ππ. Discuss what happens when you vary
ππ, ππ0, and the bandwidth of π₯π₯(ππ). Plot the final 256 samples of π π (ππ), π₯π₯(ππ), and π¦π¦(ππ).
Also compare plots of the magnitude Fourier transform of the last 256 samples of π₯π₯(ππ)
and π¦π¦(ππ). For example, in MATLAB you can use Xmag = abs(fft(x)).
(b) Modify the sinusoidal noise so that its frequency is slowly varying rather than fixed.
Show how that affects the effectiveness of the adaptive filter. Note that the
instantaneous frequency of cos(2ππππ(π‘π‘)) is ππππβππππ.
Page 3 of 3
Part 2: LMS Adaptive Filter
Learn about the adaptive LMS filter by consulting various external references. For example, you
could start with Wikipedia: Least mean squares filter and consult its references for further
information, or just google to find numerous useful tutorials. Also learn about βadaptive noise
cancellation,β which is a well-known application of the LMS filter.
Implement a computer simulation of the LMS adaptive filter, and apply it to an adaptive noise
cancellation problem. Show experimental results and discuss how the adaptive filter performs.
Include plots showing how the performance varies as you vary the convergence factor, the filter
length, and any other parameters. Be sure to vary the bandwidth of the noise to see how that
affects the performance of the adaptive filter.