ShortTimeBandPower - Maple Help

SignalProcessing

 ShortTimeBandPower
 calculate the short-time band power of a 1-D signal
 ShortTimeMeanFrequency
 calculate the short-time mean frequency of a 1-D signal
 ShortTimeSpectralEntropy
 calculate the short-time spectral entropy of a 1-D signal

 Calling Sequence ShortTimeBandPower( signal, options ) ShortTimeMeanFrequency( signal, options ) ShortTimeSpectralEntropy( signal, options )

Parameters

 signal - 1-D rtable or list of data.

Options

 • samplerate: (optional) Positive numeric value for the sampling rate. The default is 1.0.
 • overlapsize: (optional) Non-negative integer which specifies the target minimum overlap size of the segments. The default is 0.
 • segmentsize: (optional) Positive integer for the size of the overlapping segments. The default is the largest power of 2 that is not larger than the size of signal.
 • fftnormalization: (optional) One of none, symmetric, or full, indicates the normalization to be applied when using the Fast Fourier Transform (FFT). The default is symmetric.
 • temperendpoints: (optional) Either true or false, specifies whether the short-time power spectra are to be tempered at the endpoints. The default is false.
 • window: (optional) Either a list, name, or string, specifies the windowing command to be applied to the overlapping segments. The default is "none" (for no windowing to be applied). If a list is passed, the first element provides the name of the windowing command, and any remaining terms are passed as options to the command.
 • windownormalization (optional) Either true or false, indicates if the windowing function is to be normalized. The default is true.
 • frequencyunit: (optional) Unit which specifies the unit of frequency. The default is Unit(Hz). Either of the forms algebraic or Unit(algebraic) is accepted, and the unit must be convertible to a valid unit of frequency.
 • timeunit: (optional) Unit which specifies the unit of time. The default is Unit(s). Either of the forms algebraic or Unit(algebraic) is accepted, and the unit must be convertible to a valid unit of time.
 • frequencyrange: (optional) Range of numeric frequency values used to filter (i.e. band-limit) the data. If omitted, all frequencies are considered.
 • method: (optional) The method of numerical integration to be used to find band power. The options are leftendpoint, rightendpoint, simpson, and trapezoid. The default is trapezoid, which is equivalent to finding the area under the linear interpolation through all the points.
 • bandpowerplotoptions: (optional) List of additional plot options to be passed when creating the band power plot. The default is [].
 • meanfrequencyplotoptions: (optional) List of additional plot options to be passed when creating the mean frequency plot. The default is [].
 • entropyplotoptions: (optional) List of additional plot options to be passed when creating the entropy plot. The default is [].
 • output: (optional) The type of output. The supported options are:
 – bandpower: Returns a Vector of float[8] datatype containing the Short-Time Band Power (STBP). This is the default for ShortTimeBandPower.
 – bandpowerplot: Returns a plot of the bandpower Vector versus time.
 – entropy: Returns a Vector of float[8] datatype containing the Short-Time Spectral Entropy (STSE). This is the default for ShortTimeSpectralEntropy.
 – entropyplot: Returns a plot of the entropy Vector versus time.
 – meanfrequency: Returns a Vector of float[8] datatype containing the Short-Time Mean Frequency (STMF). This is the default for ShortTimeMeanFrequency.
 – meanfrequencyplot: Returns a plot of the meanfrequency Vector versus time.
 – signal: Returns a Matrix of float[8] or complex[8] datatype containing the signal, with each column representing a short-time segment.
 – stps: Returns a Matrix of float[8] datatype containing the Short-Time Power Spectrum (STPS).
 – frequencies: Returns a Vector, of float[8] datatype and length the same as signal, containing the frequencies.
 – times: Returns a Vector, of float[8] datatype and length the same as signal, containing the times.
 – record: Returns a record with the previous options.
 – list of any of the above options: Returns an expression sequence with the corresponding outputs, in the same order.

Description

 • The ShortTimeBandPower, ShortTimeMeanFrequency, and ShortTimeSpectralEntropy commands take a 1-D rtable or list signal, and first compute the Short-Time Power Spectrum (STPS) Matrix $P$ using the ShortTimeFourierTransform command and the provided options. The Short-Time Band Power is the Vector $B$ having elements ${B}_{j}$ calculated as the band power of column $j$ of $P$ using the BandPower command and the provided options, including frequencyrange. The Short-Time Mean Frequency and Short-Time Spectral Entropy are defined in a similar way, and use, respectively, the MeanFrequency and SpectralEntropy commands.
 • The values of $a=\mathrm{overlapsize}$, $b=\mathrm{segmentsize}$, and $n=\mathrm{numelems}\left(\mathrm{signal}\right)$ must satisfy $2\le n$, $0\le a$, $2\le b$, $a, and $b\le n$.
 • Maple will attempt to coerce the provided signal to a 1-D Vector of either float[8] or complex[8] datatype, and an error will be thrown if this is not possible. For this reason, it is most efficient for the passed input to use this datatype.
 • The input signal cannot have an indexing function, and must use rectangular storage.
 • The ShortTimeBandPower, ShortTimeMeanFrequency, and ShortTimeSpectralEntropy commands are not thread safe.
 • As the underlying implementation of the SignalProcessing package is a module, it is also possible to use the forms SignalProcessing:-ShortTimeBandPower, SignalProcessing:-ShortTimeMeanFrequency, and SignalProcessing:-ShortTimeSpectralEntropy to access the commands from the package. For more information, see Module Members.

Examples

 > $\mathrm{with}\left(\mathrm{SignalProcessing}\right):$
 > $\mathrm{with}\left(\mathrm{Statistics}\right):$

Example 1

 > $\mathrm{STBP}≔\mathrm{ShortTimeBandPower}\left(\left[1,10,2,9,3,8,4\right],\mathrm{segmentsize}=4,\mathrm{overlapsize}=2\right)$
 ${\mathrm{STBP}}{≔}\left[\begin{array}{c}{35.7857142857143}\\ {27.7857142857143}\\ {27.9285714285714}\end{array}\right]$ (1)

Example 2

 > $\mathrm{STBP},\mathrm{STMF},\mathrm{STSE}≔\mathrm{ShortTimeMeanFrequency}\left(\left[5,2,8,-3,6\right],\mathrm{segmentsize}=3,\mathrm{overlapsize}=1,\mathrm{output}=\left[\mathrm{bandpower},\mathrm{meanfrequency},\mathrm{entropy}\right]\right)$
 ${\mathrm{STBP}}{,}{\mathrm{STMF}}{,}{\mathrm{STSE}}{≔}\left[\begin{array}{c}{20.4000000000000}\\ {28.6666666666667}\end{array}\right]{,}\left[\begin{array}{c}{0.116129032258065}\\ {0.377981651376147}\end{array}\right]{,}\left[\begin{array}{c}{0.902384060428970}\\ {1.58066498968778}\end{array}\right]$ (2)

Detecting Noise

Pure Signal

 • First, construct a signal over time interval $\left[0,2\mathrm{\pi }\right]$ from a pure sinusoid:
 > $\mathrm{signal_size}≔4096$
 ${\mathrm{signal_size}}{≔}{4096}$ (3)
 > $\mathrm{sample_rate}≔\mathrm{evalhf}\left(\frac{\mathrm{signal_size}-1}{2\mathrm{\pi }}\right)$
 ${\mathrm{sample_rate}}{≔}{651.739491961311387}$ (4)
 > $\mathrm{Times}≔\mathrm{Vector}\left(\mathrm{signal_size},i↦\mathrm{evalhf}\left(\frac{i-1}{\mathrm{sample_rate}}\right),\mathrm{datatype}=\mathrm{float}\left[8\right]\right)$
 ${\mathrm{Times}}{≔}\begin{array}{c}\left[\begin{array}{c}{0.}\\ {0.00153435538636864}\\ {0.00306871077273728}\\ {0.00460306615910592}\\ {0.00613742154547457}\\ {0.00767177693184321}\\ {0.00920613231821185}\\ {0.0107404877045805}\\ {0.0122748430909491}\\ {0.0138091984773178}\\ {⋮}\end{array}\right]\\ \hfill {\text{4096 element Vector[column]}}\end{array}$ (5)
 > $g≔t↦2\cdot \mathrm{sin}\left(\frac{5\cdot t}{3}\right)+7$
 ${g}{≔}{t}{↦}{2}{\cdot }{\mathrm{sin}}{}\left(\frac{{5}{\cdot }{t}}{{3}}\right){+}{7}$ (6)
 > $\mathrm{Signal_Pure}≔\mathrm{Vector}\left(\mathrm{~}\left[g\right]\left(\mathrm{Times}\right),\mathrm{datatype}=\mathrm{float}\left[8\right]\right)$
 ${\mathrm{Signal_Pure}}{≔}\begin{array}{c}\left[\begin{array}{c}{7.}\\ {7.00511451238010}\\ {7.01022899131349}\\ {7.01534340335368}\\ {7.02045771505461}\\ {7.02557189297088}\\ {7.03068590365797}\\ {7.03579971367245}\\ {7.04091328957220}\\ {7.04602659791662}\\ {⋮}\end{array}\right]\\ \hfill {\text{4096 element Vector[column]}}\end{array}$ (7)
 • Now, find the spectral entropy of the pure signal, along with the plot:
 > $\mathrm{segment_size}≔64$
 ${\mathrm{segment_size}}{≔}{64}$ (8)
 > $\mathrm{overlap_size}≔0$
 ${\mathrm{overlap_size}}{≔}{0}$ (9)
 > $\mathrm{Entropy_Vector_Pure},\mathrm{Entropy_Plot_Pure}≔\mathrm{ShortTimeSpectralEntropy}\left(\mathrm{Signal_Pure},\mathrm{samplerate}=\mathrm{sample_rate},\mathrm{segmentsize}=\mathrm{segment_size},\mathrm{overlapsize}=\mathrm{overlap_size},\mathrm{output}=\left[\mathrm{entropy},\mathrm{entropyplot}\right]\right):$
 > $\mathrm{Entropy_Vector_Pure}$
 $\begin{array}{c}\left[\begin{array}{c}{0.00296520382760956}\\ {0.00260395563137417}\\ {0.00218352267109623}\\ {0.00173928565194981}\\ {0.00130198837905704}\\ {0.000897569211105509}\\ {0.000547672047919168}\\ {0.000270582736772162}\\ {0.0000826837105787348}\\ {2.23573657187615}{×}{{10}}^{{-6}}\\ {⋮}\end{array}\right]\\ \hfill {\text{64 element Vector[column]}}\end{array}$ (10)
 > $\mathrm{Entropy_Plot_Pure}$

Noisy Signal

 • Second, we add some noise:
 > $\mathrm{Noise}≔\mathrm{Vector}\left[\mathrm{column}\right]\left(\mathrm{Sample}\left(\mathrm{RandomVariable}\left(\mathrm{Normal}\left(0,5\right)\right),\mathrm{signal_size}\right)\right)$
 ${\mathrm{Noise}}{≔}\begin{array}{c}\left[\begin{array}{c}{-5.36212063999134}\\ {-1.64538935273532}\\ {-3.08545968454895}\\ {1.07233372622645}\\ {-0.127140640211923}\\ {8.64410642088916}\\ {-8.17428377171952}\\ {7.85586085877150}\\ {0.851792107052042}\\ {5.03239204375904}\\ {⋮}\end{array}\right]\\ \hfill {\text{4096 element Vector[column]}}\end{array}$ (11)
 > $\mathrm{Signal_Noisy}≔\mathrm{Signal_Pure}+\mathrm{Noise}$
 ${\mathrm{Signal_Noisy}}{≔}\begin{array}{c}\left[\begin{array}{c}{1.63787936000866}\\ {5.35972515964478}\\ {3.92476930676455}\\ {8.08767712958014}\\ {6.89331707484269}\\ {15.6696783138600}\\ {-1.14359786806155}\\ {14.8916605724439}\\ {7.89270539662424}\\ {12.0784186416757}\\ {⋮}\end{array}\right]\\ \hfill {\text{4096 element Vector[column]}}\end{array}$ (12)
 • With noise, of course, the short-time entropy changes:
 > $\mathrm{Entropy_Vector_Noisy},\mathrm{Entropy_Plot_Noisy}≔\mathrm{ShortTimeSpectralEntropy}\left(\mathrm{Signal_Noisy},\mathrm{samplerate}=\mathrm{sample_rate},\mathrm{segmentsize}=\mathrm{segment_size},\mathrm{overlapsize}=\mathrm{overlap_size},\mathrm{output}=\left[\mathrm{entropy},\mathrm{entropyplot}\right]\right):$
 > $\mathrm{Entropy_Vector_Noisy}$
 $\begin{array}{c}\left[\begin{array}{c}{2.37112404945654}\\ {2.35409277951868}\\ {2.67649092639416}\\ {1.61097907941649}\\ {2.15270134181325}\\ {1.63806461698457}\\ {2.47271767907393}\\ {2.06724952119236}\\ {1.77222363493847}\\ {2.27959301629345}\\ {⋮}\end{array}\right]\\ \hfill {\text{64 element Vector[column]}}\end{array}$ (13)
 > $\mathrm{Entropy_Plot_Noisy}$

Comparison

 • As we see from a plot of the original and noisy signals, the noise conceals the pure sinusoid:
 > $\mathrm{dataplot}\left(\mathrm{Times},\left[\mathrm{Signal_Noisy},\mathrm{Signal_Pure}\right],\mathrm{size}=\left[800,400\right],\mathrm{color}=\left[\mathrm{red},\mathrm{blue}\right],\mathrm{style}=\mathrm{line},\mathrm{legend}=\left["Noisy Signal","Pure Signal"\right],\mathrm{labels}=\left["Time \left(s\right)","Amplitude"\right],\mathrm{title}="Signal",\mathrm{font}=\left[\mathrm{Verdana},15\right],\mathrm{labelfont}=\left[\mathrm{Verdana},10\right],\mathrm{legendstyle}=\left[\mathrm{font}=\left[\mathrm{Verdana},15\right]\right]\right)$
 • However, the plot of the short-time spectral entropy indicates the locations where the original signal is strongest (namely, where the entropy is lowest and has the highest information content) and weakest (where the entropy is highest).

Compatibility

 • The SignalProcessing[ShortTimeBandPower], SignalProcessing[ShortTimeMeanFrequency] and SignalProcessing[ShortTimeSpectralEntropy] commands were introduced in Maple 2021.