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(rin_record,sin_record)
function [sout_record] = lms_driver(rin_record,sin_record)
%   Copyright 2008 The MathWorks, Inc.

k = length(rin_record);
frm_len = 80;
num_frames = round(k/frm_len);
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;
    sout_record(range) = lms_double(rin_record(range),sin_record(range));
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);
% 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