How can I use single float with filtfilt in matlab coder?

I use matlab coder (matlab version:R2017a) to compile matlab code to C code .And I want to use single floating-point number.While I have used filtfilt function in matlab code. Then I got an error it said filtfilt only takes double floating-point number.I have tried using single() to convert parameters in filtfilt but still failed.Is there anyone can help me?Thanks.

답변 (1개)

Jan
Jan 2017년 6월 19일
편집: Jan 2017년 6월 19일

0 개 추천

Either convert the signal using double(), or use FEX: FilterM, which accepts single values, but accumulate the internal filter state as doubles to increase the accuracy or the output.

댓글 수: 4

Jan
Jan 2017년 6월 22일
Moved from Answers section (please post comments as comment):
WillandSmith wrote: Thank you,Jan. I have tried double() to convert single to double.But still the matlab coder said filtfilt must have double-precision parameters. Your function is great. However I am doubt whether it can compile to C code by matlab coder. Maybe I should write my own filtfilt function in matlab?
Jan
Jan 2017년 6월 22일
@WillandSmith: Well, the function FilterX.c is a C file already, so there is no need to convert it to C. You do not have to write your own FiltFilt function, because you can use FiltFiltM.m from the FEX submission already. If you want to replace filter.m by an M-file, see: http://www.mathworks.com/matlabcentral/answers/9900-use-filter-constants-to-hard-code-filter, but it is unlikely that this is needed.
The error message means, that you have to use double() to convert the signal and the filter parameters. Use FilterX.c only, if you have a reason not to convert the signal (e.g. the memory consumption).
Thanks Jan.The FilterX.c is indeed a C file, but I still have many other matlab code and I want to complile them all into C code using matlab coder so that I don't have to rewrite all the matlab project to C code. Further more the target platform is ARM. So I have to use single-precision for reducing running time. I read your answer carefully but can't get the point to solve my problem.
While filter works on single also, filtfilt accepts doubles only (at least in some Matlab versions). You can either include the C-Mex FilterX and FiltFiltM.m (see https://www.mathworks.com/matlabcentral/answers/48620-generating-c-c-code-from-m-function-include-mex-file), or modify the builtin filtfilt.m function to accept singles also. I still do not see, where the problem is.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 函数基础知识에 대해 자세히 알아보기

태그

질문:

2017년 6월 19일

댓글:

Jan
2017년 7월 4일

Community Treasure Hunt

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

Start Hunting!