Programming Matlab function into simulink
2 次查看(过去 30 天)
显示 更早的评论
I'm trying to program an arduino due to record and do some calculations with the signal. To do that, i downloaded the arduino support package. Into simulink, i'm able to read the ecg signal, with an analoge input, but it needs to be filtered so i used the matlab function block and programmed the function below: (ecg is buffer of 10000 samples, sampled at 500Hz)
function y_filter = stats(ecg,fs,buffersize,bufferstep)
%#codegen
fcuts = [8 20];
mags = [1 0];
devs = [0.05 0.01];
[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,fs);
h = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
y_filter=filtfilt(h,1,ecg);
I'm getting the following errors
All inputs must be constant.
Function 'MATLAB Function' (#23.282.331), line 15, column 5: "[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,fs)" Launch diagnostic report. Component: MATLAB Function | Category: Coder error
Undefined function or variable 'n'. The first assignment to a local variable determines its class.
Function 'MATLAB Function' (#23.283.284), line 15, column 6: "n" Launch diagnostic report. Component: MATLAB Function | Category: Coder error
Undefined function or variable 'Wn'. The first assignment to a local variable determines its class.
Function 'MATLAB Function' (#23.285.287), line 15, column 8: "Wn" Launch diagnostic report. Component: MATLAB Function | Category: Coder error
Undefined function or variable 'beta'. The first assignment to a local variable determines its class.
Function 'MATLAB Function' (#23.288.292), line 15, column 11: "beta" Launch diagnostic report. Component: MATLAB Function | Category: Coder error
Undefined function or variable 'ftype'. The first assignment to a local variable determines its class.
Function 'MATLAB Function' (#23.293.298), line 15, column 16: "ftype" Launch diagnostic report. Component: MATLAB Function | Category: Coder error
Undefined function or variable 'n'. The first assignment to a local variable determines its class.
Function 'MATLAB Function' (#23.346.347), line 16, column 14: "n" Launch diagnostic report. Component: MATLAB Function | Category: Coder error
Undefined function or variable 'h'. The first assignment to a local variable determines its class.
Function 'MATLAB Function' (#23.411.412), line 18, column 23: "h" Launch diagnostic report. Component: MATLAB Function | Category: Coder error
-
Any help how i could fix the problem or another (better) solution to filter my ecg? it should be used to monitor a heart signal online.
0 个评论
采纳的回答
Tushar Sinha
2015-11-5
Hi Thogoe,
The issue might be occurring because the function variables are not allowed to change size to be able to generate code. Initializing all the variables to some default value at the start of the function might help resolve the issue.
You can also refer to the link below which talks about a similar issue:
I hope this helps!
Thanks,
Tushar
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 DSP Algorithm Acceleration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!