Code Packages  1
Add-on code processing modules
Static Public Member Functions | List of all members
dsp.Transform Class Reference

Provides functions for discrete signal transformations More...

Static Public Member Functions

static Complex Analysis (Complex[] A, int k)
 Returns the frequency component of a complex array using indexing in frequency domain More...
 
static double [] DCT (double[] A)
 "Discrete Cosine Transform (DCT-II)" More...
 
static Complex [] DFT (Complex[] A)
 "Discrete Fourier Transform" More...
 
static Complex [] FFT (Complex[] A)
 "Fast Fourier Transform" More...
 
static double [] IDCT (double[] A)
 "Inverse Discrete Cosine Transform (DCT-III)" More...
 
static Complex [] IDFT (Complex[] A)
 "Inverse Discrete Fourier Transform" More...
 
static Complex [] IFFT (Complex[] A)
 "Inverse Fast Fourier Transform" More...
 
static Complex Synthesis (Complex[] A, int n)
 Returns the sample value from a complex frequency domain using indexing in time domain More...
 

Detailed Description

Provides functions for discrete signal transformations

Member Function Documentation

◆ Analysis()

static Complex dsp.Transform.Analysis ( Complex []  A,
int  k 
)
static

Returns the frequency component of a complex array using indexing in frequency domain

The function runs only for the specified index (k) and does not calculate the full frequency spectrum.

Parameters
Acomplex time domain array
kfrequency domain index (0..N-1)
Returns
$\displaystyle c_k=\sum\limits_{n=0}^{N-1}A[n]e^{-j2\pi nk/N}$

Example

Complex[] c = new Complex[4] { new Complex(0.3535, 0), new Complex(0.6464, 0), new Complex(1.0607, 0), new Complex(-0.3535, 0) };
Complex res = Transform.Analysis(c, 2);
res = Complex.Round(res, 8);
Console.WriteLine(res);
1.1213+0i

◆ DCT()

static double [] dsp.Transform.DCT ( double []  A)
static

"Discrete Cosine Transform (DCT-II)"

Parameters
Areal array


Example

double[] A = new double[5] { 1, -2, 3, 2, -1 };
A = Transform.DCT(A);
Console.WriteLine(NArray.toString(A));
1.34164078649987 -0.283990227825646 -1.89736659610103 3.14949988895055 1.89736659610103

◆ DFT()

static Complex [] dsp.Transform.DFT ( Complex []  A)
static

"Discrete Fourier Transform"

The length of the returned frequency spectrum is equal to the size of the input array.

Parameters
Acomplex time domain array
Returns
$\displaystyle c[k]= \sum\limits_{n=0}^{N-1} A[n]e^{-j2\pi nk/N} \hspace{1cm}, 0\leq k \leq N-1$

Example

Complex[] c = new Complex[4] { new Complex(0.3535, 0), new Complex(0.6464, 0), new Complex(1.0607, 0), new Complex(-0.3535, 0) };
Complex[] res = Transform.DFT(c);
res = NArray.Round(res, 8);
Console.WriteLine(NArray.ToString(res));
1.7071+0i -0.7072-0.9999i 1.1213+0i -0.7072+0.9999i

◆ FFT()

static Complex [] dsp.Transform.FFT ( Complex []  A)
static

"Fast Fourier Transform"

For arbitrary size time domain array, the NArray.PaddRadix2 function can be used with zero value padding before the FFT.
For a real time domain array, the NArray.RealToComplex function can be used to convert a real array into a complex array.
If the application uses only positive frequencies, the NArray.Range function can be used to extract them.

Parameters
Acomplex time domain array. Size must be a power of 2
Returns
Transform.FFT returns the same result as Transform.DFT

Example

Complex[] c = new Complex[4] { new Complex(0.3535, 0), new Complex(0.6464, 0), new Complex(1.0607, 0), new Complex(-0.3535, 0) };
Complex[] res = Transform.FFT(c);
res = NArray.Round(res, 8);
Console.WriteLine(NArray.ToString(res));
1.7071+0i -0.7072-0.9999i 1.1213+0i -0.7072+0.9999i

◆ IDCT()

static double [] dsp.Transform.IDCT ( double []  A)
static

"Inverse Discrete Cosine Transform (DCT-III)"

Parameters
Areal array


Example

double[] A = new double[5] { 1, -2, 3, 2, -1 };
A = Transform.DCT(A);
Console.WriteLine(NArray.toString(A));
A = Transform.IDCT(A);
Console.WriteLine(NArray.toString(A));
1.34164078649987 -0.283990227825646 -1.89736659610103 3.14949988895055 1.89736659610103
1 -2 3 2 -1

◆ IDFT()

static Complex [] dsp.Transform.IDFT ( Complex []  A)
static

"Inverse Discrete Fourier Transform"

The size of the returned complex time domain array is equal to the length of the input frequency domain spectrum.

Parameters
Acomplex array representing frequency spectrum
Returns
$\displaystyle c[n]=\frac{1}{N}\sum\limits_{k=0}^{N-1}A[k]e^{j2\pi nk/N}\hspace{1cm}, 0\leq n \leq N-1 $

Example

Complex[] c = new Complex[4] { new Complex(1.7071, 0), new Complex(-0.7072, -0.9999), new Complex(1.1213, 0), new Complex(-0.7072, 0.9999) };
Complex[] res = Transform.IDFT(c);
res = NArray.Round(res, 8);
Console.WriteLine(NArray.ToString(res));
0.3535+0i 0.6464+0i 1.0607+0i -0.3535+0i

◆ IFFT()

static Complex [] dsp.Transform.IFFT ( Complex []  A)
static

"Inverse Fast Fourier Transform"

Parameters
Acomplex array representing frequency spectrum. Size must be a power of 2
Returns
Transform.IFFT returns the same result as Transform.IDFT.

Example

Complex[] c = new Complex[4] { new Complex(1.7071, 0), new Complex(-0.7072, -0.9999), new Complex(1.1213, 0), new Complex(-0.7072, 0.9999) };
Complex[] res = Transform.IFFT(c);
res = NArray.Round(res, 8);
Console.WriteLine(NArray.ToString(res));
0.3535+0i 0.6464+0i 1.0607+0i -0.3535+0i

◆ Synthesis()

static Complex dsp.Transform.Synthesis ( Complex []  A,
int  n 
)
static

Returns the sample value from a complex frequency domain using indexing in time domain

The function runs only for the specified index (n) and does not calculate the full time domain signal.

Parameters
Acomplex array representing frequency spectrum
ntime domain index
Returns
$\displaystyle c_n= \frac{1}{N} \sum\limits_{k=0}^{N-1} A[k] e^{j2\pi nk/N} $

Example

Complex[] spec = new Complex[] {new Complex(1.7071, 0), new Complex(-0.7072, -0.9999), new Complex(1.1213, 0), new Complex(-0.7072, 0.9999)};
Complex c = Transform.Synthesis(spec, 2);
c = Complex.Round(c, 8);
Console.WriteLine(c);
1.0607+0i