Programming Matlab function into simulink

3 vues (au cours des 30 derniers jours)
Thogoe
Thogoe le 3 Nov 2015
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.

Réponse acceptée

Tushar Sinha
Tushar Sinha le 5 Nov 2015
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

Plus de réponses (1)

fikana cantri
fikana cantri le 26 Mai 2019
how do you solve the issue ? i have the same problem

Catégories

En savoir plus sur DSP Algorithm Acceleration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by