matlab_to_c原版完整文件.docx





《matlab_to_c原版完整文件.docx》由会员分享,可在线阅读,更多相关《matlab_to_c原版完整文件.docx(9页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、The MATLAB to C Conversion Process for PAN_TOMPKIN.M Kerry SchutzMay 2015This document covers what changes were made to an entry on MATLAB Central called pan_tompkin.mfor MATLAB Coder compatibility. It is a very popular entry for QRS detection in ECG signals. implementation-ecg-qrs-detectorRequired
2、Products to run pan_tompkin.m MATLAB Signal Processing ToolboxAdditional Required Products to Generate C Code MATLAB CoderYou can quickly find all changes that were made to the original code by searching for the string “TMW” in pt.m. In addition the generated C code was benchmarked against the origi
3、nal MATLAB code for speed. The generated MEX file shows excellent acceleration. All work was performed in R2015a.1. First, I created a copy of the original MATLAB code, pan_tompkin.m, and called it pt.m. Accordingly, I renamed the function entry point to reflect the new name. I also added%#codegen t
4、o allow the editor to do extra C code compatibility checks. This does not impact the execution of the MATLAB code in simulation.function qrs_amp_raw,qrs_i_raw,delay=pt(ecg,fs,gr) %#codegen2. I created a testbench file, tb.m, to exercise the DUT, pt.m. Always thoroughly test your DUT doing anything r
5、elated to code generation. In this case, the author of pan_tompkin.m did not supply a testbench on MATLAB Central nor any test data files toverify against. Since the focus here is on C code generation, I simply substituted random data for the stimulus. Also the authors algorithm has sample rate depe
6、ndence. In this case, Im using 400 Hz for the sample rate but in general you should test against all relevant rates.% tb.m% simple testbench% create stimulus in = rand(1000,1);% call DUTtic; qrs_amp_raw0,qrs_i_raw0,delay0 = pt(in,400,1); toc;3. When I run the tb.m, the DUT appears to work and runs t
7、o near completion but I see an error near the end as well.Conversion to logical from matlab.graphics.Graphics is not possible. Error in pt (line 434)434: if ax(:)435:linkaxes(ax,x);436:zoom on;438: endThe variable ax is a handle graphics axes object and and does not impact the algorithm. To work-aro
8、und the problem, I just removed visualization code from the DUT since this is code best served by the testbench.4. I ran coder.screener on pt.m. This is a course-grain check for MATLAB Coder compatibility. The screener is looking for constructs and functions that are not supported for C code generat
9、ion. It does not take into account data types and sizes which are also important and as such, the build process will have to find those incompatibilities later as we will show in the steps that follow.coder.screener(-text,pt.m,report.txt); edit report.txtEverything looks good at a high-level.5. I cr
10、eated a MATLAB coder project. coder new pt6. I clicked Next and soon discovered the first set of MATLAB Coder incompatibilities.ERROR: Code generation requires variable ax to be fully defined before subscripting it.This first set of errors are all visualization related. Instead of trying to fix this
11、 error, I chose simply to work-around it.WORKAROUND: Removed all visualization code from the DUT. You can quickly find visualization sections of the code by searching for the string “if gr”.Visualization as a general rule should be placed in the testbench and not in the DUT. As a best practice, you
12、should return variables of interest from the DUT function and post-process and/or visualize them in the testbench. Removing visualization code is not however required.Occasionally having visualization within the DUT is convenient for debugging purposes. See the file pt2.m for an example of how to ke
13、ep the visualization within the DUT and still generate C code.7. I specified the testbench name in the project to be tb.m and clicked Autodefine Input Types. Once it determines the types, click Next.8. Next I clicked Check for Issues.9. MATLAB Coder finds more problems.ERROR: Error using Filter Desi
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- matlab_to_c 原版 完整 文件

限制150内