numir.signal
Signal processing package
-
Declaration
pure nothrow @nogc @safe autoblackman(size_tn, doublea0= 0.42, doublea1= 0.5, doublea2= 0.08);Classic Blackman window slice generator
Parameters
size_tnlength of window
doublea0window parameter
doublea1window parameter
doublea2window parameter
Return Value
window weight slice
-
Declaration
pure nothrow @nogc @safe autohann(size_tn, doublea= 0.5, doubleb= 0.25);Hann window slice generator
Parameters
size_tnlength of window
doubleawindow parameter
doublebwindow parameter
Return Value
window weight slice
See Also
https://ccrma.stanford.edu/~jos/sasp/Generalized_Hamming_Window_Family.html https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.hann.html
Examples
import numir.signal; import std.meta : AliasSeq; import mir.ndslice : maxIndex; import std.math : approxEqual; // test windows are symmetry and peaked at median auto n = 11; static foreach (wfun; AliasSeq!(blackman, hann)) {{ auto w = wfun(n); assert(w.maxIndex[0] == n / 2); foreach (i; 0 .. n / 2 - 1) { assert(w[i].approxEqual(w[$ - 1 - i])); } }}
-
Declaration
pure nothrow @nogc @safe autosplitFrames(Xs)(Xsxs, size_twidth, size_tstride);Split (window and
stride) time frames for FFT or convolutionsParameters
Xsxsinput slice
size_twidthlength of each segment
size_tstridethe number of skipped frames between the head of split slices
Return Value
slice of split (windowed and strided) slices
Examples
import numir.signal; import mir.ndslice.topology : iota; static immutable ys = [[0,1,2], [2,3,4]]; assert(iota(6).splitFrames(3, 2) == ys);
-
Declaration
autostft(alias windowFun = hann, Xs)(Xsxs, size_tnperseg, size_tnoverlap) if (isSlice!Xs && (DimensionCount!Xs == 1));
autostft(alias windowFun = hann, Xs)(Xsxs, size_tnperseg= 256) if (isSlice!Xs && (DimensionCount!Xs == 1));Computes the short time Fourier transform
Parameters
Xsxsinput 1d slice with the shape (ntimes,)
size_tnperseg(default 256) short-time frame width for each FFT segment
size_tnoverlap(default
nperseg/ 2) short-time frame overlapped length for each FFT segmentReturn Value
comlex 2d slice (nframes, nfreqs=
nperseg) -
Declaration
autoistft(alias windowFun = hann, Xs)(Xsxs, size_tnoverlap) if (isSlice!Xs && (DimensionCount!Xs == 2));
autoistft(alias windowFun = hann, Xs)(Xsxs) if (isSlice!Xs && (DimensionCount!Xs == 2));Computes the inverse short time Fourier transform
Parameters
Xsxsinput 2d complex slice with the shape (ntimes, nfreq)
size_tnoverlap(default nperseg / 2) short-time frame overlapped length for each FFT segment Returns 1d real slice with the shape (ntimes,)
Examples
test stft-
istfthealthimport std.complex; import std.stdio; import mir.ndslice : map, sliced; import numir.testing : approxEqual; // first 16 samples from https://raw.githubusercontent.com/ShigekiKarita/torch-nmf-ss-toy/master/test10k.wav auto xs = [-10, 15, 106, -1, -655, -1553, -1501, -522, -106, 831, 1250, 381, 1096, 2302, 2686, 2427].sliced; // need larger overlaps to revert well auto ys = stft(xs, 8, 7); auto ixs = istft(ys, 7).map!(c => c.re); assert(approxEqual(ixs, xs));