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

Provides basic functions for signal analysis More...

Static Public Member Functions

static double [] Amplitude (double[] A, double dB)
 Amplify/attenuate the amplitude of a real signal by level in decibells (dB) More...
 
static double [] AmplitudeGain (double[] A_out, double[] A_in)
 Returns the amplitude gain in decibels (dB) between an input and an output signal More...
 
static double [] AutoCorrelation (double[] A)
 Perform auto-correlation operation More...
 
static double [] Convolution (double[] A, double[] H)
 Perform convolution operation in time domain More...
 
static double [] CrossCorrelation (double[] A, double[] H)
 Perform cross-correlation operation More...
 
static double [] DecibelToLinear (double[] A)
 Converts signal amplitude from decibels scale to linear More...
 
static T [] Difference< T > (T[] A)
 First-difference function More...
 
static double [] DownSample (double[] A, int factor)
 Reduce the sampling rate of a array by integer factor More...
 
static double [] LinearToDecibel (double[] A)
 Converts signal amplitude from a linear scale to decibels More...
 
static T [] MixDownF< T > (Func< T[], T > f, params T[][] args)
 Function to perform mix-down operations on multiple signals More...
 
static T [] MovingF< T > (T[] A, int size, Func< T[], T > f)
 Function to perform operations on a signal using a moving window More...
 
static double [] Normalize (double[] A)
 Normalize array level in the range from minus one to one (-1:1) More...
 
static double [] NormalizeOne (double[] A)
 Normalize array level to a length of one More...
 
static double [] Power (double[] A, double dB)
 Amplify/attenuate the power of a real signal by level in decibells (dB) More...
 
static double [] PowerGain (double[] A_out, double[] A_in)
 Returns the power gain in decibels (dB) between an input and an output signal More...
 
static T [] RunningSum< T > (T[] A)
 Running-sum function More...
 
static T [] SeriesF< T > (T[] A, Func< T, T > f)
 Function to perform calculations on each sample of a signal More...
 
static bool [] Threshold (double[] A, double limit)
 Check which samples of an array are below a specified limit More...
 
static double [] ThresholdR (double[] A, double limit)
 Check which samples of an array are below a specified limit More...
 
static double [] UpSample (double[] A, int factor)
 Increase the sampling rate of a array by integer factor. More...
 
static double [] ZeroHold (double[] A, int factor)
 Implements Zero-order hold by an integer factor. More...
 

Detailed Description

Provides basic functions for signal analysis

Member Function Documentation

◆ Amplitude()

static double [] dsp.Signal.Amplitude ( double []  A,
double  dB 
)
static

Amplify/attenuate the amplitude of a real signal by level in decibells (dB)

Parameters
Areal array
dBlevel in decibels
Returns
$\displaystyle res_{i}=A_{i}10^{db/20}$

Example

double[] A = new double[4] { 0, 1, 10, 100 };
A = Signal.Amplitude(A, 20);
Console.WriteLine(NArray.ToString(A));
0 10 100 1000

◆ AmplitudeGain()

static double [] dsp.Signal.AmplitudeGain ( double []  A_out,
double []  A_in 
)
static

Returns the amplitude gain in decibels (dB) between an input and an output signal

Parameters
A_inreal array (input)
A_outreal array (output)
Returns
$\displaystyle res_{i}=20\log_{10}\left(\frac{out_i}{in_i}\right)$

Example

double[] A = new double[4] { 1, 1, 1, 1 };
double[] B = new double[4] { 1, 10, 100, 1000 };
double[] res = Signal.AmplitudeGain(B, A);
Console.WriteLine(NArray.ToString(res));
0 20 40 60

◆ AutoCorrelation()

static double [] dsp.Signal.AutoCorrelation ( double []  A)
static

Perform auto-correlation operation

Auto-correlation performs convolution of one array with the reversed version of itself.
The returned array has length equal to size(A)*2-1

Parameters
Areal array

Example

double[] A = new double[8] { 1, 0, 1, 0, 1, 0, 1, 0 };
A = Signal.AutoCorrelation(A);
Console.WriteLine(NArray.ToString(A));
0 1 0 2 0 3 0 4 0 3 0 2 0 1 0

◆ Convolution()

static double [] dsp.Signal.Convolution ( double []  A,
double []  H 
)
static

Perform convolution operation in time domain

The two arrays are fully immersed each other. The returned array has length equal to size(A)+size(H)-1

Parameters
Areal array
Hreal array (kernel)

Example

double[] A = new double[8] { 1, 0, 1, 0, 1, 0, 1, 0 };
double[] h = new double[4] { 1, 0, 1, 0 };
double[] res = Signal.Convolution(A, h);
Console.WriteLine(NArray.ToString(res));
1 0 2 0 2 0 2 0 1 0 0

◆ CrossCorrelation()

static double [] dsp.Signal.CrossCorrelation ( double []  A,
double []  H 
)
static

Perform cross-correlation operation

Cross-correlation performs convolution of one array with the reversed version of the other.
The returned array has length equal to size(A)+size(H)-1.


Parameters
Areal array
Hreal array (kernel)

Example

double[] A = new double[8] { 1, 0, 1, 0, 1, 0, 1, 0 };
double[] h = new double[4] { 1, 0, 1, 0 };
double[] res = Signal.CrossCorrelation(A, h);
Console.WriteLine(NArray.ToString(res));
0 1 0 2 0 2 0 2 0 1 0

◆ DecibelToLinear()

static double [] dsp.Signal.DecibelToLinear ( double []  A)
static

Converts signal amplitude from decibels scale to linear

Parameters
Areal array
Returns
$\displaystyle res_{i}=10^{A_{i}/20}$

Example

double[] A = new double[4] { double.NegativeInfinity, 0, 20, 40 };
A = Signal.DecibelToLinear(A);
Console.WriteLine(NArray.ToString(A));
0 1 10 100

◆ Difference< T >()

static T [] dsp.Signal.Difference< T > ( T []  A)
static

First-difference function

◆ DownSample()

static double [] dsp.Signal.DownSample ( double []  A,
int  factor 
)
static

Reduce the sampling rate of a array by integer factor

Downsample(x,n) decreases the sampling rate of x by keeping every n-th sample starting with the first sample.

Parameters
Areal array
factordown-sampling factor

Example

double[] A = new double[5] { 1, -0.5, 1.5, 0.5, -1};
A = Signal.DownSample(A, 2);
Console.WriteLine(NArray.toString(A));
1 1.5 -1

◆ LinearToDecibel()

static double [] dsp.Signal.LinearToDecibel ( double []  A)
static

Converts signal amplitude from a linear scale to decibels

Parameters
Areal array
Returns
$\displaystyle res_{i}=20\log_{10}(A_{i})$

Example

double[] A = new double[4] { 0, 1, 10, 100 };
A = Signal.LinearToDecibel(A);
Console.WriteLine(NArray.ToString(A));
-Infinity 0 20 40

◆ MixDownF< T >()

static T [] dsp.Signal.MixDownF< T > ( Func< T[], T >  f,
params T  args[][] 
)
static

Function to perform mix-down operations on multiple signals

MixDownF can handle input functions that have more than one parameter by using the lamda operator =>
The size of the return array is equal to the first input array.

Parameters
finput function which returns a single number and takes as input an array
argsmultiple arrays

Example

double[] x = new double[] { 4, 2, 3};
double[] y = new double[] { 1, 4, 6 };
double[] z = new double[] { 4, 6 , 9};
double[] res = Signal.MixDownF(Statistics.Average, x, y, z);
Console.WriteLine(NArray.ToString(res));
3 4 6

◆ MovingF< T >()

static T [] dsp.Signal.MovingF< T > ( T []  A,
int  size,
Func< T[], T >  f 
)
static

Function to perform operations on a signal using a moving window

MovingF can handle input functions that have more than one parameter by using the lamda operator =>
The size of the return array is equal to the input array.

Parameters
Aarray
sizesize of window (buffer)
finput function which returns a single number and takes as input an array


Example

double[] data = new double[] { 1, 4, 6, 8 };
double[] res = Signal.MovingF(data, 3, Statistics.Average);
res = NArray.Round(res, 1);
Console.WriteLine(NArray.ToString(res));
0.3 1.7 3.7 6

◆ Normalize()

static double [] dsp.Signal.Normalize ( double []  A)
static

Normalize array level in the range from minus one to one (-1:1)

Parameters
Areal array

Example

double[] A = new double[4] { -10, 10, -5, 5 };
A = Signal.Normalize(A);
Console.WriteLine(NArray.ToString(A));
-1 1 -0.5 0.5

◆ NormalizeOne()

static double [] dsp.Signal.NormalizeOne ( double []  A)
static

Normalize array level to a length of one

Parameters
Areal array

Example

double[] A = new double[2] { 1, 3};
A = Signal.NormalizeOne(A);
Console.WriteLine(NArray.ToString(A));
0.316227766016838 0.948683298050514

◆ Power()

static double [] dsp.Signal.Power ( double []  A,
double  dB 
)
static

Amplify/attenuate the power of a real signal by level in decibells (dB)

Parameters
Areal array
dBlevel in decibels
Returns
$\displaystyle res_{i}=A_{i}10^{db/10}$

Example

double[] A = new double[4] { 0, 1, 10, 100 };
A = Signal.Power(A, 10);
Console.WriteLine(NArray.ToString(A));
0 10 100 1000

◆ PowerGain()

static double [] dsp.Signal.PowerGain ( double []  A_out,
double []  A_in 
)
static

Returns the power gain in decibels (dB) between an input and an output signal

Parameters
A_inreal array (input)
A_outreal array (output)
Returns
$\displaystyle res_{i}=10\log_{10}\left(\frac{out_i}{in_i}\right)$

Example

double[] A = new double[4] { 1, 1, 1, 1 };
double[] B = new double[4] { 1, 10, 100, 1000 };
double[] res = Signal.PowerGain(B, A);
Console.WriteLine(NArray.ToString(res));
0 10 20 30

◆ RunningSum< T >()

static T [] dsp.Signal.RunningSum< T > ( T []  A)
static

Running-sum function

◆ SeriesF< T >()

static T [] dsp.Signal.SeriesF< T > ( T []  A,
Func< T, T >  f 
)
static

Function to perform calculations on each sample of a signal

SeriesF can handle input functions that have more than one parameter by using the lamda operator =>

Parameters
Aarray
finput function which returns a number


Example 1

double[] A = new double[] { 1, 2, 3};
double[] res = Signal.SeriesF(A, Math.Sqrt);
Console.WriteLine(NArray.ToString(res));
1 1.4142135623731 1.73205080756888

Example 2

double[] A = new double[] { 1, 2, 3};
double[] res = Signal.SeriesF(A, d=> d * d);
Console.WriteLine(NArray.ToString(res));
1 4 9

◆ Threshold()

static bool [] dsp.Signal.Threshold ( double []  A,
double  limit 
)
static

Check which samples of an array are below a specified limit

Parameters
Areal array
limitmaximum value
Returns
Returns True if sample value is equal to or greater than limit, else False

Example

double[] A = new double[] { 3, 1, 4, 2};
bool[] res = Signal.Threshold(A, 2);
Console.WriteLine(NArray.ToString(res));
True False True True

◆ ThresholdR()

static double [] dsp.Signal.ThresholdR ( double []  A,
double  limit 
)
static

Check which samples of an array are below a specified limit

Parameters
Areal array
limitmaximum value


Returns
Returns 1 if sample value is equal to or greater than limit, else 0

Example

double[] A = new double[] { 3, 1, 4,2};
double[] res = Signal.ThresholdR(A, 2);
Console.WriteLine(NArray.ToString(res));
1 0 1 1

◆ UpSample()

static double [] dsp.Signal.UpSample ( double []  A,
int  factor 
)
static

Increase the sampling rate of a array by integer factor.

upsample(x,n) increases the sampling rate of x by inserting n-1 zeros between samples.

Parameters
Areal array
factorup-sampling factor

Example

double[] A = new double[5] { 1, -0.5, 1.5, 0.5, -1};
A = Signal.UpSample(A, 2);
Console.WriteLine(NArray.toString(A));
1 0 -0.5 0 1.5 0 0.5 0 -1 0

◆ ZeroHold()

static double [] dsp.Signal.ZeroHold ( double []  A,
int  factor 
)
static

Implements Zero-order hold by an integer factor.

Parameters
Areal array
factorzero-hold factor

Example

double[] A = new double[5] { 1, -0.5, 1.5, 0.5, -1};
A = Signal.ZeroHold(A, 2);
Console.WriteLine(NArray.toString(A));
1 1 -0.5 -0.5 1.5 1.5 0.5 0.5 -1 -1