compare fir filter implementations using socmodelanalyzer -凯发k8网页登录
this example shows how to analyze and compare different implementations of a simulink® algorithm based on the number of arithmetic operations. use the soc blockset socmodelanalyzer
function to generate reports that show the number of operators for different implementations of a fir filter using static and runtime execution.
design task and requirements
this design task evaluates two implementations of a fir filter and compares the implementation costs. this example uses the number of operators as a way to measure the implementation cost.
to meet system requirements such as speed, latency, and hardware resources, consider and compare several implementations of the algorithm. the number of arithmetic operators used in an implementation can help you identify resource usage and allocation.
manual analysis and calculation of the number of arithmetic operators can be tedious, error prone, and time consuming. manual calculations can be inaccurate for an algorithm involving a branch, loop, or recursion construct and might be impossible to calculate if the execution path depends on the input data or random factors (for example, a convergence algorithm).
structure of model
the soc_analyze_fir_tb
model implements a low pass digital fir filter in two ways. the symmetric_fir subsystem exploits symmetry in coefficients to optimize the resources. the transposed_fir subsystem employs a filter structure geared toward higher speed of operation. the model uses a chirp input signal as an input stimulus and a fir_ref (discrete fir filter) block as a reference for checking numerical correctness of the implementations.
open the soc_analyze_fir_tb
model in simulink and examine the structure of the model.
open_system('soc_analyze_fir_tb');
to design the low pass fir filter we use the (dsp system toolbox) app to generate coefficients for an 8th order fir filter. the fir filter has a cutoff frequency of 0.25 (normalized) and a passband ripple and stop band attenuation of 1 db and 60 db, respectively. the model sets these coefficients via the model initialize callback.
simulate the model to validate the functionality of both implementations against the reference fir block. the responses of the filter implementations match the reference.
sim('soc_analyze_fir_tb');
compare implementations using model analyzer
use the socmodelanalyzer
function to generate reports for the number of arithmetic operators in each implementation and compare the implementations. the reports are generated using the runtime execution of the model.
symmetric fir filter:
to estimate the number of operators for symmetric fir filter implementation, use the socmodelanalyzer
function. specify the subsystem name for the includeblockpath
name-value pair argument of the function. set the output folder to specify where to generate the reports. enter this command at the matlab command prompt.
socmodelanalyzer('soc_analyze_fir_tb.slx','folder','report_sym','includeblockpath',... 'soc_analyze_fir_tb/symmetric_fir');
generating operators analysis report for /tmp/bdoc23a_2213998_3594841/tp07e2a7de/soc-ex82446029/soc_analyze_fir_tb.slx ... saving report files in /tmp/bdoc23a_2213998_3594841/tp07e2a7de/soc-ex82446029/report_sym. operator estimate: done.
open the report by clicking the open report viewer link on the matlab console. alternatively, you can use the function. the report provides two views. the first view is the operator view, which presents the data such that each row corresponds to an operator. to use this view, click operator view on the report toolstrip. the second view is the model view where each row corresponds to a simulink subsystem path. to use this view, click model view on the report toolstrip. reports are also saved in the
report_sym
folder as a mat-file (soc_analyze_fir_tb.mat
) and an excel® file (soc_analyze_fir_tb.xlsx
).
by default, the report opens with the operator view. the viewer opens the aggregate view of each operator and data type. for example, the symmetric fir filter contains a total of 8 add( )
operators of data-type double
and 5 mul(*)
operators of data-type double
executed 10,001 times each. (the model simulation duration is 10 s and the base rate is 10 ms. this produces 10,000 simulation cycles plus 1 for initialization.) to get the detailed report for each operator, expand that operator. the report shows the operator count as used in various blocks. trace the operator by clicking on one of the links in the last column of the report to highlight the location of the operator in the soc_analyze_fir_tb
model.
transposed fir filter
to estimate the number of operators for the transposed fir filter implementation, use the socmodelanalyzer
function. specify 'soc_analyze_fir_tb/transposed_fir'
for the 'includeblockpath'
name-value pair argument of the function. set the output folder for the generated reports to report_trans
. enter this command at the matlab command prompt.
socmodelanalyzer('soc_analyze_fir_tb.slx','folder','report_trans','includeblockpath',... 'soc_analyze_fir_tb/transposed_fir');
generating operators analysis report for /tmp/bdoc23a_2213998_3594841/tp07e2a7de/soc-ex82446029/soc_analyze_fir_tb.slx ... saving report files in /tmp/bdoc23a_2213998_3594841/tp07e2a7de/soc-ex82446029/report_trans. operator estimate: done.
open the report for the transposed fir filter by clicking the open report viewer link on the matlab console.
for the transposed fir filter, the report shows an estimated number of 8 additions of data-type double
and 9 multiplications of data-type double
(each operator executed 10,001 times).
comparison of symmetric and transposed implementations
compare the symmetric and transposed fir filter reports generated by using the socmodelanalyzer
function. the symmetric fir filter uses fewer multiplication operators (9) than the transposed fir filter (5). they both use the same number of add operators (8).
conclusion
you used the socmodelanalyzer
function to estimate and analyze the number of arithmetic operators in two fir filter implementations. you generated operator reports for both symmetric and transposed fir filters. you compared the number of multiply and add operators for two implementations.
you can use the socmodelanalyzer
function for analyzing the number of operators in a simulink algorithm.
see also
|