MATLAB Answers

Jim Clay

Using 'single' arrays with the "filter" command

Asked by Jim Clay
on 19 Nov 2012

We have to minimize our application's memory footprint and execution time, so I'm trying to move from "double" data arrays to "single" data arrays. The problem is that the "filter" command appears to return "double" filter states. Is there a way to use "single" data with the filter or even the "conv" command?

  1 Comment

Matt J
on 19 Nov 2012

if your inputs are single, so should the output be.

2 Answers

Answer by Jonathan Sullivan on 19 Nov 2012

Make sure all your inputs to filter are singles.

Here's an example for a simple moving average:

x = rand(100,1,'single');
a = ones(1,10,'single')/single(10);
b = single(1);
xf = filter(a,b,x);

  1 Comment

I have done that, but the second output, the final filter state, is still double.

Answer by Jan Simon
on 20 Nov 2012
Edited by Jan Simon
on 20 Nov 2012

See: FEX: FilterM, which accepts singles also.

Do you mean the 2nd output of filter with "double filter states"?

  1 Comment

Yes, I mean the 2nd output of filter. I will check out the FilterM command.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!