Copyright: (c) 1997 H. Lohninger, Vienna, Austria


FOURIER unit
Fourier - Version 1.0

The unit FOURIER contains a visual component for fast Fourier transform.

FOURIER is released under the shareware concept. The unregistered version is fully functional with one exception: the shareware version runs properly only when the Delphi, or C++Builder IDE is also up and running.

Product information

Interface of unit FOURIER

Installation of FOURIER

Delphi and C++Builder issues

How to use TFastFourier

Methods and Properties of TFastFourier:

Clear	ClearImag

ClearReal	DataBuffer

ImagMax	ImagMin

ImagSpec	InverseTransform

PowerMax	PowerSpec

RealMax	RealMin

RealSpec	SpectrumSize

Transform	WeightingWindow


Clear method
 Clear

See also:	ClearImag, ClearReal

Class:	TFastFourier

Declaration:	procedure Clear;

The method Clear resets both the real and the imaginary part of the spectrum to zero values.


ClearImag method
 ClearImag

See also:	ClearReal, Clear

Class:	TFastFourier

Declaration:	procedure ClearImag;

The method ClearImag resets the imaginary part of the spectrum to zero values.


ClearReal method
 ClearReal

See also:	ClearImag, Clear

Class:	TFastFourier

Declaration:	procedure ClearReal;

The method ClearReal resets the real part of the spectrum to zero values.


DataBuffer property
 DataBuffer

See also:	RealSpec, ImagSpec

Class:	TFastFourier

Declaration:	property DataBuffer: pointer;

For high speed data processing, the mechanism of feeding data to the FFT algorithm by means of the properties RealSpec and ImagSpec may be too slow. The read-only property DataBuffer provides a way for quick access to the internal data buffer. DataBuffer is a pointer to the internal buffer. The internal buffer is of the following type:

TDataBuf = array[1..2*SpectrumSize] of double

The buffer array contains the data (or Fourier coefficients) in alternating order, with the values of the real part at odd indexes and the imaginary values at even addresses.

Attention:	Manipulating the data buffer directly is potentially dangerous and may lead to program crashes if not done properly. It is recommended not to use this property unless there is a real need for it.

Below is a sample code showing how to use the DataBuffer property. Please note, that the data buffer may be filled by block move commands, or DMA (direct memory access) routines in order to get maximum speed (not shown here).

const

  SpecSize = 256;

type

  Tdbuf = array[1..2*SpecSize] of double;

...

FFT.SpectrumSize := SpecSize;

for i:=1 to SpecSize do              { load a square wave }

  begin

  if i <= (SpecSize div 2)                { the real part }

    then TDBuf(FFT.DataBuffer^)[2*i-1] := 0

    else TDBuf(FFT.DataBuffer^)[2*i-1] := 1;

  TDBuf(FFT.DataBuffer^)[2*i] := 0;  { the imaginary part }

  end;

...


 ImagMax

See also:	ImagMin, RealMax, PowerMax, ImagSpec

Class:	TFastFourier

Declaration	function ImagMax: double;

The read-only property ImagMax returns the maximum value of the imaginary part of the Fourier spectrum.


 ImagMin

See also:	ImagMax, RealMin, ImagSpec

Class:	TFastFourier

Declaration	function ImagMin: double;

The read-only property ImagMin returns the minimum value of the imaginary part of the Fourier spectrum.


ImagSpec property
 ImagSpec

See also:	RealSpec, PowerSpec, ImagMax, ImagMin, DataBuffer

Class:	TFastFourier

Declaration:	property ImagSpec[ix: integer]: double;

The array property ImagSpec provides access to the imaginary part of the spectrum. The index ix may assume values between 1 and SpectrumSize. Accessing any value of the array below 1 and above SpectrumSize will result in a zero value on read, or in no action on write.

Note:	Since the index of the data buffer starts with 1 (and not 0), the index of the harmonics of the resulting Fourier spectrum is shifted by one. Thus the constant coefficient a0 is stored in ImagSpec[1], the first harmonic in ImagSpec[2], the second in ImagSpec[3], and so on.


 InverseTransform

See also:	Transform

Class:	TFastFourier

Declaration:	procedure InverseTransform;

The procedure InverseTransform calculates the inverse Fourier transform of the Fourier spectrum stored in the array properties RealSpec and ImagSpec.


 PowerMax

See also:	ImagMax, RealMax, PowerSpec

Class:	TFastFourier

Declaration	function PowerMax: double;

The read-only property PowerMax returns the maximum value of the power spectrum. Note that PowerMax does not include the constant part of the power spectrum (index 1 of property PowerSpec).


PowerSpec property
 PowerSpec

See also:	RealSpec, ImagSpec, PowerMax

Class:	TFastFourier

Declaration:	property PowerSpec[ix: integer]: double;

The array property PowerSpec provides access to the power spectrum. The index ix may assume values between 1 and SpectrumSize. Accessing any value of the array below 1 and above SpectrumSize will result in a zero value on read, or in no action on write.

Note:	Since the index of the data buffer starts with 1 (and not 0), the index of the harmonics of the resulting Fourier spectrum is shifted by one. Thus the constant coefficient a0 is stored in PowerSpec[1], the first harmonic in PowerSpec[2], the second in PowerSpec[3], and so on.


 RealMax

See also:	RealMin, ImagMax, PowerMax, RealSpec

Class:	TFastFourier

Declaration	function RealMax: double;

The read-only property RealMax returns the maximum value of the real part of the Fourier spectrum.


 RealMin

See also:	RealMax, ImagMin, RealSpec

Class:	TFastFourier

Declaration	function RealMin: double;

The read-only property RealMin returns the minimum value of the real part of the Fourier spectrum.


RealSpec property
 RealSpec

See also:	ImagSpec, PowerSpec, RealMax, RealMin, DataBuffer

Class:	TFastFourier

Declaration:	property RealSpec[ix: integer]: double;

The array property RealSpec provides access to the real part of the spectrum. The index ix may assume values between 1 and SpectrumSize. Accessing any value of the array below 1 and above SpectrumSize will result in a zero value on read, or in no action on write.

Note:	Since the index of the data buffer starts with 1 (and not 0), the index of the harmonics of the resulting Fourier spectrum is shifted by one. Thus the constant coefficient a0 is stored in RealSpec[1], the first harmonic in RealSpec[2], the second in RealSpec[3], and so on.


SpectrumSize property
 SpectrumSize

See also:

Class:	TFastFourier

Declaration:	property SpectrumSize: integer;

The property SpectrumSize determines the length of the data array used for the Fourier transform. SpectrumSize must be a power of 2, with a minimum value of 4 and a maximum of 32768 points. Setting SpectrumSize to a value other than a power of 2 will result in an error message.

Hint:	If the number of data to be transformed differs from a power of 2, you should fill the unused elements of the data buffer with zero values.


 Transform

See also:	InverseTransform, WeightingWindow

Class:	TFastFourier

Declaration:	procedure Transform;

The method Transform calculates the Fourier transform of the signal as stored in the array properties RealSpec and ImagSpec. Before transformation takes place the signal is weighted by a function specified by the property WeightingWindow. The result of the transformation replaces the original data in these properties.


 TFastFourierWgtWin

See also:	WeightingWindow

Class:	TFastFourier

Declaration:	TFastFourierWgtWin = (fwRectangle, fwTriangle, fwCos2, fwGauss, fwHamming, fwBlackman);

The type declaration TFastFourierWgtWin specifies the available weighting windows.


 WeightingWindow

See also:	Transform

Class:	TFastFourier

Declaration:	property  WeightingWindow: TFastFourierWgtWin;

A signal sampled for a limited amount of time may exhibit a distorted Fourier spectrum. In order to minimize this distortion, the signal may be multiplied by a weighting function which reduces the signal towards zero at both ends of the sampling window. Several weighting windows are provided by TFastFourier:

fwRectangle	rectangle window (no weighting function)

fwTriangle	triangular window

fwCos2	cosine-squared window

fwGauss	Gaussian window

fwHamming	Hamming window

fwBlackman	Blackman window

Note that selecting the right window is always a compromise and some kind of art.


 Delphi and C++Builder Issues

See also:	Installation of FOURIER

Any component of SDL comes for both the Delphi and the C++Builder environment. Thus, you get full support both for Delphi and C++Builder with our components. The following general directory layout of the delivered zip files makes it easier to access the parts you need:

Please note, that the RES files of the sample applications are supplied both as a 16-bit and a 32-bit version (denoted by the extension RES16, and RES32). You have to rename the proper version to RES before compiling the sample applications.


registration of shareware
 Registration of FOURIER

See also:	How to order

The unit FOURIER is a shareware component. You can register it for US$ 10.00. In return, you get the newest version of FOURIER and unlimited free updates by email. The registered version is, of course, fully functional and does no longer need the Delphi, or the C++Builder IDE. The user may then create stand-alone programs which can be deployed without paying any further licences.

The sources of FOURIER are available separately at a price of US$ 50,-.

 Click here for further details and infos on available discounts.


 Installation of FOURIER

See also:	Delphi and C++Builder Issues

The installation of the component is a two-part process. First you have to install the component into the Delphi (C++ Builder) VCL by following the instructions in the Delphi (C++Builder) manual.  Secondly, you should install the help file of this component into the help system of Delphi (C++ Builder).

Delphi installation

C++ Builder installation


 How to use TFastFourier

See also:	Installation of FOURIER

The application of TFastFourier is straightforward. First, put as many FFT components as needed on a form and specify the proper data array size(s) by setting the property SpectrumSize. In order to calculate the Fourier spectrum, fill in the RealSpec array property with the data and call the method Transform. Optionally, you may set the property WeightingWindow, in order to suppress windowing artefacts. Thereafter the results of the transform is available from the array properties RealSpec (real part of the complex spectrum) and ImagSpec (imaginary part). The original data in RealSpec will be lost. In addition, you may retrieve the corresponding power spectrum from the property PowerSpec.

The inverse transformation can be achieved quite similarly: fill the properties RealSpec and ImagSpec with the Fourier spectrum and call the method InverseTransform. For high speed applications, the data buffer of the FFT algorithm may be accessed directly by the property DataBuffer.

You may also have a look at the sample programs which are delivered with the unit FOURIER.


 Interface of FOURIER

Note: you may have to switch to small fonts to get a legible interface list.

type

  TFastFourierWgtWin = (fwRectangle, fwTriangle, fwCos2, fwGauss,

                        fwHamming, fwBlackman);

  TFastFourier = class (TComponent)

    private

      FNumData       : integer;      { size of data array, must be 2^n }

      FData          : pointer;

      FWgtWin        : TFastFourierWgtWin;

      MaxValuesValid : boolean;

      FMaxReal       : double;

      FMaxImag       : double;

      FMinReal       : double;

      FMinImag       : double;

      FMaxPower      : double;

      function  GetRealVal(ix: integer): double;

      procedure SetRealVal (ix: integer; v: double);

      function  GetImagVal(ix: integer): double;

      procedure SetImagVal (ix: integer; v: double);

      procedure SetNumData (ndata: integer);

      procedure SetWgtWin (ww: TFastFourierWgtWin);

      function  GetPowerSpec (ix: integer): double;

      function  GetMaxPower: double;

      function  GetMaxReal: double;

      function  GetMaxImag: double;

      function  GetMinReal: double;

      function  GetMinImag: double;

      procedure DoFFT (isign: integer);

      procedure CalcMaxValues;

    public

      constructor Create(AOwner: TComponent); override;

      destructor Destroy; override;

      property  RealSpec[ix: integer]: double read GetRealVal write SetRealVal;

      property  ImagSpec[ix: integer]: double read GetImagVal write SetImagVal;

      procedure Clear;

      procedure ClearImag;

      procedure ClearReal;

      procedure Transform;

      procedure InverseTransform;

      property  PowerSpec[ix: integer]: double read GetPowerSpec;

      property  PowerMax: double read GetMaxPower;

      property  RealMax: double read GetMaxReal;

      property  ImagMax: double read GetMaxImag;

      property  RealMin: double read GetMinReal;

      property  ImagMin: double read GetMinImag;

      property  DataBuffer: pointer read FData;

    published

      property  SpectrumSize: integer read FNumData write SetNumData;

      property  WeightingWindow: TFastFourierWgtWin read FWgtWin write SetWgtWin;

    end;


 How to order

Back to the Contents

For registration please run the program REGISTER.EXE (which prints the registration form) and send the printed form together with the proper amount of money (preferrably credit cards or cash, for cheques please add US$ 5,-) to the following address:

   Software Development Lohninger

   P.O.B. 123

   A-1061 Vienna

   Austria, Europe

   email: helpdesk@lohninger.com

The components are preferrably delivered by email. For quick delivery (within 24 hours), please fax the order form (credit card orders, only) to the fax number indicated at our home page:

http://www.lohninger.com/

There are several additional Delphi / C++Builder components, and other software products available from SDL. Ordering several components (w/o source code) together will entitle you to a discount:

2 components	-10 %

3..5 components	-20 %

more than 5	-30 %

Special offer 1: The maximum registration fee is limited to US$55,- (take all components and pay only US$ 55,-). This special offer and the discount are not applicable to the prices of the sources.

Special offer 2: Purchase the sources of all of our components for only US$410,-

Both offers include

•	unlimited free updates by email

•	free registered copies of any future components

•	free support for both the Delphi and the C++Builder version of the components

For the latest release of SDL´s Delphi and C++Builder components and for pricing information see http://www.lohninger.com/ or write to the address above.


A personal remark

We are putting much effort into the production of  most reliable components and units for other programmers. Everybody  who is using our software gets our expertise at a competitive price. But this is only possible if everybody who uses our software, registers it and pays for it. So, if you don't want to kill the shareware idea, don't hesitate to support our work and register this piece of software.

Hans Lohninger

Vienna, Austria.


Installing under C++Builder
 C++Builder Installation

See also:	Delphi installation

1. Installing the component into the C++ Builder VCL

1.1	Copy the OBJ, and the DCR files to the directory where the C++ Builder library is located  (XXX/CBuilder/Lib).

1.2	Copy the HPP file into the include directory (XXX/CBuilder/Include)

1.3	If not already running, start up C++Builder.

1.4	Click on Component, and then on Install. You can now add the new component by using the Add button (browsing for the OBJ  file is most convenient).

1.5	After you have added all the components to be installed, click on OK. C++ Builder will then add the selected components to the VCL on a palette entry called LoComp.

2. Adding the help file to the C++Builder help system

2.1  (optional) Copy the HLP file(s) to the help directory of C++Builder

2.2  Run the OpenHelp application from the C++Builder group menu.

2.3  Click on the Add button, and add the help file(s) to the Available Help Files list

2.4  Select the help file(s) and click on >

2.5  Click on OK. Thereafter the C++Builder help system knows about the new component(s).

As an alternative, you could install the cumulative help file LOCOMP.HLP which covers all components of SDL. The cumulative help is available for free at the following web site:

htpp://www.lohninger.com/


Installing under Delphi
 Delphi Installation

See also:	C++ Builder installation

1. Installing the component into the Delphi VCL

1.0	There are several subdirectories in the distributed package named delphi10, delphi20, delphi30, and cppbuild. Select the proper subdirectory.

1.1  Copy the DCU, RES, DFM, and DCR files to the directory where the Delphi library is located. If not already running, start up Delphi.

1.2a  Delphi 1: click on Options, and then Install Components.

1.2b  Delphi 2: click on Component, and then on Install..

You can now add the new component by using the Add button (browsing for the DCU file is most convenient).

1.2c	Delphi 3: click on Component, and then on Install Component....

You can now add the new component by selecting the proper package and browsing for the DCU file of the component to be installed.

1.3  After you have added all the components you want to install, click on OK. Delphi will then add the selected components to the VCL on a palette entry called LoComp.

2. Merging the help keywords into the master help index

2.1  Copy the HLP and the KWF files to the directory where the master help file DELPHI.HLP is located (usually \DELPHI\BIN).

2.2  Run the HELPINST application from the Delphi group menu.

2.3  Open the master index DELPHI.HDX

2.4  Add the keyword file (.KWF)

2.5 	Save and compile the new index. Thereafter the Delphi master help index includes the keywords for the component's Help screens.

As an alternative, you could install the cumulative help file LOCOMP.HLP into the Delphi Tools menu. This approach is far better and much more reliable than merging the help files into the master help index (at least for Delphi 1). The cumulative help is available for free at the following web site:

htpp://www.lohninger.com/

-------------------------------

Note:	Assure yourself that the PATH environment variable includes the directory where the help file is stored. Otherwise the Windows help system will not find the new help file. Alternatively, you can copy the help file to the Windows directory.


Free Additional Help Files

Back to the Contents

For technical reasons, this help file is restricted to a single component or unit. If you want to have the cumulative help for all components available from SDL, you may download a free copy of the cumulative help from one of the following web sites:

http://www.lohninger.com/

or

http://qspr03.tuwien.ac.at/lo/