tags:

views:

259

answers:

3

I'd like to generate some code using MATLAB Embedded Coder that runs an fft2 operation on a uint8 datatype. The end application is going to operate on images up to 4096 by 4096, so I'd like to not have to use the double (~134MB of double data vs. ~16MB) input required to get emlc to compile my code right now.

Here's a sample of what I'm running:

%#eml
function bar = emlc_test(foo)
    bar = fft2(foo);
end

with compiler command:

emlc -T rtw emlc_test -c -report -v -eg { zeros(32,32,'uint8') }

This throws error:

??? Function 'fft' is not defined for values of class 'uint8'.

The same code/compilation command works fine when changing 'uint8' to 'double'

But looking at the generated code it seems like processing should be capable of running in uint8 space. Is there a flag I'm missing to allow my fft2 operation to work on uint8 data rather than double data?

+1  A: 

No, not possible. fft and fft2 only support single and double floats. Not much you can do about it. If you want to save memory space, try single floats.

sellibitze
+3  A: 

The MATLAB fft2 reference documentation is explicit on its requirement of types double or single.

It seems you may have to use a "monster" (*) matrix based on singles even for the input. I think that the reason for this is that there is no way for MATLAB to decide the type desired in the output, other that it being the same as the input.
(**) Actually not that big: single type is only 4 times what you intended.

mjv
@Peter Mortensen, thanks for fixing my spelling of `MATLAB` (not `MatLab`); my coding habits (including camel-casing) have further impaired my command of the English grammar or, in this case, my respect for registered names...
mjv
+1  A: 

If you really need the optimisation, I think the only thing you can do is reinvent the wheel: implement your FFT function from scratch (it's a lot of work).

Emilio M Bumachar
Even then ... how should he do it on a uint8 vector? The DFT corresponds to a unitary linear map on a set of complex vectors. The FFT algoriths usually work "in-place" and rotate and shuffle the data. You can't do that on an uint8 array without introducing *lots* of rounding errors and overflows and underflows.
sellibitze
As it turns out I've ultimately ended up replacing the Matlab generated code with KISS FFT since Matlab's C output actually ran slower than in Matlab -- either way my intention was to use the code outside of Matlab in a C application.
Mark E

related questions