SignalProcessing Improvements in Maple 2023
The SignalProcessing package has been expanded with new and updated commands.
>
|
with( SignalProcessing ):
|
|
Quantize
|
|
•
|
For example, suppose we want to quantize the values generated by over the interval so that the values are to the nearest quarter integer. With this new command, we can do either of the following:
|
>
|
X := GenerateSignal( sin(t), t = 0 .. 2 * Pi, 50 )^+;
|
| (1) |
>
|
Y := Quantize( X, -1 .. 1, 9 );
|
| (2) |
>
|
Z := Quantize( X, < seq( 0.25 * k, k = -4 .. 4 ) > );
|
| (3) |
•
|
The command can also display the original and quantized signals together:
|
>
|
Quantize( X, -1 .. 1, 9, 'output' = 'plot', 'emphasizecodes' );
|
•
|
The example above uses the default nearest for the option truncation, but below and above are also available. Moreover, classical quantization techniques midriser and midtread are provided:
|
>
|
Quantize( X, 'midriser', 1, 9, 'output' = 'plot', 'emphasizecodes' );
|
>
|
GenerateSignal( sin(t), t = 0 .. 2 * Pi, 50, 'quantization' = [-1..1,9], 'output' = 'signalplot' );
|
|
|
SavitzkyGolayFilter
|
|
•
|
The new SignalProcessing:-SavitzkyGolayFilter command applies the Savitzky-Golay Filter to a signal, with applications including smoothing noisy data and estimating derivatives of data. The filter is also known as Polynomial Smoothing, Least-Squares Smoothing, and Locally Weighted Scatterplot Smoothing (LOWESS).
|
•
|
For example, consider the following:
|
>
|
f := sin(t) + 1/5 * cos(3*t); # original expression
|
>
|
t2 := 2 * Pi; # finish time
|
>
|
m := 200; # number of points
|
>
|
(T,X) := GenerateSignal( f, t = t1 .. t2, m, 'noisedeviation' = 0.2, 'includefinishtime' = 'false', 'output' = ['times','signal'] );
|
•
|
The smoothing, both unweighted and weighted, noticeably reduces the noise:
|
>
|
d := 2; # degree of polynomial interpolants
|
>
|
r := 10; # radius of frame
|
>
|
W := < seq( 1 .. r + 1 ), seq( r .. 1, -1 ) >: # weights
|
>
|
SavitzkyGolayFilter( X, d, r, 'timerange' = t1 .. t2, 'plotoptions' = [ 'title' = "Unweighted Savitzky-Golay Filtered Signal" ], 'output' = 'plot' );
|
>
|
SavitzkyGolayFilter( X, d, W, 'timerange' = t1 .. t2, 'plotoptions' = [ 'title' = "Weighted Savitzky-Golay Filtered Signal" ], 'output' = 'plot' );
|
>
|
(dt,T,U) := GenerateSignal( t * (t^2-1)^3, t = -1 .. 1, 75, 'includefinishtime' = 'false', 'output' = ['timestep','times','signal'] );
|
>
|
V := DifferentiateData( U, 1, 'step' = dt, 'method' = 'savitzkygolay', 'extrapolation' = 'periodic', 'frameradius' = 2 );
|
>
|
dataplot( T, [U,V], 'style' = 'line', 'legend' = ["Signal","First derivative"], 'color' = ['red','blue'], 'view' = [-1..1,'DEFAULT'] );
|
|
|
Convolution
|
|
>
|
A := LinearAlgebra:-RandomVector( 5, 'generator' = -1.0 .. 1.0, 'datatype' = 'float[8]' );
|
| (13) |
>
|
B := LinearAlgebra:-RandomVector( 3, 'generator' = -1.0 .. 1.0, 'datatype' = 'float[8]' );
|
| (14) |
>
|
C1 := Convolution( A, B, 'shape' = 'full' );
|
| (15) |
>
|
C2 := Convolution( A, B, 'shape' = 'same' );
|
| (16) |
>
|
C3 := Convolution( A, B, 'shape' = 'valid' );
|
| (17) |
•
|
Moreover, lists can now be passed for signals in addition to rtables.
|
|
|
FFT and InverseFFT
|
|
•
|
The SignalProcessing:-FFT and SignalProcessing:-InverseFFT commands now support padding and truncation. Padding is helpful due to the increase in both the speed of computation and the frequency resolution. The size option accepts a positive integer for the new size and keywords same (the default, for not changing the length) and recommended (for changing the length to the next power of 2). For example:
|
>
|
X := LinearAlgebra:-RandomVector( 3, 'generator' = -1.0 .. 1.0, 'datatype' = 'complex[8]' );
|
| (18) |
>
|
Y1 := FFT( X, 'size' = 'same' );
|
| (19) |
>
|
Y2 := FFT( X, 'size' = 'recommended' );
|
| (20) |
>
|
Y3 := FFT( X, 'size' = 5 );
|
| (21) |
•
|
The size option also works with multi-dimensional input. Moreover, lists can now be passed for signals in addition to rtables.
|
|
|