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.
10.3. CODE GENERATION 145
Figure 10.1 shows the initial screen for the Coder. Start by selecting the function to be
converted and change the Numeric Conversion option to single precision floating-point arith-
metic.
Figure 10.1: MATLAB coder function selection.
After the function is selected, the input types need to be specified (see Figure 10.2). is
can be done manually or by using the above test bench script to automatically determine the data
types. Select the test bench script and choose the Autodefine Input Types option to complete
this step.
After the input types are set, the Coder then checks to ensure that it is able to generate a
C code from the provided MATLAB script. Figure 10.3 shows the outcome with no detected
errors. Although many of the built-in MATLAB functions work with the MATLAB Coder,
not all are supported. Unsupported functions are required to be written from scratch by the
programmer.
Once the MATLAB script is checked and passed, a corresponding C source code can be
generated by pressing the Generate button (see Figure 10.4). Although various configuration
settings are available, the default settings are adequate for the generation of C source codes.
146 10. IMPLEMENTATION VIA MATLAB CODER
Figure 10.2: Input type specification.
Figure 10.3: Function error check.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.154.151