Programming Matlab function into simulink

조회 수: 1 (최근 30일)
Thogoe
Thogoe 2015년 11월 3일
답변: fikana cantri 2019년 5월 26일
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.

채택된 답변

Tushar Sinha
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

추가 답변 (1개)

fikana cantri
fikana cantri 2019년 5월 26일
how do you solve the issue ? i have the same problem

카테고리

Help CenterFile Exchange에서 DSP Algorithm Acceleration에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by