Recent

Author Topic: Fast Fourier Transform (FFT) Forward, Reverse, 1D and 2D  (Read 1147 times)

Dzandaa

  • Sr. Member
  • ****
  • Posts: 423
  • From C# to Lazarus
Fast Fourier Transform (FFT) Forward, Reverse, 1D and 2D
« on: March 24, 2025, 06:01:19 pm »
Hi,

This is a FFT and Complex units I wrote for demonstration purpose.

Included Test for 1D and 2D arrays
Buffers must be exponent of 2

For 1D FTT, there are also some Windows Filters like Hamming, Hanning, etc...
For 2D FTT, image must be square and exponent of 2 for size.

You cant select lower and higher frequencies to change the result.

Tested on Windows 10 and Linux Mint 20.2

B->

Regards,
Dzandaa

Thaddy

  • Hero Member
  • *****
  • Posts: 16783
  • Ceterum censeo Trump esse delendam
Re: Fast Fourier Transform (FFT) Forward, Reverse, 1D and 2D
« Reply #1 on: March 24, 2025, 06:15:49 pm »
Why didn't you use the standard fpc supplied uComplex unit?
The ComplexU unit seems to me like a reinvented wheel.
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

Dzandaa

  • Sr. Member
  • ****
  • Posts: 423
  • From C# to Lazarus
Re: Fast Fourier Transform (FFT) Forward, Reverse, 1D and 2D
« Reply #2 on: March 24, 2025, 06:28:15 pm »
Hi,

@Thaddy:
Quote
Why didn't you use the standard fpc supplied uComplex unit?
The ComplexU unit seems to me like a reinvented wheel.
Just for the fun and learning Pascal.

B->
Regards,
Dzandaa

ackarwow

  • Full Member
  • ***
  • Posts: 141
    • Andrzej Karwowski's Homepage
Re: Fast Fourier Transform (FFT) Forward, Reverse, 1D and 2D
« Reply #3 on: March 24, 2025, 06:49:20 pm »
Hi @Dzandaa

Good job! Impressive...

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12151
  • FPC developer.
Re: Fast Fourier Transform (FFT) Forward, Reverse, 1D and 2D
« Reply #4 on: March 24, 2025, 07:42:15 pm »
Is this correct for non power of 2 samplesizes, and what is the advantage over the standard FFT unit by Nils Haeck ?

Paolo

  • Hero Member
  • *****
  • Posts: 580
Re: Fast Fourier Transform (FFT) Forward, Reverse, 1D and 2D
« Reply #5 on: March 24, 2025, 07:56:08 pm »
Quote
Just for the fun and learning Pascal
+1

tetrastes

  • Hero Member
  • *****
  • Posts: 640
Re: Fast Fourier Transform (FFT) Forward, Reverse, 1D and 2D
« Reply #6 on: March 24, 2025, 08:51:53 pm »
standard FFT unit by Nils Haeck ?

Where can I find it?

Dzandaa

  • Sr. Member
  • ****
  • Posts: 423
  • From C# to Lazarus
Re: Fast Fourier Transform (FFT) Forward, Reverse, 1D and 2D
« Reply #7 on: March 25, 2025, 11:14:27 am »
Hi,

Quote
Is this correct for non power of 2 samplesizes, and what is the advantage over the standard FFT unit by Nils Haeck ?

@marcov:

Non, it's just for power of 2.

It is the simplest FFT, just to show what an FFT can do with filtering.

Just Need BGRABitmap for 2D FFT and Industrial stuff for both 1D and 2D.

And I don't know the FFT by Nils Haeck.

B->
Regards,
Dzandaa

Thaddy

  • Hero Member
  • *****
  • Posts: 16783
  • Ceterum censeo Trump esse delendam
Re: Fast Fourier Transform (FFT) Forward, Reverse, 1D and 2D
« Reply #8 on: March 25, 2025, 12:02:39 pm »
standard FFT unit by Nils Haeck ?

Where can I find it?
Yes, where?
(Interested because I added a very simple fft implementation to a different forum entry last week. The smallest I could come up with and reasonably usable, especially for audio fft's for display use)
« Last Edit: March 25, 2025, 12:05:45 pm by Thaddy »
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12151
  • FPC developer.
Re: Fast Fourier Transform (FFT) Forward, Reverse, 1D and 2D
« Reply #9 on: March 25, 2025, 04:35:24 pm »
Afaik the original site is no longer there (same author as nativejpg). But a bit googling it is easy to find:

https://github.com/neurolabusc/MRIcron/blob/master/niftiview7/FFTs.pas and other fft* files.

I have a slightly different version myself, that was modified once, but I don't know if they are that important.   (my main code typically has 200*2^n samples)

I also spent quite some time in trying to accelerate it with avx, but while all individual routines where several times faster, overall it was not. Probably something frustrates the micro-op cache or so, it will have to wait till I can inline it, e.g. when avx intrinsics become available.

If somebody knows the butterfly diagram for number 20 (specially what to do extra to merge two number 10 diagrams)
« Last Edit: March 25, 2025, 11:00:56 pm by marcov »

VTwin

  • Hero Member
  • *****
  • Posts: 1227
  • Former Turbo Pascal 3 user
Re: Fast Fourier Transform (FFT) Forward, Reverse, 1D and 2D
« Reply #10 on: March 25, 2025, 04:51:12 pm »
For the record, DMath (and LMath) contain fft routines. I have not used them in years, but they worked well for me at the time. I can not comment on how they compare to this implementation.

https://wiki.lazarus.freepascal.org/DMath
« Last Edit: March 25, 2025, 04:58:17 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 15.3.2: Lazarus 3.8 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 3.8 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 3.8 (64 bit on VBox)

 

TinyPortal © 2005-2018