144 10. IMPLEMENTATION VIA MATLAB CODER
10.2 TEST BENCH
An important step in implementing any signal processing algorithm is functional verification.
is has benefits both for debugging purposes as well as simulating the response on a target
platform on which the algorithm is to run. For audio signal processing, MATLAB assumes
samples of an entire audio signal are available but on an actual target, audio signal processing
is done in a frame-based manner. us, one needs to implement frame-based processing. e
following script shows how such an implementation is achieved.
clear all;
sampleRate=8000;
sampleTime=1/sampleRate;
frameSize = 256;
time=[0:sampleTime:10*sampleRate*sampleTime];
%generate signal
length = floor(size(time,2)/frameSize)*frameSize;
time = time(1:length);
signal = 1/2*square(2*pi*600*time,50);
audiowrite('Square_duty-50_600Hz_10s.wav',signal,sampleRate);
%simulate frame-based processing
signal = reshape(signal,frameSize,[]);
signal = signal';
result = zeros(size(signal));
for i = 1:size(signal,1)
result(i,:) = FIR(signal(i,:));
end
is script generates a test signal and writes it to a file for use on a target platform. e signal
is reshaped into a matrix of frame-sized columns and transposed to form frame-sized rows as
would be the behavior on the target. e rows are then passed to the MATLAB function for
processing.
10.3 CODE GENERATION
e above MATLAB function and the test bench script steps allow generating a C code using
the MATLAB Coder. e MATLAB Coder (Coder) [2] can be found in the Apps section
of the toolbar. e following screenshot shows the process of using a MATLAB function to
generate a C source code.