How can I play the output from LMS filter ?
Show older comments
close all;
clear all;clc;
[signal,fs] = audioread('signal.wav');
%%soundsc(signal,fs);
noise = wgn(length(signal), 1, 0);
d = signal + noise;
sound(d)
x = sin(1./(1+exp(-noise)));
mu = 0.1;
M = 20;
tic
[e1, y1, w1] = myLMS(d, x, mu, M);
toc
figure()
subplot(3,1,1)
plot([1:length(x)]/fs,x);
xlabel('time');
title('x(n)');
subplot(3,1,2)
plot([1:length(d)]/fs,d);
xlabel('time');
title('d(n)');
subplot(3,1,3)
plot([1:length(y1)]/fs,y1);
xlabel('time');
title('LMS y(n)');
function [e, y, w] = myLMS(d, x, mu, M)
Ns = length(d);
if (Ns <= M)
print('error: ????????????');
return;
end
if (Ns ~= length(x))
print('error: ??????????????');
return;
end
x = x;
xx = zeros(M,1);
w1 = zeros(M,1);
y = zeros(Ns,1);
e = zeros(Ns,1);
for n = 1:Ns
xx = [xx(2:M);x(n)];
y(n) = w1' * xx;
e(n) = d(n) - y(n);
w1 = w1 + mu * e(n) * xx;
w(:,n) = w1;
end
end
Answers (0)
Categories
Find more on Signal Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!