How to store the output of a repeating function (Matlab Function Block Simulink) ?
Show older comments
I was trying out the Self guided tutorial to implement a hardware friendly peak-finder. (https://www.mathworks.com/matlabcentral/fileexchange/69651-hdl-coder-self-guided-tutorial)
The function block takes 11 samples at a time and compares those with the middle sample and if theyre smaller, then it is a local max.
when it is detected the detected flag goes up (detected = true),but it doesnt show the location where the detected=true.
the function runs multiple times, until the inputs dont change and there is only one time where a peak is detected, .
I want to find out where this peak is located .
I implemented a persistent counter so every time the function runs it adds +1 to the counter, and that one time where detected is true, that is the location (+/- a constant). So its a basic if condition:
if detected==true
peak_loc=counter;
end
the problem is i need to assign the function output (peak_loc) in the else condition also, but this overwrites the variable the next time the function runs, because the peak was detected in the previous function run.
Can somebody help?
(My idea was to store these function outputs in an array and then find the position of the ''true'' and that will be the peak location, but there will also be the problem of the else condition)
Accepted Answer
More Answers (2)
Kiran Kintali
on 2 Aug 2021
Edited: Kiran Kintali
on 2 Aug 2021
>> makehdl('pulse_detector_v4_with_index/Pulse Detector')
### Generating HDL for 'pulse_detector_v4_with_index/Pulse Detector'.
### Using the config set for model pulse_detector_v4_with_index for HDL code generation parameters.
### Running HDL checks on the model 'pulse_detector_v4_with_index'.
### Begin compilation of the model 'pulse_detector_v4_with_index'...
### Applying HDL optimizations on the model 'pulse_detector_v4_with_index'...
### Begin model generation.
### Model generation complete.
### Begin VHDL Code Generation for 'pulse_detector_v4_with_index'.
### Working on pulse_detector_v4_with_index/Pulse Detector/Compute Power as hdl_prj\hdlsrc\pulse_detector_v4_with_index\Compute_Power.vhd.
### Working on pulse_detector_v4_with_index/Pulse Detector/Local Peak/MATLAB Function as hdl_prj\hdlsrc\pulse_detector_v4_with_index\MATLAB_Function.vhd.
### Working on pulse_detector_v4_with_index/Pulse Detector/Local Peak as hdl_prj\hdlsrc\pulse_detector_v4_with_index\Local_Peak.vhd.
### Working on pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL Optimized/FilterBank/FilterCoef as hdl_prj\hdlsrc\pulse_detector_v4_with_index\FilterCoef.vhd.
### Working on pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL Optimized/FilterBank/FilterCoef as hdl_prj\hdlsrc\pulse_detector_v4_with_index\FilterCoef_block.vhd.
### Working on pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL Optimized/FilterBank/FilterCoef as hdl_prj\hdlsrc\pulse_detector_v4_with_index\FilterCoef_block1.vhd.
### Working on pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL Optimized/FilterBank/subFilter/FilterTapSystolicWvldin as hdl_prj\hdlsrc\pulse_detector_v4_with_index\FilterTapSystolicWvldin.vhd.
### Working on pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL Optimized/FilterBank/subFilter as hdl_prj\hdlsrc\pulse_detector_v4_with_index\subFilter.vhd.
### Working on pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL Optimized/FilterBank as hdl_prj\hdlsrc\pulse_detector_v4_with_index\FilterBank.vhd.
### Working on pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL Optimized as hdl_prj\hdlsrc\pulse_detector_v4_with_index\Discrete_FIR_Filter_HDL_Optimized.vhd.
### Working on pulse_detector_v4_with_index/Pulse Detector as hdl_prj\hdlsrc\pulse_detector_v4_with_index\Pulse_Detector.vhd.
### Generating package file hdl_prj\hdlsrc\pulse_detector_v4_with_index\Pulse_Detector_pkg.vhd.
### Code Generation for 'pulse_detector_v4_with_index' completed.
### Generating HTML files for code generation report at pulse_detector_v4_with_index_codegen_rpt.html
### Creating HDL Code Generation Check Report Pulse_Detector_report.html
### HDL check for 'pulse_detector_v4_with_index' complete with 0 errors, 0 warnings, and 2 messages.
### HDL code generation complete.
>> makehdl('pulse_detector_v4_with_index/Pulse Detector', 'targetlang', 'verilog')
### Generating HDL for 'pulse_detector_v4_with_index/Pulse Detector'.
### Using the config set for model pulse_detector_v4_with_index for HDL code generation parameters.
### Running HDL checks on the model 'pulse_detector_v4_with_index'.
### Begin compilation of the model 'pulse_detector_v4_with_index'...
### Begin model generation.
### Model generation complete.
### Begin Verilog Code Generation for 'pulse_detector_v4_with_index'.
### Working on pulse_detector_v4_with_index/Pulse Detector/Compute Power as hdl_prj\hdlsrc\pulse_detector_v4_with_index\Compute_Power.v.
### Working on pulse_detector_v4_with_index/Pulse Detector/Local Peak/MATLAB Function as hdl_prj\hdlsrc\pulse_detector_v4_with_index\MATLAB_Function.v.
### Working on pulse_detector_v4_with_index/Pulse Detector/Local Peak as hdl_prj\hdlsrc\pulse_detector_v4_with_index\Local_Peak.v.
### Working on pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL Optimized/FilterBank/FilterCoef as hdl_prj\hdlsrc\pulse_detector_v4_with_index\FilterCoef.v.
### Working on pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL Optimized/FilterBank/FilterCoef as hdl_prj\hdlsrc\pulse_detector_v4_with_index\FilterCoef_block.v.
### Working on pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL Optimized/FilterBank/FilterCoef as hdl_prj\hdlsrc\pulse_detector_v4_with_index\FilterCoef_block1.v.
### Working on pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL Optimized/FilterBank/subFilter/FilterTapSystolicWvldin as hdl_prj\hdlsrc\pulse_detector_v4_with_index\FilterTapSystolicWvldin.v.
### Working on pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL Optimized/FilterBank/subFilter as hdl_prj\hdlsrc\pulse_detector_v4_with_index\subFilter.v.
### Working on pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL Optimized/FilterBank as hdl_prj\hdlsrc\pulse_detector_v4_with_index\FilterBank.v.
### Working on pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL Optimized as hdl_prj\hdlsrc\pulse_detector_v4_with_index\Discrete_FIR_Filter_HDL_Optimized.v.
### Working on pulse_detector_v4_with_index/Pulse Detector as hdl_prj\hdlsrc\pulse_detector_v4_with_index\Pulse_Detector.v.
### Code Generation for 'pulse_detector_v4_with_index' completed.
### Generating HTML files for code generation report at pulse_detector_v4_with_index_codegen_rpt.html
### Creating HDL Code Generation Check Report Pulse_Detector_report.html
### HDL check for 'pulse_detector_v4_with_index' complete with 0 errors, 0 warnings, and 2 messages.
### HDL code generation complete.
>>
I am not seeing the error w.r.to code generator. What version of MATLAB are you using?
You can update "detected" logic in the MATLAB code to enable other scenerios.
Yes, you should be able to synthesize this code using synthesis tool to target FPGA / ASIC.
5 Comments
Youssef Abdelsalam
on 2 Aug 2021
Youssef Abdelsalam
on 2 Aug 2021
Youssef Abdelsalam
on 2 Aug 2021
Youssef Abdelsalam
on 2 Aug 2021
Youssef Abdelsalam
on 3 Aug 2021
Kiran Kintali
on 3 Aug 2021
0 votes
>> Do you have an idea how to detect multiple peaks not just one ?
Can you consider Multiple enabled delays in a cascaded fashion to store more peaks?

Categories
Find more on HDL Code Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
