An Adaptive Algorithm Developed By Widrow

Print   

02 Nov 2017

Disclaimer:
This essay has been written and submitted by students and is not an example of our work. Please click this link to view samples of our professional work witten by our professional essay writers. Any opinions, findings, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of EssayCompany.

A quick and simple graphical method can be used to design a filter and validate the design using MATLAB the design can then be scaled up to higher order structures, and then implemented in real-time.

An adaptive algorithm developed by Widrow known as the LMS algorithm can control a filter coefficients to a dynamic environment.

Introduction

This report will cover the design of an IIR Notch filter using the Pole/Zero placement design method, and the analysis of an adaptive filter based on the LMS Widrow algorithm.

Notch filter design

Table 1.1 Filter specification

Frequency notch, fN.

50Hz

Frequency sampling, Fs.

8KHz

Bandwidth, Bw.

5Hz

Theory

A graphical method is used to compute the filter coefficients [1], the transfer function of a second order filter is given in equation 1.1 the design requires the computation of the coefficients a(k) and b(k).

\* MERGEFORMAT (.)

Design equations

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

The bandwidth of the filter is controlled by the poles

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

Where the pole magnitudes, are given by the value of R.

Now the design equations have given the values of the poles and zeros as shown below.

From equation 1.9 the poles and zeros are given below:

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

Figure 1.1 Z-plane showing complex conjugate poles and zeros of the IIR notch filter.

Now a discrete system can in general be described by its transfer function as shown in equation 1.12.

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

From equation 1.13 the location of zeros are place on the unit circle of the z-plane at the points + pi/80 and – pi/80, a complex conjugate pair, and the poles are also place at the same angle with magnitude R, note the magnitude of R determines the bandwidth of the filter.

Now with algebraic manipulation the filter coefficients can be computed.

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

Now divide by top and bottom of equation.

\* MERGEFORMAT (.)

From equation (1.13) the coefficients are

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

Note the highest power is z-2 in the transfer function H(z), therefore a 2nd order filter, it is possible to implement this filter using a minimum of delay elements with a canonical structure as shown below.

Figure 1.2 Second order canonical filter structure.

Testing the Notch Filter

MATLAB is used to determine the frequency response of the filter and to confirm the notch frequency.

The MATLAB generated frequency and phase response of the notch filter is shown below in figure 1.3 and figure 1.4. (The MATLAB code is listed in appendix A).

Figure 1.3 Notch filter frequency response.

Figure 1.4 Notch filter phase response.

A test signal will be applied to the filter, composed of two waveforms, one at 50Hz and the other at 120Hz, the magnitude spectrum of these two input test signals is shown in figure 1.5.

An input signalis applied to the filter where is given by

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

MATLAB generated magnitude spectrum of the Notch filter test signal.

Figure 1.5 Magnitude spectrum of Notch filter showing input and output.

The input signal has two components one at 50Hz and the other at 120Hz; these will now be applied as the input signal to the digital notch filter, the output of the filter y(n) for unknown reason has not attenuated the signal at the notch frequency even though the frequency response of the filter does indicate a notch at that frequency.

Due to time constraints it has not been possible to resolve this problem.

Real time C implementation

The objective now is to take the designed second order IIR notch filter and develop a C program in order to test the filter in a real time environment using the Texas Instruments real time development board TMS1320C DSK.

Figure 1.6 Second order filter structure.

The IIR filter will be implemented in real time using Texas Instruments TMS1320C DSK development board.

Algorithm design

Using the following method starting with the C algorithm:

Let w0=w1=w2=O

Read a sample x

Calculate w0

w0= x - a1w1 - a2w2

y= w0 + b1w1 + b2w2

Shift

w2 = w1

w1 = w0

Send y out

Repeat at 1.

Develop C function

From the algorithm a C function is created based on a second order structure.

Double SOS (double *a, double *b, double *w, double x)

{

Double y;

W [0] = x – a [1] * W [1] – a [2] * W [2];

Y = b [0] * W [0] + b [1] * W [1] + b [2] * W [2];

W [2] = W [1];

W [1] = W [0];

Return (y);

}

Transferring the C function to Texas Instruments TMS1320C DSK.

Due to time constraint it has not been possible to transfer the C function to the TMS1320C DSK environment for real time implementation.

Introduction adaptive filtering

The adaptive LMS Widrow algorithm was developed by Widrow [2]

The performance of an adaptive filter using the adaptive LMS algorithm will be investigated using MATLAB, in a noise cancellation application. The analysis begins by using the Wiener filter model, the block diagram is shown in figure 1.6. The objective is to minimize the output error signal e (n) by using feedback. The mathematics that follows describes how this is achieved.

Figure 1.7 Wiener filter

Adaptive noise cancellation configuration.

\* MERGEFORMAT (.)

Where the filter is an FIR filter then:

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

Where MSE

\* MERGEFORMAT (.)

Now taking the derivative of with respect to

Wiener-Hopf equation

\* MERGEFORMAT (.)

From the Wiener-Hopf equation the optimum coefficients that minimizes the MSE is found by using and the respective auto-correlation and cross-correlation coefficients.

The Wiener-Hopf equation (1.22) forms the basis of adaptive filter as used in the LMS algorithm, the drawback is that it requires the values of the correlation functions as this is not possible in a real-time application, this leads onto the LMS Widrow algorithm.

LMS Widrow algorithm

Figure 1.7 shows a block diagram of an adaptive filter that uses the LMS algorithm in a noise cancellation application, where d(n) is the noise affected signal which contains the wanted signal, represented by s(n), and the interfering noise, given by v(n). There is a reference signal x (n), which is highly correlated to v (n) the noise.

Figure 1.8 Basic LMS Widrow adaptive filter.

Figure 1.9 LMS Widrow filter used in noise cancellation process.

[3] The adaptive filter has two main parts, the FIR digital filter with coefficients that can be adjusted and the adaptive LMS algorithm that controls the value or the updating of the coefficients of the FIR filter. The input and delayed signal d (n) and d (n-D) are both applied at the same time to the filter. Because of the delaying d (n), d (n-D) are less correlated with each other while it is still correlated with the noise. The delayed input, d (n-D), will be processed by the filter to generate an estimate signal of the noise, y (n). This estimation

LMS Algorithm

The LMS algorithm is based on the steepest descent algorithm the main difference being the LMS uses the instantaneous values of the correlation coefficients as opposed to the steepest descent that still uses the correlation values.

Derivation of LMS algorithm from steepest descent algorithm

Steepest descent algorithm

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

Instead of using and , we use their instantaneous values.

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

Theory adaptive filter

The wanted signal, e(n), will be obtained by the subtraction of the filter output, y(n), from the noise contaminated input , d(n):

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

\* MERGEFORMAT (.)

For an desired signal that is not correlated with the noise, s(n) and v(n) will then be uncorrelated. And then s(n) and y(n) are also uncorrelated.

If the adaptive filter is adjusted towards an optimum, the noise and the total output power will then be minimized. The wanted signal, is not affected by the adjustments where s(n) is not correlated with v(n). Therefore.

The S/N ratio in the desired output will be maximized and the filter has adaptively learned to generate the noise (i.e. y(n) ï‚» v(n)).

FIR Filter

The filter used in the noise cancellation process is realized using a FIR, The FIR filter is selected for its simplicity and stability. Figure 1.27 shows the FIR filter.

This filter produces the estimation of the noise as, which is y(n), and its output is given by

\* MERGEFORMAT (.)

Where b (k) are the updateable coefficients of the filter, and x[n] and y[n] are the input and the output of the filter, respectively.

Figure 1.10 FIR filter structure.

Adaptive algorithms

In the adaptive noise cancelation filter, as shown in Figure 1.9, the coefficients of the filter are updated using the LMS adaptive algorithm. This updating is carried out such that the estimate of the wanted output signal, e(n), is then minimized in accordance to the LMS criterion.

LMS Algorithm

The LMS algorithm tries to minimize the MSE value based on steepest decent algorithm where the weight vectors will be updated on a sample by sample basis as follows:

The coefficient values which are obtained by the LMS algorithm will be an estimate only and should improve over time, when the filter can learn the features of the input signals. For improved performance it will be required that the coefficient values must converge to the optimum value, , which the rate is governed by mu. In a real situation, B(k) will not reach the theoretical optimum solution, but will fluctuates around it.

Results

The adaptive filter is now tested using MATLAB; the wanted signal is shown in figure

Figure 1.11The wanted signal is shown prior to being contaminated by noise.

Using MATLAB the wanted signal is now contaminated by noise and shown as noisy signal in figure, the power spectrum of the wanted signal and the contaminated signal is also shown, and the output error signal (wanted signal) is shown with its corresponding power spectrum which shows it as a single component.

Figure 1.12 The power spectrum of the noisy signal and error signal.

It can be seen it takes about 40 samples for the error signal to converge to estimate the wanted signal accurately, the convergence factor Mu governs the rate at which the convergence occurs, the Mu value was 0.01 for the above cleared signal.

The output will now be considered for different values of Mu.

Figure 1.13 Shows the cleared signal given when the Mu values are at 0.02 if you compare it to the error signal of figure 1.12 it can be seen that the wanted signal has converged a bit quicker than at mu=0.01.

Figure 1.14 Shows the output cleared signal given when the Mu value is at 0.03.

Figure 1.15 Shows the output cleared signal given when the Mu value is at 0.04.

Conclusion

A simple technique used to design a digital filter is by using poles and zeros, by placing them where a required peak or null is wanted on the complex z-plane this method is quick and can provide a simple design if the design is more complex or the filter order is large it would be better to use a program such as MATLAB to complete design.

The poles and zeros method does give useful insight into the operation of filters.

It is also possible to design higher order filters by cascading many second order filters together, these filters can be implemented in a real time environment by developing C algorithms and corresponding C functions providing the operations can be carried within the speed of the DSP processor.

An adaptive filter is dynamic as it adapts itself to changing channel or signal conditions, care must be taken to ensure the adaptive algorithm can operate in a real time application.

Appendix A MATLAB code listings

Notch filter frequency response

clear;

Fs=8000;

R=0.998;

b1=2*cos(pi/80);

a1=2*R*cos(pi/80);

a2=R*R;

b=[1,-b1,1];

a=[1,-a1,a2];

[h,f]=freqz(b,a,2048,Fs);

H=abs(h);

HdB=20*log10(H);

phase=angle(h);

subplot(3,1,1);

plot(f,phase);

title('Phase Response');

xlabel('Frequency');

grid;

subplot(3,1,2);

plot(f,HdB);

title('Frequency Response')

ylabel('Magnitude (dB)');

xlabel('Frequency');

grid;

subplot(3,1,3);

zplane(b,a);

grid;

Notch filter test signal

clear; %Clear the work areas

N=1024; % Total Number of Samples

Fs=1000; % Sampling frequency set at 1000Hz

f1=120;

f2=50;

n=0:N-1;

x=sin(2*pi*(f1/Fs)*n)+sin(2*pi*(f2/Fs)*n);

[pxx,fx]=psd(x,2*N,Fs);

subplot(2,1,1);

plot(fx,20*log10(pxx));

axis([0 250 -40 40])

grid;

title('Magnitude Spectrum of x(n)');

xlabel('Frequency, Hz');

ylabel('Magnitude, dB');

R=0.998;

b1=2*cos(pi/80);

a1=2*R*cos(pi/80);

a2=R*R;

b=[1,-b1,1];

a=[1,-a1,a2];

y=filter(b, a, x);

[pyy, fy]=psd(y, 2*N, Fs);

subplot(2,1,2);

plot(fy, 20*log10(pyy));

grid;

Adaptive filter LMS Algorithm

function [B,y,e,J]= Mylms(x, dn, mu, M)

% Use of the function:

% function [B,y,e,J]= Mylms(x, dn, mu, M)

N = length(x);

y = zeros(1, N);

B = zeros(1, M);

for n=M: N

x1=x(n: -1: n-M+1);

y(n) = B * x1';

e(n) = dn(n) - y(n);

B = B + 2*mu*e(n)*x1;

end;

J = e.^2;

% Note J is the learning Curve of the Adaptive Process.

% Adaptive Noise Cancellation Demonstration

% Using the Adaptive LMS Algorithm

clear all;

A=1;

N=128;

f0=1000; % The frequency of the wanted signal s(n)

f1=2000; % The frequency of the noisy signal

Fs=8000;

n=0:N-1;

mu=0.01;

M=10;

% Generate a Sinusoidal of Frequency f0

s=sin(2*pi*(f0/Fs)*n);

% Generate another Sinewave to simulate a noisy tone and add it to

the wanted signal

v=sin(2*pi*(f1/Fs)*n);

% Construct the d(n)=s(n)+v(n)

d=s+v;

% Construct the x(n) to be the same noisy tone

x=sin(2*pi*(f1/Fs)*n);

% Call the LMS Algorithm

[B,y,e,J]= Mylms(x, d, mu, M);

% Plot the noisy signal and the Error Signal as well as their PSD

figure(1);

subplot(2,2,1);

plot(d), title('The Noisy Signal'); grid;

[psdd,f]=psd(d,length(d),Fs);

subplot(2,2,3);

plot(f,psdd), title('The Spectrum of the Noisy Signal'); grid;

subplot(2,2,2);

plot(e), title('The cleared Signal (Error Signal!)'); grid;

[psde,f]=psd(e,length(e),Fs);

subplot(2,2,4);

plot(f,psde), title('The Spectrum of the Error Signal (i.e s(n)');



rev

Our Service Portfolio

jb

Want To Place An Order Quickly?

Then shoot us a message on Whatsapp, WeChat or Gmail. We are available 24/7 to assist you.

whatsapp

Do not panic, you are at the right place

jb

Visit Our essay writting help page to get all the details and guidence on availing our assiatance service.

Get 20% Discount, Now
£19 £14/ Per Page
14 days delivery time

Our writting assistance service is undoubtedly one of the most affordable writting assistance services and we have highly qualified professionls to help you with your work. So what are you waiting for, click below to order now.

Get An Instant Quote

ORDER TODAY!

Our experts are ready to assist you, call us to get a free quote or order now to get succeed in your academics writing.

Get a Free Quote Order Now