Re: [fpc-pascal] Good FFT example anywhere?

2017-04-12 Thread Michael Schnell

On 10.04.2017 23:20, Bo Berglund wrote:

- A pulse stimulus is applied to the object to measure
- The response transient is recorded for up to 150 ms


OK. In this case you will not need the "Windowing".

Instead you need to make sure that the pulse is surrounded by enough 
Zero-line data. I suggest to place the Pulse's non-zero data in the 
middle of an array of at least the double count of samples, the rest 
being zero. Supposedly th Pulse starts with Zero, anyway, so no problem 
here. If at the end the measurement is truncated, you should use a 
"sinc" or similar curve to force it smoothly down to zero with the last 
measured sample before the Zero-line starts.


Not doing this will result in a huge aliasing and unusable "spectrum data.

The cause is that Digital Fourier Transform converts a number of samples 
in the same number of "bins" (= complex amplitude / phase spectrum data 
for a dedicated frequency).


If there are n (="Window-Size") samples and the Sample Frequency is f, 
the bins represent the frequencies 0, f/n, 2f/n, 3f/n, ... Hence the 
bin[1] represents the Sample Frequency by the Window Size, which is the 
lowest frequency usable, while the last bin represents the Sample 
Frequency which in fact is not usable due to the Nyquist Theorem, that 
allows for using only frequencies lower than half the Sample Frequency. 
(This said, you need to make sure by hardware means that no frequencies 
higher than half the sample even reach the A/D converter. Otherwise you 
will feature aliasing that will make the spectrum unusable. )


The Nyquist Theorem also is visible in the fact that a DFT does not 
really convert the signal you measured to a spectrum you want to see, 
but in fact converts a periodic signal to a periodic spectrum. The 
(assumed) period of the signal being the Window Size divided by the 
Sample Frequency, the period of the spectrum being the Sample Frequency 
divided by the Window Size. Hence adding the Zero-Line will allow your 
signal to be the significant part of a period.


-Michael
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Good FFT example anywhere?

2017-04-11 Thread Michael Schnell



On 09.04.2017 10:06, Bo Berglund wrote:

It will produce 8192 samples
for each measurement.
If the "measurements" come as a sequence of sample-blocks, you 
additional to the core FFT will need a sliding Window algorithm to e.g. 
create something like a life spectrum display or do a useful convolution.


-Michael
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Good FFT example anywhere?

2017-04-09 Thread Ched

Hi,

As an owner of the Numerical Receipes in Pascal, I can say that the sources codes are *very very old* 
styled and a rewritting to dynamical array of data is a good idea ! The N.R. are probably written by 
ForTranists :) But ths book contains lots of useful knowledge en tricks for numericians and is pleasant 
to read.


Cheers, Ched'





Le 09.04.2017 à 19:21, Rolf Grunsky a écrit :

On 2017-04-09 04:06 AM, Bo Berglund wrote:

I am looking for some good example of FFT functions in pascal but it
seems like what Google serves up is rather old and refers to
Turbo-pascal and the like...
So maybe someone here knows about some open-source example of FFT
using FreePascal (or Delphi)?

I want to analyze the frequency content of transient responses
measured using a 24 bit A/D converter. It will produce 8192 samples
for each measurement.

Any suggestions welcome!

PS: I have saved this list from Sept 2003 and I searched it for the
word FFT without success, except the hits on the word offtopic.. DS



The book "Numerical Recipes: The Art of Scientific Computing" has an entire 
section of FFT. The first
edition of the book has code in both FORTRAN and Pascal. You can find out more at 
"numerical.recipes".
Later editions are C and C++ and may not have Pascal examples.

There are many other scientific computing topics in the book.



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Good FFT example anywhere?

2017-04-09 Thread Rolf Grunsky

On 2017-04-09 04:06 AM, Bo Berglund wrote:

I am looking for some good example of FFT functions in pascal but it
seems like what Google serves up is rather old and refers to
Turbo-pascal and the like...
So maybe someone here knows about some open-source example of FFT
using FreePascal (or Delphi)?

I want to analyze the frequency content of transient responses
measured using a 24 bit A/D converter. It will produce 8192 samples
for each measurement.

Any suggestions welcome!

PS: I have saved this list from Sept 2003 and I searched it for the
word FFT without success, except the hits on the word offtopic.. DS


The book "Numerical Recipes: The Art of Scientific Computing" has an 
entire section of FFT. The first edition of the book has code in both 
FORTRAN and Pascal. You can find out more at "numerical.recipes". Later 
editions are C and C++ and may not have Pascal examples.


There are many other scientific computing topics in the book.

--
   TRUTH in her dress finds facts too tight.
   In fiction she moves with ease.
   Stray Birds by Rabindranath Tagore
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Good FFT example anywhere?

2017-04-09 Thread fredvs
> As you can see it uses double, which means you will be OK to supply 
> both single and integer values, just load the array with them and they
> will be converted. 

Many thanks for answer.

Hmmm, it seems magic and very simple to use.
Ok, I will try with my audio library. 

By the way (who knows) did you try it, for example, to isolate some
frequency from a buffer of sample (like a high-pass filter) ?
(Of course example are welcome ;-) ).

Fre;D





-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Good-FFT-example-anywhere-tp5728169p5728183.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Good FFT example anywhere?

2017-04-09 Thread Bo Berglund
On Sun, 9 Apr 2017 08:01:07 -0700 (MST), fredvs
 wrote:

>Hello.
>
>> I was using attached unit some 7 years ago for various speech processing
>> purposes.
>
>+ @Martin
>
>Can those units be used for sound samples (array of float32 or array ot
>integer 32/16) ?
>

The unit declares the fft procedure like this:

(*---
procedure fft

Calculates the Fast Fourier Transform of the array of complex numbers
represented by 'RealIn' and 'ImagIn' to produce the output complex
numbers in 'RealOut' and 'ImagOut'.
---*)
procedure fft (
NumSamples:   word;   { must be a positive integer power of 2 }
var  RealIn:   array of double;
var  ImagIn:   array of double;
var  RealOut:  array of double;
var  ImagOut:  array of double );

As you can see it uses double, which means you will be OK to supply
both single and integer values, just load the array with them and they
will be converted.

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Good FFT example anywhere?

2017-04-09 Thread Bo Berglund
On Sun, 9 Apr 2017 11:22:00 +0300, Žilvinas Ledas
 wrote:

>
>On 2017-04-09 11:06, Bo Berglund wrote:
>> I am looking for some good example of FFT functions in pascal but it
>> seems like what Google serves up is rather old and refers to
>> Turbo-pascal and the like...
>> So maybe someone here knows about some open-source example of FFT
>> using FreePascal (or Delphi)?
>
>I was using attached unit some 7 years ago for various speech processing 
>purposes.
>
>Best regards,
>Žilvinas
>

I looked at it briefly and there are parts of it I don't understand,
for example:
NumberOfBitsNeeded, what purpose is this?
ReverseBits, does what and why?

I might have to run the code in a test program to see what is actually
going on. I did take the courses on Fourier transforms and the FFT
variant but that was a long time ago (like 40 years or so) so I am
rusty in that regard.

Generally (in reply to the other suggestions) I want a pure pascal
function so I can build it for the target platform, which will
probably end up being ARM and Linux (RPi3).
So no Intel stuff or Windows dll solutions...


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Good FFT example anywhere?

2017-04-09 Thread Adriaan van Os

I am looking for some good example of FFT functions in pascal but it
seems like what Google serves up is rather old and refers to
Turbo-pascal and the like...


But note that even a perfect FFT will suffer from some side-effects





Regards,

Adriaan van Os
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Good FFT example anywhere?

2017-04-09 Thread Marco van de Voort
In our previous episode, Bo Berglund said:
> Turbo-pascal and the like...
> So maybe someone here knows about some open-source example of FFT
> using FreePascal (or Delphi)?

When I looked around I was also pointed towards IPP and FFTW, but shied away
from the license consequences (reapllying every 12 months
https://software.intel.com/en-us/faq/free-software and GPL resp)

There is a fairly decent performing unit set under MPL out there by Nils
Haeck, that also performance well for samples sizes that are not a power of
two:

http://www.simdesign.nl/fft.html
 
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Good FFT example anywhere?

2017-04-09 Thread Adriaan van Os

Bo Berglund wrote:

I am looking for some good example of FFT functions in pascal but it
seems like what Google serves up is rather old and refers to
Turbo-pascal and the like...
So maybe someone here knows about some open-source example of FFT
using FreePascal (or Delphi)?

I want to analyze the frequency content of transient responses
measured using a 24 bit A/D converter. It will produce 8192 samples
for each measurement.

Any suggestions welcome!


For maximum speed you would use vector-code. This could be assembly from Pascal. But it is easier 
to use Intel IPP  or Apple Accelerate Framework 
 when you are on OS X or iOS. Apple also has a 
lib with C-source code  that is much faster than the FFT in the 
Accelerate Framework when the FFT size is large, see 
.


Pascal interfaces for IPP are here .

There are also the FFTs in the GNU Scientific library 
 but it has license 
restrictions .


I have a Pascal FastFourierTransform.pas unit (without vector code), but it is not written by me. 
You would have to contact the author for permission to use it. I can give the email address by 
private email.


Regards,

Adriaan van Os

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Good FFT example anywhere?

2017-04-09 Thread Žilvinas Ledas


On 2017-04-09 11:06, Bo Berglund wrote:

I am looking for some good example of FFT functions in pascal but it
seems like what Google serves up is rather old and refers to
Turbo-pascal and the like...
So maybe someone here knows about some open-source example of FFT
using FreePascal (or Delphi)?


Hi,

I was using attached unit some 7 years ago for various speech processing 
purposes.



Best regards,
Žilvinas



I want to analyze the frequency content of transient responses
measured using a 24 bit A/D converter. It will produce 8192 samples
for each measurement.

Any suggestions welcome!

PS: I have saved this list from Sept 2003 and I searched it for the
word FFT without success, except the hits on the word offtopic.. DS




(*==

fourier.pas  -  Don Cross 

This is a Turbo Pascal Unit for calculating the Fast Fourier Transform
(FFT) and the Inverse Fast Fourier Transform (IFFT).
Visit the following URL for the latest version of this code.
This page also has a C/C++ version, and a brief discussion of the
theory behind the FFT algorithm.

   http://www.intersrv.com/~dcross/fft.html#pascal

Revision history [most recent first]:

1996 December 11 [Don Cross]
Improved documentation of the procedure CalcFrequency.
Fixed some messed up comments in procedure ifft.

1996 December 6 [Don Cross]
Made procedure 'fft_integer' more efficient when buffer size changes
in successive calls:  the buffer is now only resized when the input
has more samples, not a differing number of samples.
Also changed the way 'fft_integer_cleanup' works so that it is
more "bullet-proof".

1996 December 4 [Don Cross]
Adding the procedure 'CalcFrequency', which calculates the FFT
at a specific frequency index p=0..n-1, instead of the whole
FFT.  This is O(n) instead of O(n*log(n)).

1996 November 30 [Don Cross]
Adding a routine to allow FFT of an input array of integers.
It is called 'fft_integer'.

1996 November 18 [Don Cross]
Added some comments.

1996 November 17 [Don Cross]
Wrote and debugged first version.

==*)

//{$N+,E+}   (* Allows code to use type 'double' and run on any iX86 machine *)
{$R-}  (* Turn off range checking...we violate array bounds rules *)


unit Fourier;


interface

//uses definition;

(*---
  procedure fft

  Calculates the Fast Fourier Transform of the array of complex numbers
  represented by 'RealIn' and 'ImagIn' to produce the output complex
  numbers in 'RealOut' and 'ImagOut'.
---*)
procedure fft (
NumSamples:   word;   { must be a positive integer power of 2 }
var  RealIn:   array of double;
var  ImagIn:   array of double;
var  RealOut:  array of double;
var  ImagOut:  array of double );


(*---
  procedure ifft

  Calculates the Inverse Fast Fourier Transform of the array of complex
  numbers represented by 'RealIn' and 'ImagIn' to produce the output complex
  numbers in 'RealOut' and 'ImagOut'.
---*)
procedure ifft (
NumSamples:   word;   { must be a positive integer power of 2 }
var  RealIn:   array of double;
var  ImagIn:   array of double;
var  RealOut:  array of double;
var  ImagOut:  array of double );



(*---
  procedure fft_integer

  Same as procedure fft, but uses integer input arrays instead of
  double.  Make sure you call fft_integer_cleanup after the last
  time you call fft_integer to free up memory it allocates.
---*)
procedure fft_integer (
NumSamples:   word;
var  RealIn:   array of integer;
var  ImagIn:   array of integer;
var  RealOut:  array of double;
var  ImagOut:  array of double );


(*--
   procedure fft_integer_cleanup

   If you call the procedure 'fft_integer', you must call
   'fft_integer_cleanup' after the last time you call 'fft_integer'
   in order to free up dynamic memory.
--*)
procedure fft_integer_cleanup;


(*--
   procedure CalcFrequency

   This procedure calculates the complex frequency sample at a given
   index directly.  Use this instead of 'fft' when you only need one
   or two frequency samples, not the whole spectrum.

   It is also useful for calculating the Discrete Fourier Transform (DFT)
   of a number 

Re: [fpc-pascal] Good FFT example anywhere?

2017-04-09 Thread Martin Schreiber
On Sunday 09 April 2017 10:06:41 Bo Berglund wrote:
> I am looking for some good example of FFT functions in pascal but it
> seems like what Google serves up is rather old and refers to
> Turbo-pascal and the like...
> So maybe someone here knows about some open-source example of FFT
> using FreePascal (or Delphi)?
>
MSEgui has tfft which uses the FFTW library.
https://gitlab.com/mseide-msegui/mseide-msegui/blob/master/lib/common/math/msefft.pas

Martin
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal