Forum > Packages and Libraries

dmath fft, got empty OutArray

(1/4) > >>

senglit:
hi,

i need to transform a signal from time domain to freq domain and I find dmath can do it. This is my code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure CalcSpec(data:string);var  NumSamples,MaxIndex:integer;            InArray, OutArray : TCompVector;  I                 : Integer;  dataInt:array of integer;begin        NumSamples := data.Length div 4;  MaxIndex := NumSamples-1;  // I missed this in original post  SetLength(dataInt,NumSamples);  Move(data[1],dataInt[0],data.Length);    DimCompVector(InArray, MaxIndex);  DimCompVector(OutArray, MaxIndex);  for i := 0 to NumSamples - 1 do    begin      InArray[I].X := dataInt[I]/256.0;          end;  FFT(NumSamples, InArray, OutArray);end;         
After running this procedure, I found everything in OutArray is 0. With debuger I can see the data like this:
InArray = (COMPLEX (X = -15430;Y = 0), COMPLEX (X = -15730;Y = 0), COMPLEX (X = -15900;Y = 0), COMPLEX (X = -16510;Y = 0);......)
OutArray = (COMPLEX (X = 0;Y = 0), COMPLEX (X = 0;Y = 0), COMPLEX (X = 0;Y = 0), COMPLEX (X = 0;Y = 0), COMPLEX (X = 0;Y = 0), .......)

How to get the correct result?

Nitorami:
Have you checked if the procedure sets an error flag ? I believe dmath does not throw exceptions in case of errors but just sets a flag you need to check. Use function utypes.matherr for that.

marcov:
Don't move an array of integer into an array of complex ? Run a loop and assign them one at a time.

Iow the MOVE() statement is wrong.

wp:
Just to make sure that the fft of dmath is working I wrote the attached small project which syntesizes some input waves, performs the FFT and displays input and output data in charts. (The required dmath units are included in the project, therefore, it should compile even if you don't have dmath on your system). - The result looks reasonable (I did not care about normalization of the output wave amplitudes).

As for your issue: You pass your data to the analyses function in a very unusual way. Input comes as a string, but it does not seem to be an "ordinary" string of characters, but an array of 4-byte integers. Why don't you use a simple dynamic array or one of the "vector" types of dmath? But anyway, I rewrote the above-mentioned demo to handle data in this "string" way and to use much of your code -- and it works correctly. Therefore, I guess your problem is outside, in the routine which stuffs the original data into the string passed to the CalcSpec method.

glorfin:
I don't quite understand one thing: OutArray is local variable in this procedure. How do you get data out of it? Do you look in the debugger immediately after call to FFT or after the return from your procedure?

Navigation

[0] Message Index

[#] Next page

Go to full version