Description
Components Overview
Units
Global functions
Data types
Examples
Components
Overview
The library contains two components:
TdspIIRFilter - Implementation of
the Infinite Impulse Response filter
TdspFFT - Implementation
of Fast Fourier Transform
Units
dspIIRFilters.pas - contains the
implementation of TdspIIRFilter component
dspFFT.pas - implementation of TdspFFT component
dspTypes.pas - contains the base types
dspComplex.pas - set of functions to work with complex numbers
dspWindow.pas - implementation of window functions
Global functions
Unit dspWindow
function dspGetWindowValue(Window:
TdspWindow; Index, Length: Integer): TdspSingle;
This function returns the window value for specified
window function at the Index position. The Length parameter specifies
the window length.
procedure
dspCalculateWindow(Window: TdspWindow; Data: PdspSingle; Length:
Integer);
This procedure calculates the window values for specified
Window function. The values will be stored in the Data parameter. The
window length and length of data are specified in the length parameter.
procedure dspApplyWindow(Window:
TdspWindow; Data: PdspSingle; Length: Integer);
This procedure applies the specified window to the data. The length
parameter is the window length.
Unit dspComplex
function cmpxInit (Re:
TdspFloat; Im: TdspFloat = 0.0): TdspComplex; overload;
This function converts Re and Im to complex
procedure cmpxInit (var Z:
TdspComplex; Re: TdspFloat; Im: TdspFloat = 0.0); overload;
This procedure converts Re and Im to complex Z
function cmpxNeg (Z: TdspComplex) :
TdspComplex;
This function returns negated value of complex number
function cmpxSqr (Z: TdspComplex) :
TdspComplex;
This function returns the square of Z
function cmpxSqrt (Z: TdspComplex)
: TdspComplex;
This function returns the square root of Z
function cmpxSqrtx (V: TdspFloat) :
TdspFloat;
This function returns the square root of V. If V < 0 then function
returns 0.
function cmpxExp (Z: TdspComplex) :
TdspComplex;
This function returns exponent raised to Z (e^Z)
function cmpxExpj (V: TdspFloat) :
TdspComplex;
This function returns exponent raised to jV (e^jV)
function cmpxHypot (Z: TdspComplex)
: TdspFloat;
This function returns the hypotenuse of Z.
function cmpxArcTan2 (Z:
TdspComplex) : TdspFloat;
This function returns the arctan of Z
function cmpxConj (Z: TdspComplex)
: TdspComplex;
This function returns conjugate of Z
function cmpxMul (Z: TdspComplex;
V: TdspFloat) : TdspComplex; overload;
This function multiplies a complex and a real
function cmpxMul (Z1, Z2:
TdspComplex) : TdspComplex; overload;
This function multiplies two complex numbers
function cmpxDiv (Z: TdspComplex;
V: TdspFloat) : TdspComplex; overload;
This function divides Z with R
function cmpxDiv (Z1, Z2:
TdspComplex) : TdspComplex; overload;
This function divides two complex numbers
function cmpxAdd (Z1, Z2:
TdspComplex) : TdspComplex;
This function adds two complex numbers
function cmpxSub (Z1, Z2:
TdspComplex) : TdspComplex;
This function substracts two complex numbers
Data types
TdspIIRFilterOrder
= 1..8
The order of IIR filter.
TdspIIRFilterKind
= (fkButterworth, fkChebyshev, fkBessel)
The characteristics of IIR filter.
TdspIIRFilterResponse
= (ftLowpass, ftHighpass, ftBandpass, ftBandstop)
The frequency response of IIR filter. Lowpass, Highpass, Bandpass or
Bandstop, respectively.
TdspIIRFilterProc =
function(V: TdspFloat): TdspFloat of object
The filter procedure.
TdspFFTPower
= 2..15
The power of 2. Uses in FFT.
TdspWindow =
(fwNone, fwHamming, fwHanning, fwBlackman, fwGaussian, fwWelch,
fwParzen)
The window function.
TdspFloat =
Extended
TdspFloatArray =
Array[0..High(Integer) div Sizeof(TdspFloat) - 1] of TdspFloat
PdspFloatArray = ^TdspFloatArray
TdspSingle = Single;
PdspSingle = ^TdspSingle;
TdspSingleArray =
Array[0..High(Integer) div Sizeof(TdspSingle) - 1] of TdspSingle
PdspSingleArray = ^TdspSingleArray
TdspIntArray = Array[0..High(Integer)
div Sizeof(Integer)-1] of Integer
PdspIntArray = ^TdspIntArray
TdspIIRFilter
This component implements an infinite
impulse response digital filter. Lowpass, highpass, bandpass and
bandstop filters, with Butterworth, Bessel or Chebyshev
characteristics, are designed using the bilinear transform.
property Kind: TdspIIRFilterKind
The characteristics of IIR filter. You can design the
filter with Butterworth, Bessel or Chebyshev characteristics.
property Response: TdspIIRFilterResponse
The frequency response of the filter. You can design the filter with
Lowpass, Highpass, Bandpass or Bandstop frequency response.
property Order: TdspIIRFilterOrder
The order of the filter.
property Frequency1: TdspFloat
property Frequency2: TdspFloat
The corner (–3 dB) frequencies. For lowpass and highpass filters, only
Frequency1 is required. For bandpass and bandstop filters, both
Frequency1 (the lower corner frequency) and Frequency2 (the upper
corner frequency) are required. The valid values: 0 < Frequency1
< SampleRate / 2; 0 < Frequency2 < SampleRate / 2; Frequency1
< Frequency2.
property SampleRate: TdspFloat
The sampling rate of signal.
property Ripple: TdspFloat
The passband ripple in dB, meaningful for Chebyshev filter only.
Filter: TdspIIRFilterProc
Or function Filter(InputValue: TdspFloat): TdspFloat;
Processing input value according to filter parameters. The result is
filtered value. Data can be processed in real time. For example, you
can process the audio stream in real time.
Note: In some cases the filter is astable. This effect
occurs when the value of Alpha1=Frequency1/SampleRate is small (less
then 0.001) or the value of equation (Frequency2 - Frequency1) /
SampleRate (for filters with bandpass and bandstop frequency responses)
is small (<0.01).
procedure Reset
This procedure clears internal buffers.
function
GetFrequencyResponse(Frequency: TdspSingle): TdspSingle
This procedure returns a frequency response.
property ManualReset: Boolean
Set this property to true if you want to change the filter parameters
(frequencies and filter kind) during data processing. Usually
(ManualReset = false) when the filter parameters are changed the
internal buffers are cleared. So you can get some distortions at the
processed signal.
property Info: String
This property contains filter information: gain, input and output
coefficients.
property LastError: String
This description of the error.
TdspFFT
This component implements a fast fourier
transform and inverse fast fourier transform with single floating point
precision.
RealIn, ImagIn: PdspSingleArray
Input data for FFT.
RealOut, ImagOut: PdspSingleArray
Output data.
procedure Clear
This procedure zeros the input and output data.
procedure FFT
This procedure does FFT.
procedure IFFT
This procedure does inverse FFT.
procedure CalculateMagnitudes
This procedure calculates the spectrum of signal.
property BufferSize2: Integer
A half of buffer size.
property Power: TdspFFTPower
A power of 2. The buffer size = 2^Power.
property BufferSize: Longint
The buffer size. The value must be a power of 2.
property Window: TdspWindow
The window function for input data.
Examples
Simple FFT
demo - Using FFT to get spectrum of signal
This demo shows how to work with FFT component. The program
generates the signal and fills the FFT buffer with the data. Then the
program calculates FFT and spectrum of signal. And finally, it displays
the input signal and spectrum using TChart component.
Simple IIR Filter demo - Setup
IIR filter and filtering the signal in real time
This demo shows how to work with IIR filter component to
process realtime signal. The program generates a signal. The every
value of signal is passed through the filter. The input and output
values are displayed on the screen. Change the parameters of the filter
and you will see the changes of filtered signal on the chart.
IIR
Plot demo - Plot the frequency response of IIR filter
This
demo shows how to plot the frequency response of IIR filter. You can
change the parameters of filter and plot the frequency respomse on a
chart.
Perfomance - Test the
perfomance of IIR filter and FFT
This demo tests perfomance of calculations for IIR filter and FFT on
your system.
Simple spectrum analyzer -
Sound visualization during recording
This demo shows how to calculate the spectrum of recorded
signal in realtime.
Simple player - Sound processing and visualization during playing
wav-files
This demo shows how to build a timbre block, graphical equalizer and
spectrum analyzer. The timbre block uses IIR Filter components. The
graphical equalizer uses FFT components and FFT convolution method to
filter signal. The spectrum analyzer uses FFT components. Please see
the source code of demos for more details.
|