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.

ec_fixed_setup_structures.m
%% Echo Cancellation Data Specification

% This file is best navigated using "Show cell titles"
% Note that this is an m-script which means all variables
% are evaluated in the base workspace.
%
% Signal Objects Note:
% Since multiple signals in model will have this name it is 
% important to explicitly resolve these signals in the model's
% Configuration Parameters Dialog
%     Diagnostics -> Data Validity -> Explicit Only
% This variation of the setup file uses custom storage classes and
% structures for the rin_linear, sin_linear, and sout_linear signals.
%   Copyright 2008 The MathWorks, Inc.

%% Model parameters
load sm_filt;  % spkr_to_mic_filter coefficients
sm_length = length(spkr_to_mic_filter);  % variable from sm_filt mat file
spkr_to_mic_delay = spkr_to_mic_delay;    % also part of sm_file file
pic_frame_size = 80;
Fs = 8000;
Ts = 1/Fs;
mpt_dimensions = [pic_frame_size 1];

%% Input Signal: rin_linear
rin_linear = mpt.Signal;
rin_linear.SamplingMode ='Frame based';
rin_linear.Dimensions = mpt_dimensions;
rin_linear.Description = 'Far End Voice';
rin_linear.DataType = 'fixdt(1,16,14)';
rin_linear.RTWInfo.StorageClass = 'Custom';
rin_linear.RTWInfo.CustomStorageClass = 'Struct';
rin_linear.RTWInfo.CustomAttributes.StructName = 'ec_struct';

%% Input Signal: sin_linear
sin_linear = mpt.Signal;
sin_linear.SamplingMode ='Frame based';
sin_linear.Dimensions = mpt_dimensions;
sin_linear.Description = 'Near end voice plus echo';
sin_linear.DataType = 'fixdt(1,16,14)';
sin_linear.RTWInfo.StorageClass = 'Custom';
sin_linear.RTWInfo.CustomStorageClass = 'Struct';
sin_linear.RTWInfo.CustomAttributes.StructName = 'ec_struct'; 

%% Input Signal: sout_linear
sout_linear = mpt.Signal;
sout_linear.SamplingMode ='Frame based';
sout_linear.Dimensions = mpt_dimensions;
sout_linear.Description = 'Echo Cancelled Output (near end)';
sout_linear.DataType = 'fixdt(1,16,14)';
sout_linear.RTWInfo.StorageClass = 'Custom';
sout_linear.RTWInfo.CustomStorageClass = 'Struct';
sout_linear.RTWInfo.CustomAttributes.StructName = 'ec_struct';

%% Input Signal: step_size
step_size = Simulink.Parameter;
step_size.Description = 'Echo Canceller Step Size';
step_size.DataType = 'auto';  % must use auto, fixpt doesn't work here
step_size.RTWInfo.StorageClass = 'Custom';  % originally 'Auto'
step_size.RTWInfo.CustomStorageClass = 'Define';
step_size.RTWInfo.Alias = 'STEP_SIZE';
step_size.Value = 300/32768;

%% Input Signal: ec_length
ec_length = Simulink.Parameter;
ec_length.Description = 'Echo Canceller Length';
ec_length.DataType = 'auto';   % must use auto, fixpt doesn't work here
ec_length.RTWInfo.StorageClass = 'Custom';  % originally 'Auto'
ec_length.RTWInfo.CustomStorageClass = 'Define';
ec_length.RTWInfo.Alias = 'EC_LENGTH';
ec_length.Value = 32;

%% Input Signal: Echo Cancellor Weights (Wts)
Wts = mpt.Signal;
Wts.SamplingMode ='Sample based';
Wts.Dimensions = ec_length.Value;
Wts.Description = 'Echo Cancellor Taps';
Wts.DataType = 'fixdt(1,16,15)';
Wts.RTWInfo.StorageClass = 'Auto';

%% LMS Parameters
temp = eval(Wts.DataType);
LMS_Wts_WordLen = temp.WordLength;
LMS_Wts_FracLen = temp.FractionLength;
LMS_Prod_WordLen = 16;
LMS_Prod_FracLen = 15;
LMS_Accum_WordLen = 32;
LMS_Accum_FracLen = 20;
LMS_Parms_WordLen = 16;
LMS_StepSize_FracLen = 15;
LMS_Leakage_FracLen = 15;

%% Input Signal: bypass
bypass = mpt.Signal;
bypass.SamplingMode = 'Sample based';
bypass.Dimensions = 1;
bypass.Description = 'Enable the Echo Canceller';
bypass.DataType = 'int16';
bypass.RTWInfo.StorageClass = 'Auto';

%% Input Signal: reset
reset = mpt.Signal;
reset.SamplingMode = 'Sample based';
reset.Dimensions = 1;
reset.Description = 'Clear the echo canceller taps to all zeros';
reset.DataType = 'int16';
reset.RTWInfo.StorageClass = 'Auto';

Contact us