Azzera filtri
Azzera filtri

Include fft.m in Java Project

1 visualizzazione (ultimi 30 giorni)
Frank Gomez
Frank Gomez il 31 Ago 2011
Hello everyone!
I have a matlab function (let's call it mfun) which calls the fft. I use this mfun in Java code, through a class created by Matlab builder JA (R2010a), but I get a java error "Undefined function or method 'fft' for input arguments of type 'int32'". I guess that Java cannot access to the fft function, the .jar file only has one class with this mfun. So, how can I include fft in the .jar?
Thanks!

Risposta accettata

Rick Rosson
Rick Rosson il 31 Ago 2011
Hi Frank,
The issue is not with deploying fft using Builder JA, but rather with fft itself. The fft function does not support integer classes as input arguments.
Please try the following at the MATLAB Command Line:
x = int32(randi([-256 255],128,1));
X = fft(x);
Notice that you get the same error message.
You can, however, coerce the integer class input argument to double or single to perform the transformation:
X = fft(double(x));
OR
X = fft(single(x));
HTH.
Rick
  1 Commento
Frank Gomez
Frank Gomez il 31 Ago 2011
Ok, I understand, I tried this code and got the same error. So, here is how I call my function (the one called time2rms, which in matlab calls the fft)
double[] array= {5.2d,3.7d,5.3d};
input = new MWNumericArray(array,MWClassID.DOUBLE);
output= converter.time2rms(1, input, 3);
This time2rms function has 2 parameters, a vector and a number of items (input and 3), also I declared a MWNumericArray which double values. The execption appears when I call the time2rms function. How should I declare the array of numbers?

Accedi per commentare.

Più risposte (2)

Rick Rosson
Rick Rosson il 31 Ago 2011
I think the easiest thing to do would be to modify the MATLAB source code for the time2rms function, and then re-deploy using the MATLAB Compiler and Builder JA.
There are two ways to modify the MATLAB code:
  1. Check the input arguments at the very beginning of the function to see if they are floating point. If not, coerce them right then and there, OR
  2. Find each instance where the function calls fft, and coerce the input argument at each call site.
To accomplish #1, you would need to use the isa function:
if ~( isa(x,'double') || isa(x,'single') )
x = double(x)
end
I am not sure which way is better, but both should work.
HTH.
Rick
  1 Commento
Frank Gomez
Frank Gomez il 5 Set 2011
Hello Rick,
The problem still persists, after make the proper cast inside the matlab code:
vector_2= double(vector_1)
So I'm affraid the problem could be located in another aspect about conversion from JAVA to Matlab, because this time2rms works properly inside Matlab, it seams like the conversion does not work well.

Accedi per commentare.


Frank Gomez
Frank Gomez il 6 Dic 2011
I think I found the problem. The key thing is that when I build the .jar with my matlab functions, It seems I have to include the fft.m in order to make the fft available when I call time2rms function in JAVA code. So... now, the question is different. Is there any way to include the fft.m in this .jar?
Thanks!
  1 Commento
Frank Gomez
Frank Gomez il 6 Dic 2011
Or... I need to implement the fft algorithm in order to make it visible?

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by