forum.alglib.net

ALGLIB forum
It is currently Sun Dec 22, 2024 10:43 am

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Help. FFT in Delphi 7
PostPosted: Mon Nov 08, 2010 9:09 am 
Offline

Joined: Mon Nov 08, 2010 8:41 am
Posts: 8
Location: Kazakhstan, Kurchatov
Hello. I use ALGLIB for Delphi7. I have error when i specify the size of the array Buf (type of TReal1DArray): SetLength (Buf, N), I am using the function FFTR1D.Please, suggest me what could be the reason?


Top
 Profile  
 
 Post subject: Re: Help. FFT in Delphi 7
PostPosted: Mon Nov 08, 2010 11:36 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
What kind of error you have - compiler error, runtime error? Can you post here code which calls ALGLIB (and error message text)?


Top
 Profile  
 
 Post subject: Re: Help. FFT in Delphi 7
PostPosted: Tue Nov 09, 2010 5:22 am 
Offline

Joined: Mon Nov 08, 2010 8:41 am
Posts: 8
Location: Kazakhstan, Kurchatov
This problem goes away by itself, did not even understand how.
Now another problem: the function FFTR1D (const A: TReal1DArray; N: AlglibInteger; var F: TComplex1DArray),
returns an array of F values:"+NAN", instead of real numbers. how to get rid of, I do not know.


Top
 Profile  
 
 Post subject: Re: Help. FFT in Delphi 7
PostPosted: Tue Nov 09, 2010 5:25 am 
Offline

Joined: Mon Nov 08, 2010 8:41 am
Posts: 8
Location: Kazakhstan, Kurchatov
Suddenly do not understand the question! I need instead of "+ NAN" get real numbers. Thank you for your help!


Top
 Profile  
 
 Post subject: Re: Help. FFT in Delphi 7
PostPosted: Tue Nov 09, 2010 7:56 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
If you want to get help, you should post your code first. Code which calls ALGLIB functions and leads to incorrect results. How can someone tell what's wrong without looking at code?


Top
 Profile  
 
 Post subject: Re: Help. FFT in Delphi 7
PostPosted: Tue Nov 09, 2010 8:14 am 
Offline

Joined: Mon Nov 08, 2010 8:41 am
Posts: 8
Location: Kazakhstan, Kurchatov
unit fftun;
interface
uses Math, Sysutils, Ap, ftbase;

...

procedure FFTC1D(var A : TComplex1DArray; N : AlglibInteger);
var
Plan : FTPlan;
I : AlglibInteger;
Buf : TReal1DArray;
begin
Assert(N>0, 'FFTC1D: incorrect N!');

//
// Special case: N=1, FFT is just identity transform.
// After this block we assume that N is strictly greater than 1.
//
if N=1 then
begin
Exit;
end;

//
// convert input array to the more convinient format
//
GetMem(buf,2*n);
SetLength(Buf, 2*N);
I:=0;
while I<=N-1 do
begin
Buf[2*I+0] := A[I].X;
Buf[2*I+1] := A[I].Y;
Inc(I);
end;

//
// Generate plan and execute it.
//
// Plan is a combination of a successive factorizations of N and
// precomputed data. It is much like a FFTW plan, but is not stored
// between subroutine calls and is much simpler.
//
FTBaseGenerateComplexFFTPlan(N, Plan);
FTBaseExecutePlan(Buf, 0, N, Plan);//After this procedure, the array is filled with the Buf "+ NAN".

//
// result
//
I:=0;
while I<=N-1 do
begin
A[I].X := Buf[2*I+0];
A[I].Y := Buf[2*I+1];
Inc(I);
end;


Attachments:
after.jpg
after.jpg [ 37.11 KiB | Viewed 12691 times ]
befor.jpg
befor.jpg [ 25.17 KiB | Viewed 12691 times ]
Top
 Profile  
 
 Post subject: Re: Help. FFT in Delphi 7
PostPosted: Tue Nov 09, 2010 8:19 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
No, I talked about your code, which calls ALGLIB functions. Maybe you have subtle errors in the initialization of arrays....

And what about this GetMem(buf,2*n) call? There is no such code in the original library - looks like you've tweaked ALGLIB code a bit. I suspect that this call is the reason behind failure. Try once more with original, unmodified ALGLIB.


Top
 Profile  
 
 Post subject: Re: Help. FFT in Delphi 7
PostPosted: Tue Nov 09, 2010 9:08 am 
Offline

Joined: Mon Nov 08, 2010 8:41 am
Posts: 8
Location: Kazakhstan, Kurchatov
I am very grateful. getmem - it was my mistake, forgot to remove it. by getmem, I tried to solve the problem with the size of the array. Now everything works. Thank you again!


Top
 Profile  
 
 Post subject: Re: Help. FFT in Delphi 7
PostPosted: Wed Nov 10, 2010 9:10 am 
Offline

Joined: Mon Nov 08, 2010 8:41 am
Posts: 8
Location: Kazakhstan, Kurchatov
Hello! I have a question: When drawing the data obtained after converting the sinusoid, turns smooth peak, although it should be sharp. Why is this happening? sinusoid has a frequency of 2 kHz.


Attachments:
fft-sin.jpg
fft-sin.jpg [ 56.27 KiB | Viewed 12685 times ]
Sinusoid.jpg
Sinusoid.jpg [ 114.88 KiB | Viewed 12685 times ]
Top
 Profile  
 
 Post subject: Re: Help. FFT in Delphi 7
PostPosted: Wed Nov 10, 2010 9:43 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
I don't think that it is error in the FFT - it looks like aliasing effect.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group