Code covered by the BSD License  

Highlights from
Echo Canceller Workbook targeting a dsPIC

image thumbnail

Echo Canceller Workbook targeting a dsPIC

by

 

22 Jan 2008 (Updated )

This set of models and word documents show an echo canceller development workflow.

lms_driver
function [Wts, sout_record] = lms_driver
%   Copyright 2008 The MathWorks, Inc.

load lms_io.mat

k = length(rin_record);
frm_len = 80;
num_frames = round(k/frm_len);
sout_record = zeros(1,length(rin_record));
h = figure('visible','off');
ah = axes;
set(ah,'ylimmode','manual');
set(ah,'xlimmode','manual');
set(ah,'xlim',[1 32]);
set(ah,'ylim',[-.1 .4]);
set(ah,'xgrid','on','ygrid','on');
lh = line;
set(lh,'xdata',1:32);
set(lh,'ydata',[1:32]/100);
set(h,'visible','on');
num_frames = 10;
for frm_num = 1:num_frames
    start_idx = (frm_num-1)*frm_len+1;
    stop_idx  = frm_num*frm_len;
    range = start_idx:stop_idx;
    [Wts, sout_record(range)] = lms_double(rin_record(range),sin_record(range));
    set(lh,'ydata',Wts);
    pause(.2);
end


function [Wts, sout] = lms_double(rin, sinp)
% Paramter initialization and memory allocation
persistent w;
persistent fifo;
    
filter_length = 32;
mu = 300/32768;       
N = length(rin);
if isempty(fifo)
    fifo = zeros(filter_length,1);
    w = zeros(1,filter_length);
end

% Loop over input vector
for n = 1:N
        % Update fifo
        fifo(1:filter_length-1) = fifo(2:filter_length);
        fifo(filter_length) = rin(n);
        % Update filter
        y = w*fifo;
        e = sinp(n) - y;
        err = mu * e;
        w = w + err*fifo';
        % Update output
        sout(n) = e;
end
Wts = w'; % output a column vector, not a row

Contact us