如何存储重复函数的输出(Matlab函数块Simulink) ?万博1manbetx

7次浏览(过去30天)
优素福Abdelsalam
优素福Abdelsalam 2021年7月31日
回答: Kiran Kintali 2021年8月3日
我正在尝试使用Self - guided tutorial来实现一个硬件友好的寻峰器。(//www.tianjin-qmedu.com/matlabcentral/fileexchange/69651-hdl-coder-self-guided-tutorial)
函数块一次取11个样本,并将这些样本与中间样本进行比较,如果它们更小,则为局部最大值。
当它被检测到时,detected标志会升起(detected =true),但它不会显示detected=true的位置。
函数运行多次,直到输入不改变,只有一次检测到峰值。
我想知道这座山峰的位置。
我实现了一个持久计数器,所以每次函数运行时,它都会向计数器添加+1,并且检测到的时间为真,这就是位置(+/-一个常量)。所以这是一个基本的if条件:
如果检测到= = true
peak_loc =计数器;
结束
问题是我还需要在else条件下分配函数输出(peak_loc),但这将在下次函数运行时覆盖变量,因为在前一次函数运行时检测到峰值。
有人能帮帮我吗?
(我的想法是将这些函数输出存储在一个数组中,然后找到“true”的位置,这将是峰值位置,但也会有else条件的问题)

接受的答案

Kiran Kintali
Kiran Kintali 2021年8月1日
编辑:Kiran Kintali 2021年8月1日
峰值查找器的硬件友好实现
%函数输入:
% * windowslen -在Simulink->编辑数据下定义的不可调参数万博1manbetx
% * threhold -输入端口(连接到常量)
% * DataBuff -输入端口(使用Simulink块完成缓冲)万博1manbetx
函数输出:
% *“detected”在MidSample为本地最大值时设置
% * "index" 64位索引值,在检测到峰值时保存峰值的位置
函数[MidSample,detected,index] = fcn(WindowLen, threshold, DataBuff)
% # codegen
持续的计数器;
如果isempty(柜台)
Counter = uint64(0);
结束
计数器=计数器+ 1;
索引=计数器;
MidIdx = ceil(WindowLen/2);
通过减法将窗口中的每个值与中间样本进行比较
MidSample = DataBuff(middidx);
CompareOut = DataBuff - MidSample;%这是一个向量
%,如果结果中的所有值都为负,而中间样本为
%大于阈值,则为本地最大值
如果所有(CompareOut <= 0) && (MidSample >阈值)
检测到=真;
其他的
检测到=错误;
结束
2的评论

登录评论。

更多答案(2)

Kiran Kintali
Kiran Kintali 2021年8月2日
编辑:Kiran Kintali 2021年8月2日
> > makehdl (“pulse_detector_v4_with_index /脉冲探测器”
# # #生成'pulse_detector_v4_with_index/Pulse Detector'的HDL。
# # #使用模型pulse_detector_v4_with_index的配置集用于HDL代码生成参数。
# # #运行HDL检查模型'pulse_detector_v4_with_index'。
# # #开始'pulse_detector_v4_with_index'模型的编译...
应用HDL优化模型'pulse_detector_v4_with_index'...
开始模型生成。
# # #模型一代完成。
# # #开始VHDL代码生成'pulse_detector_v4_with_index'。
# # #工作将pulse_detector_v4_with_index/Pulse Detector/Compute Power作为hdl_prj\hdlsrc\pulse_detector_v4_with_index\Compute_Power.vhd。
# # #工作在pulse_detector_v4_with_index/脉冲检测器/局部峰值/MATLAB函数作为hdl_prj\hdlsrc\pulse_detector_v4_with_index\MATLAB_Function.vhd。
# # #工作在pulse_detector_v4_with_index/Pulse Detector/Local Peak as hdl_prj\hdlsrc\pulse_detector_v4_with_index\Local_Peak.vhd。
# # #工作关于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。
# # #工作在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。
# # #工作关于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。
# # #工作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。
# # #工作关于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。
# # #工作关于pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL优化/FilterBank作为hdl_prj\hdlsrc\pulse_detector_v4_with_index\FilterBank.vhd。
# # #工作关于pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL优化为hdl_prj\hdlsrc\pulse_detector_v4_with_index\Discrete_FIR_Filter_HDL_Optimized.vhd。
# # #工作作为hdl_prj\hdlsrc\pulse_detector_v4_with_index\Pulse_Detector.vhd。
# # #生成包文件hdl_prj\hdlsrc\pulse_detector_v4_with_index\Pulse_Detector_pkg.vhd。
# # #代码生成'pulse_detector_v4_with_index'完成。
# # #生成HTML文件的代码生成报告pulse_detector_v4_with_index_codegen_rpt.html
# # #创建HDL代码生成检查报告Pulse_Detector_report.html
# # #高密度脂蛋白检查'pulse_detector_v4_with_index'完成,错误为0, 0警告,和2消息。
# # #高密度脂蛋白代码生成完成。
> > makehdl (“pulse_detector_v4_with_index /脉冲探测器”“targetlang”“verilog”
# # #生成'pulse_detector_v4_with_index/Pulse Detector'的HDL。
# # #使用模型pulse_detector_v4_with_index的配置集用于HDL代码生成参数。
# # #运行HDL检查模型'pulse_detector_v4_with_index'。
# # #开始'pulse_detector_v4_with_index'模型的编译...
开始模型生成。
# # #模型一代完成。
# # #开始Verilog代码生成'pulse_detector_v4_with_index'。
# # #工作将pulse_detector_v4_with_index/Pulse Detector/Compute Power作为hdl_prj\hdlsrc\pulse_detector_v4_with_index\Compute_Power.v。
# # #工作在pulse_detector_v4_with_index/脉冲检测器/局部峰值/MATLAB函数作为hdl_prj\hdlsrc\pulse_detector_v4_with_index\MATLAB_Function.v。
# # #工作在pulse_detector_v4_with_index/Pulse Detector/Local Peak as hdl_prj\hdlsrc\pulse_detector_v4_with_index\Local_Peak.v。
# # #工作关于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。
# # #工作在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。
# # #工作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。
# # #工作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。
# # #工作关于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
# # #工作关于pulse_detector_v4_with_index/Pulse Detector/Discrete FIR Filter HDL优化/FilterBank作为hdl_prj\hdlsrc\pulse_detector_v4_with_index\FilterBank.v。
# # #工作关于pulse_detector_v4_with_index/脉冲探测器/离散FIR滤波器HDL优化为hdl_prj\hdlsrc\pulse_detector_v4_with_index\Discrete_FIR_Filter_HDL_Optimized.v。
# # #工作作为hdl_prj\hdlsrc\pulse_detector_v4_with_index\Pulse_Detector.v。
# # #代码生成'pulse_detector_v4_with_index'完成。
# # #生成HTML文件的代码生成报告pulse_detector_v4_with_index_codegen_rpt.html
# # #创建HDL代码生成检查报告Pulse_Detector_report.html
# # #高密度脂蛋白检查'pulse_detector_v4_with_index'完成,错误为0, 0警告,和2消息。
# # #高密度脂蛋白代码生成完成。
>>
我没有看到错误w.r.代码生成器。你用的是哪个版本的MATLAB ?
您可以在MATLAB代码中更新“检测到的”逻辑以启用其他场景。
是的,你应该能够使用合成工具合成这段代码来针对FPGA / ASIC。
5个评论
优素福Abdelsalam
优素福Abdelsalam 2021年8月3日
另一个问题:如果我使用FPGA数据捕获与DSP系统工具箱逻辑分析仪从FPGA捕获数据,我需要索引输出吗?(因为有了逻辑分析器,我就能看到 发现= 1 我会手动定位它)。

登录评论。


Kiran Kintali
Kiran Kintali 2021年8月3日
你知道如何检测多个峰值而不是一个吗?
您是否可以考虑以级联方式启用多个延迟以存储更多峰值?

社区寻宝

在MATLAB Central中找到宝藏,并发现社区如何帮助您!

开始狩猎!