Adaptive Filters In the Frequency Domain: Difference between revisions

From Class Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:
Here is a MATLAB or octave file that demonstrates the convergence.
Here is a MATLAB or octave file that demonstrates the convergence.


% This is to test the adaptive filter done in the frequency domain.
% This script plots a Fourier Series for a Square Wave
% It is supposed to converge to an unknown transfer function, Hu.
% GPL License. Look on Google. Any version is fine.
% Rob Frohne 2012
% Algorithm developed by Rob Frohne 3/22/2012.

mu = 1
N = 32
L = 2048;
M = L*N;
e = 0;
Hu = randn(1,N);
H = zeros(size(Hu));
clf;
t=0:.01:10;
x = 100*randn(1,M);
T=2.5
M=50
for k=1:L-1
sum1=0;
X = fft(x(k*N+1:(k+1)*N));
for m=1:2:M,
R = Hu.*X;
sum1 = sum1+4/m/pi*sin(m*pi/2)*cos(2*pi*m*t/T);
E = R-H.*X;
H = H + mu*2*E.*conj(X)/(X*X'); % Note: The (X*X') normalizes the
% step size with respect to the input.
e = [e,10*log10(norm(H-Hu))];
end
end
plot(t,sum1,'b-',t(1:10:end),sum1(1:10:end),'r*')
plot(e)
title('Fourier Series Representation of a Square Wave')
xlabel('time (seconds)')
title('Error Norm')
ylabel('Function')
ylabel('dB')
xlabel('Iteration')
grid on;
axis([0,10,-2,2])
legend('Five Terms','Five Terms Sampled')
print("squarewave.png","-dpng") % Prints the plot to a png file called squarewave.png

Revision as of 20:55, 26 March 2012

To come up with a frequency domain example of an adaptive LMS filter, you can have an unknown transfer function in parallel with your adaptive filter, where the output of one is subtracted from the other creating an error signal. This is then squared and the steepest descent method is used to find a guess to the LMS error iteratively, after every N point FFT is done and at each frequency. The step size is adjusted to be independent of the amplitude of the input. The result converges nicely. See the derivation on the photo.

Here is a MATLAB or octave file that demonstrates the convergence.

% This is to test the adaptive filter done in the frequency domain. % It is supposed to converge to an unknown transfer function, Hu. % Algorithm developed by Rob Frohne 3/22/2012.

mu = 1
N = 32
L = 2048;
M = L*N;
e = 0;
Hu = randn(1,N); 

H = zeros(size(Hu));

x = 100*randn(1,M);

for k=1:L-1
	X = fft(x(k*N+1:(k+1)*N));
	R = Hu.*X;
	E = R-H.*X;
	H = H + mu*2*E.*conj(X)/(X*X'); % Note: The (X*X') normalizes the
	% step size with respect to the input.
	e = [e,10*log10(norm(H-Hu))];
end

plot(e)
title('Error Norm')
ylabel('dB')
xlabel('Iteration')