Programming Matlab function into simulink
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Thogoe
el 3 de Nov. de 2015
Respondida: fikana cantri
el 26 de Mayo de 2019
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 comentarios
Respuesta aceptada
Tushar Sinha
el 5 de Nov. de 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
0 comentarios
Más respuestas (1)
fikana cantri
el 26 de Mayo de 2019
how do you solve the issue ? i have the same problem
0 comentarios
Ver también
Categorías
Más información sobre DSP Algorithm Acceleration en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!