Click or drag to resize
Accord.NET (logo)

Signal Class

Represents a discrete signal (measured in time).
Inheritance Hierarchy
SystemObject
  Accord.AudioSignal
    Accord.AudioComplexSignal

Namespace:  Accord.Audio
Assembly:  Accord.Audio (in Accord.Audio.dll) Version: 3.8.0
Syntax
public class Signal : IDisposable
Request Example View Source

The Signal type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyChannels
Gets the number of channels of this signal.
Public propertyData
Gets a pointer to the first sample of the signal.
Public propertyDuration
Gets the signal duration in milliseconds.
Public propertyLength
Gets the number of samples in each channel of this signal, as known as the number of frames in the signal.
Public propertyRawData
Gets the raw binary data representing the signal.
Public propertySampleFormat
Gets the sample format used by this signal.
Public propertySampleRate
Gets the number of samples per second for this signal.
Public propertySamples
Gets the total number of samples in this signal.
Top
Methods
  NameDescription
Public methodCopyTo(Array)
Copies this signal to a given array.
Public methodCopyTo(Double)
Copies this signal to a given array.
Public methodCopyTo(Single)
Copies this signal to a given array.
Public methodDispose
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Protected methodDispose(Boolean)
Releases unmanaged and - optionally - managed resources
Public methodStatic memberDurationOfSamples
Gets the duration of each sample in a signal with the given number of samples and sampling rate.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Releases unmanaged resources and performs other cleanup operations before the Signal is reclaimed by garbage collection.
(Overrides ObjectFinalize.)
Public methodStatic memberFromArray(Array, Int32, SampleFormat)
Creates a new Signal from a float array.
Public methodStatic memberFromArray(Array, Int32, Int32, SampleFormat)
Creates a new Signal from a float array.
Public methodStatic memberFromArray(Array, Int32, Int32, Int32, SampleFormat)
Creates a new Signal from a float array.
Public methodStatic memberFromFile
Loads a signal from a file, such as a ".wav" file.
Public methodCode exampleGetEnergy
Computes the signal energy.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetSample
Gets the value of the specified sample in the Signal.
Public methodStatic memberGetSampleSize
Gets the size (in bits) of a sample format.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodStatic memberNumberOfSamples
Gets the number of samples contained in a signal of given duration and sampling rate.
Public methodSetSample
Sets the value of the specified sample in the Signal.
Public methodToComplex
Converts this signal to a ComplexSignal object.
Public methodToDouble
Converts this signal into a array of floating-point samples.
Public methodToFloat
Converts this signal into a array of floating-point samples.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodSplit(Int32, Int32)Overloaded.
Splits a signal using a window
(Defined by Extensions.)
Public Extension MethodSplit(IWindow, Int32)Overloaded.
Splits a signal using a window
(Defined by Extensions.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

A real discrete-time signal is defined as any real-valued function of the integers.

In signal processing, sampling is the reduction of a continuous signal to a discrete signal. A common example is the conversion of a sound wave (a continuous-time signal) to a sequence of samples (a discrete-time signal).

A sample refers to a value or set of values at a point in time and/or space.

Examples
// create an empty audio signal 
Signal signal = new Signal(channels, length, sampleRate, format);
float[,] data = 
{
    {  0.00f, 0.2f  },
    {  0.32f, 0.1f  },
    {  0.22f, 0.2f  },
    {  0.12f, 0.42f },
    { -0.12f, 0.1f  },
    { -0.22f, 0.2f  },
};

// or create an audio signal from an array of audio frames
Signal target = Signal.FromArray(data, sampleRate: 8000);

It is also possible to load signals from a file or stream, as long as you have a decoder for the given format available. For example, in order to load a .wav file using DirectSound, please add a reference to Accord.Audio.DirectSound and run the following code snippet:

// Let's say we would like to compute the energy of an audio signal. For this,
// we will take an example signal from the Free Spoken Digits Dataset (FSDD):
FreeSpokenDigitsDataset fsdd = new FreeSpokenDigitsDataset(basePath);
Signal signal = fsdd.GetSignal(digit: 3, speaker: "jackson", index: 0);

// The energy is defined as the sum of squared values in all 
// channels of the audio signal. In this case, it should be:
double energy = signal.GetEnergy(); // 19.448728048242629
See Also