ltfatpy.fourier package - Basic Fourier and DCT analysis.¶
Support routines¶
fftindex¶
Module of frequency index of FFT modulations computation
Ported from ltfat_2.1.0/fourier/fftindex.m
-
ltfatpy.fourier.fftindex.
fftindex
(N, nyquistzero=False)[source]¶ Frequency index of FFT modulations
Usage:
n = fftindex(N)
Input parameters:
Parameters: - Output parameters:
Returns: Indexes of the frequencies of the standard FFT Return type: numpy.ndarray fftindex(N)
returns the index of the frequencies of the standard FFT of length N as they are ordered in the output from thenumpy.fft.fft()
routine. The numbers returned are in the range-ceil(N/2)+1:floor(N/2)
.fftindex(N, True)
does as above, but sets the Nyquist frequency to zero.See also
dft()
Basic Fourier analysis¶
fftreal¶
Module of FFT for real valued data computation
Ported from ltfat_2.1.0/fourier/fftreal.m
-
ltfatpy.fourier.fftreal.
fftreal
(f, N=None, dim=0)[source]¶ FFT for real valued input data
Usage:
c = fftreal(f)
c = fftreal(f, N, dim)
Input parameters:
Parameters: - f (numpy.ndarray) – Real valued input array
- N (int) – FFT length
- dim (int) – Axis over which to compute the FFT. By default the first axis is used.
- Output parameters:
Returns: Discrete Fourier coefficients of f for positive frequencies Return type: numpy.ndarray fftreal(f)
computes the coefficients corresponding to the positive frequencies of the FFT of the real valued input signal f.The function takes the same arguments as
numpy.fft.rfft()
. See the help on this function for a thorough description.Note
This Python port doesn’t use the C core of LTFAT to implement the FFT for real arrays as in the Octave version.
Instead it direclty uses the implementation available in numpy.
This can lead to sightly different results when comparing the results of the Octave and Python versions of fftreal.
See also
ifftreal¶
Module of inverse FFT for real valued data computation
Ported from ltfat_2.1.0/fourier/ifftreal.m
-
ltfatpy.fourier.ifftreal.
ifftreal
(c, N, dim=0)[source]¶ Inverse FFT for real valued signals
Usage:
f = ifftreal(c, N)
f = ifftreal(c, N, dim)
Input parameters:
Parameters: - c (numpy.ndarray) – Discrete Fourier coefficients of a real array for positive frequencies
- N (int) – IFFT length
- dim (int) – Axis over which to compute the IFFT. By default the first axis is used.
- Output parameters:
Returns: Reconstructed signal Return type: numpy.ndarray ifftreal(c, N)
computes an inverse FFT of the positive frequency Fourier coefficients c. The length N must always be specified, because the correct transform length cannot be determined from the size of c.ifftreal(c, N, dim)
does the same along dimension dim.Note
This Python port doesn’t use the C core of LTFAT to implement the inverse FFT for real arrays as in the Octave version.
Instead it direclty uses the implementation available in numpy.
This can lead to sightly different results when comparing the results of the Octave and Python versions of ifftreal.
See also
dft¶
Module of normalized discrete Fourier transform
Ported from ltfat_2.1.0/fourier/dft.m
-
ltfatpy.fourier.dft.
dft
(f, N=None, dim=0)[source]¶ Normalized Discrete Fourier Transform
Usage:
c = dft(f)
c = dft(f, N, dim)
Input parameters:
Parameters: - f (numpy.ndarray) – Input array
- N (int) – DFT length
- dim (int) – Axis over which to compute the DFT. By default the first axis is used.
- Output parameters:
Returns: Normalized discrete Fourier coefficients of f Return type: numpy.ndarray dft()
computes a normalized or unitary discrete Fourier transform. The unitary discrete Fourier transform is computed byfor .
The output of
dft()
is a scaled version of the output fromnumpy.fft.fft()
. The function takes the same first three arguments asnumpy.fft.fft()
. See the help onnumpy.fft.fft()
for a thorough description.See also
idft¶
Module of inverse normalized discrete Fourier transform
Ported from ltfat_2.1.0/fourier/idft.m
-
ltfatpy.fourier.idft.
idft
(c, N=None, dim=0)[source]¶ Inverse Normalized Discrete Fourier Transform
Usage:
f = idft(c)
f = idft(c, N, dim)
Input parameters:
Parameters: - c (numpy.ndarray) – Normalized discrete Fourier coefficients of a signal
- N (int) – IDFT length
- dim (int) – Axis over which to compute the IDFT. By default the first axis is used.
- Output parameters:
Returns: Reconstructed signal Return type: numpy.ndarray idft()
computes a normalized or unitary inverse discrete Fourier transform. The unitary inverse discrete Fourier transform is computed byfor .
The output of
idft()
is a scaled version of the output fromnumpy.fft.ifft()
. The function takes the same first three arguments asnumpy.fft.ifft()
. See the help onnumpy.fft.ifft()
for a thorough description.See also
Simple operations on periodic functions¶
isevenfunction¶
Module of even function tests
Ported from ltfat_2.1.0/fourier/isevenfunction.m
-
ltfatpy.fourier.isevenfunction.
isevenfunction
(f, tol=1e-10, centering='wp')[source]¶ True if function is even
Usage:
t = isevenfunction(f)
t = isevenfunction(f, tol)
Input parameters:
Parameters: - f (numpy.ndarray) – vector of data to test (one dimension)
- tol (float) – tolerance (1e-10 by default)
- centering (str) – Point even function type : whole or half point even. centering can be ‘wp’ or ‘hp’, ‘wp’ is the default.
-Output parameter:
Returns: True if f is whole point even Return type: bool isevenfunction(f) returns True if f is whole point even. Otherwise it returns False.
isevenfunction(f, tol)
the same, using the tolerance tol to measure how large the error between the two parts of the vector can be. Default is 1e-10.Setting centering to ‘hp’, does the same for half point even functions.
See also
middlepad()
,peven()
middlepad¶
Module of symmetrical zero-extension or cut of data
Ported from ltfat_2.1.0/fourier/middlepad.m
-
ltfatpy.fourier.middlepad.
middlepad
(f, L, dim=None, centering='wp')[source]¶ Symmetrically zero-extends or cuts a function
Usage:
h = middlepad(f, L)
h = middlepad(f, L, dim)
h = middlepad(f, L, ...)
Input parameters:
Parameters: - f (numpy.ndarray) – Input array
- L (int) – Length of the output array
- dim (int) – Axis over which to zero-extend or cut f
- centering (str) – Flag specifying if f is whole point even when
centering='wp'
or half point even whencentering='hp'
- Output parameters:
Returns: Zero-extended or cut array Return type: numpy.ndarray middlepad(f, L)
zero-extends or cuts f to length L by inserting zeros in the middle of the vector, or by cutting in the middle of the vector.If f is whole-point even,
middlepad(f, L)
will also be whole-point even.middlepad(f, L, dim)
does the same along dimension dim.If f has even length, then f will not be purely zero-extended, but the last element will be repeated once and multiplied by
1/2
. That is, the support of f will increase by one!Adding the flag
centering='wp'
will cut or extend whole point even functions (the default). Addingcentering='hp'
will do the same for half point even functions.See also
Periodic functions¶
pgauss¶
This module contains sampled, periodized Gaussian window function
Ported from ltfat_2.1.0/fourier/pgauss.m
-
ltfatpy.fourier.pgauss.
pgauss
(L, tfr=1.0, fs=0.0, width=0.0, bw=0.0, c_f=0.0, centering='wp', delay=0.0, norm='2', **kwargs)[source]¶ Sampled, periodized Gaussian
- Usage:
(g, tfr) = pgauss(L)
(g, tfr) = pgauss(L, tfr, fs, width, bw, c_f, centering, delay, norm)
Input parameters:
Parameters: - L (int) – Length of the output vector.
- tfr (float) – determines the ratio between the effective support of g and the effective support of the DFT of g. If then g has a wider support than the DFT of g. Default is 1.
- fs (float) – Use a sampling rate of fs Hz as unit for specifying the width, bandwidth, centre frequency and delay of the Gaussian. Default is which indicates to measure everything in samples.
- width (float) – Set the width of the Gaussian such that it has an
effective support of width samples. This means that
approx. 96% of the energy or 79% of the area under the graph is
contained within width samples. This corresponds to a -6 db
cutoff. This is equivalent to calling
pgauss(L,tfr = s^2/L)
. Default is zero, unset. - bw (float) – As for the width argument, but specifies the width in the frequency domain. The bandwidth is measured in normalized frequencies, unless the fs value is given. Default is zero, unset.
- c_f (float) – Set the centre frequency of the Gaussian to cf. Default is zero.
- centering (str) – “wp” means output is whole point even. This is the default. Setting it to hp means output is half point even which is the case for the most Matlab filters routines.
- delay (float) – Delay the output by delay. Default is zero.
- norm (str) – normalization to apply (default is L2)
Normalization types :
Name Norms ‘1’ L1-norm ‘2’ L2-norm Output parameters:
Returns: (g, tfr)
Return type: Variables: - array g (numpy) – window array of length L
- tfr (int) – ratio between the effective support of g and the effective support of the DFT of g.
pgauss(L,tfr)
samples of a periodized Gaussian. The function returns a numpy array g containing a regular sampling of the periodization of the function .The norm of the returned Gaussian is equal to 1.
The function is whole-point even. This implies that
fft(pgauss(L, tfr))
is real for any L and tfr. The DFT of g is equal topgauss(L, 1/tfr)
.If this function is used to generate a window for a Gabor frame, then the window giving the smallest frame bound ratio is generated by
pgauss(L, a*M/L)
.- Examples:
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from ltfatpy import sgram >>> # This example creates a Gaussian function, and demonstrates that it is >>> # its own Discrete Fourier Transform: >>> g = pgauss(128)[0] >>> # Test of DFT invariance: Should be close to zero. >>> np.linalg.norm(g - np.fft.fft(g)/np.sqrt(128)) <= 1e-10 True >>> # The next plot shows the Gaussian in the time domain: >>> _ = plt.plot(np.fft.fftshift(g)) >>> plt.show() >>> # The next plot shows the Gaussian in the time-frequency plane: >>> _ = sgram(g, nf=True, tc=True, normalization='lin') >>> plt.show()
Note
g is real if c_f = 0 and complex if not.
See also
dgtlength()
,psech()
,firwin()
,pbspline()
,normalize()
psech¶
Module of Sampled, periodized hyperbolic secant calculation
Ported from ltfat_2.1.0/fourier/psech.m
-
ltfatpy.fourier.psech.
psech
(L, tfr=None, s=None, **kwargs)[source]¶ Sampled, periodized hyperbolic secant
Usage:
(g, tfr) = psech(L)
(g, tfr) = psech(L, tfr)
(g, tfr) = psech(L, s=...)
Input parameters:
Parameters: - Output parameters:
Returns: (g, tfr)
Return type: Variables: - g (numpy.ndarray) – periodized hyperbolic cosine
- tfr (float) – calculated ratio between time and frequency support
psech(L,tfr)
computes samples of a periodized hyperbolic secant. The function returns a regular sampling of the periodization of the functionThe returned function has norm equal to 1.
The parameter tfr determines the ratio between the effective support of g and the effective support of the DFT of g. If tfr > 1 then g has a wider support than the DFT of g.
psech(L)
does the same setting than tfr = 1.psech(L,s)
returns a hyperbolic secant with an effective support of s samples. This means that approx. 96% of the energy or 74% or the area under the graph is contained within s samples. This is equivalent topsech(L,s^2/L)
.(g,tfr) = psech( ... )
returns the time-to-frequency support ratio. This is useful if you did not specify it (i.e. used the s input format).The function is whole-point even. This implies that
fft(psech(L,tfr))
is real for any L and tfr.If this function is used to generate a window for a Gabor frame, then the window giving the smallest frame bound ratio is generated by
psech(L,a*M/L)
.Examples:
This example creates a
psech
function, and demonstrates that it is its own Discrete Fourier Transform:>>> import numpy as np >>> import numpy.linalg as nla >>> g = psech(128)[0] # DFT invariance: Should be close to zero. >>> diff = nla.norm(g-np.fft.fft(g)/np.sqrt(128)) >>> np.abs(diff) < 10e-10 True
See also
pgauss()
,pbspline()
,pherm()
- References:
- [JS02]
Hermite functions and fractional Fourier transforms¶
pherm¶
This module contains samples of a periodized Hermite function
Ported from ltfat_2.1.0/fourier/pherm.m
-
ltfatpy.fourier.pherm.
pherm
(L, order, tfr=1, phase='accurate', orthtype='noorth')[source]¶ PHERM Periodized Hermite function
- Usage:
g, = pherm(L,order)
g, = pherm(L,order,tfr)
g, D = pherm(...)
Input parameters:
Parameters: - L (int) – Length of vector.
- order (scalar or numpy.ndarray) – Order of Hermite function.
- tfr (float) – ratio between time and frequency support. 1 by default
- phase (str) – ‘accurate’ or ‘fast’ (see below)
- orthtype (str) – ‘noorth’, ‘polar’ or ‘qr’ (see below).
- Output parameters:
Returns: (g, D)
Return type: Variables: - g (numpy.ndarray) – The periodized Hermite function
- D (numpy.ndarray) – The eigenvalues of the Discrete Fourier Transform corresponding to the Hermite functions.
pherm(L,order,tfr)
computes samples of a periodized Hermite function of order order. order is counted from 0, so the zero’th order Hermite function is the Gaussian.The parameter tfr determines the ratio between the effective support of g and the effective support of the DFT of g. If then g has a wider support than the DFT of g.
pherm(L,order)
does the same setting .If order is a vector,
pherm
will return a matrix, where each column is a Hermite function with the corresponding order.g, D = pherm(...)
also returns the eigenvalues D of the Discrete Fourier Transform corresponding to the Hermite functions.The returned functions are eigenvectors of the DFT. The Hermite functions are orthogonal to all other Hermite functions with a different eigenvalue, but eigenvectors with the same eigenvalue are not orthogonal (but see the flags below).
phase can take the following values:
- ‘accurate’ By default it uses a numerically very accurate that
- computes each Hermite function individually. This is the default
- ‘fast’ Use a less accurate algorithm that calculates all the
- Hermite up to a given order at once.
orthtype can take the following values:
- ‘noorth’ orthonormalization of the Hermite functions. This is the
- default.
- ‘polar’ Orthonormalization of the Hermite functions using the
- polar decomposition orthonormalization method.
- ‘qr’ Orthonormalization of the Hermite functions using the
- Gram-Schmidt orthonormalization method (usign
qr
).
If you just need to compute a single Hermite function, there is no speed difference between the accurate and fast algorithm.
- Examples:
The following plot shows the spectrograms of 4 Hermite functions of length 200 with order 1, 10, 100, and 190::
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from ltfatpy import sgram >>> plt.close('all') >>> _ = plt.figure() >>> _ = plt.subplot(221) >>> _ = sgram(pherm(200, 1)[0], nf=True, tc=True, normalization='lin', ... colorbar=False) >>> _ = plt.subplot(2,2,2) >>> _ = sgram(pherm(200, 10)[0], nf=True, tc=True, normalization='lin', ... colorbar=False) >>> _ = plt.subplot(2,2,3) >>> _ = sgram(pherm(200, 100)[0], nf=True, tc=True, ... normalization='lin', colorbar=False) >>> _ = plt.subplot(2,2,4) >>> _ = sgram(pherm(200, 190)[0], nf=True, tc=True, ... normalization='lin', colorbar=False) >>> plt.show()
Approximation of continuous functions¶
fftresample¶
Module of signal resampling using Fourier interpolation
Ported from ltfat_2.1.0/fourier/fftresample.m
-
ltfatpy.fourier.fftresample.
fftresample
(f, L, dim=None)[source]¶ Resample signal using Fourier interpolation
- Usage:
h = fftresample(f, L)
h = fftresample(f, L, dim)
Input parameters:
Parameters: - f (numpy.ndarray) – Input array
- L (int) – Length of the output resampled array
- dim (int) – Axis over which to do the resampling
- Output parameters:
Returns: Resampled array Return type: numpy.ndarray fftresample(f, L)
returns a Fourier interpolation of the signal f to length L. If the function is applied to a matrix, it will apply to each column.fftresample(f, L, dim)
does the same along dimension dim.If the input signal is not a periodic signal (or close to), the
dctresample()
method gives much better results at the endpoints.See also
dctresample()
,middlepad()
pderiv¶
Module of derivative of smooth periodic function computation
Ported from ltfat_2.1.0/fourier/pderiv.m
-
ltfatpy.fourier.pderiv.
pderiv
(f, dim=None, difforder=4)[source]¶ Derivative of smooth periodic function
- Usage:
fd = pderiv(f)
fd = pderiv(f, dim)
fd = pderiv(f, dim, difforder)
Input parameters:
Parameters: - f (numpy.ndarray) – Input array
- dim (int) – Axis over which to compute the derivative
- difforder (int or float) – Order of the centered finite difference scheme used.
Possible values are:
2
,4
,float('inf')
- Output parameters:
Returns: Derivative of f Return type: numpy.ndarray pderiv(f)
will compute the derivative of f using a using a 4th order centered finite difference scheme. f must have been obtained by a regular sampling. If f is a matrix, the derivative along the columns will be found.pderiv(f, dim)
will do the same along dimension dim.pderiv(f, dim, difforder)
uses a centered finite difference scheme of order difforder instead of the default.pderiv(f, dim, float('inf'))
will compute the spectral derivative using a DFT.pderiv
assumes that f is a regular sampling of a function on the torus[0, 1)
. The derivative of a function on a general torus[0, T)
can be found by scaling the output by1/T
.
Cosine and Sine transforms.¶
dcti¶
This module contains DCTI function
Ported from ltfat_2.1.0/fourier/dcti.m
-
ltfatpy.fourier.dcti.
dcti
(f, L=None, dim=None)[source]¶ Discrete Cosine Transform type I
Usage:
c = dcti(f)
c = dcti(f,L,dim)
Input parameters:
Parameters: - f (numpy.ndarray) – Input data. f dtype has to be float64 or complex128.
- L (int) – Length of the output vector. Default is the length of f.
- dim (int) – dimension along which the transformation is applied. Default is the first non-singleton dimension.
- Output parameter:
Returns: c
Return type: numpy.ndarray dcti(f)
computes the discrete cosine transform of type I of the input signal f. If f is a matrix then the transformation is applied to each column. For N-D arrays, the transformation is applied to the first non-singleton dimension.dcti(f,L)
zero-pads or truncates f to length L before doing the transformation.dcti(f,dim=dim)
ordcti(f,L,dim)
applies the transformation along dimension dim.The transform is real (output is real if input is real) and it is orthonormal.
This transform is its own inverse.
Let f be a signal of length L, let and define the vector w of length L by
Then
The implementation of this functions uses a simple algorithm that require an FFT of length 2L-2, which might potentially be the product of a large prime number. This may cause the function to sometimes execute slowly. If guaranteed high speed is a concern, please consider using one of the other DCT transforms.
- Examples:
The following figures show the first 4 basis functions of the DCTI of length 20:
>>> import numpy as np >>> # The dcti is its own adjoint. >>> F = dcti(np.eye(20, dtype=np.float64)) >>> import matplotlib.pyplot as plt >>> plt.close('all') >>> fig = plt.figure() >>> for ii in range(1,5): ... ax = fig.add_subplot(4,1,ii) ... ax.stem(F[:,ii-1]) ... <Container object of 3 artists> <Container object of 3 artists> <Container object of 3 artists> <Container object of 3 artists> >>> plt.show()
- References:
- [RY90][Wickerhauser94]
dctii¶
This module contains DCTII function
Ported from ltfat_2.1.0/fourier/dctii.m
-
ltfatpy.fourier.dctii.
dctii
(f, L=None, dim=None)[source]¶ Discrete Cosine Transform type II
Usage:
c = dctii(f)
c = dctii(f,L,dim)
Input parameters:
Parameters: - f (numpy.ndarray) – Input data. f dtype has to be float64 or complex128.
- L (int) – Length of the output vector. Default is the length of f.
- dim (int) – dimension along which the transformation is applied. Default is the first non-singleton dimension.
- Output parameter:
Returns: c
Return type: numpy.ndarray dctii(f)
computes the discrete cosine transform of type II of the input signal f. If f is a matrix then the transformation is applied to each column. For N-D arrays, the transformation is applied to the first non-singleton dimension.dctii(f,L)
zero-pads or truncates f to length L before doing the transformation.dctii(f,dim=dim)
ordctii(f,L,dim)
applies the transformation along dimension dim.The transform is real (output is real if input is real) and it is orthonormal.
This is the inverse of |dctiii|.
Let f be a signal of length L, let and define the vector w of length L by
Then
- Examples:
The following figures show the first 4 basis functions of the DCTII of length 20:
>>> import numpy as np >>> # The dctii is its own adjoint. >>> F = dctii(np.eye(20, dtype=np.float64)) >>> import matplotlib.pyplot as plt >>> plt.close('all') >>> fig = plt.figure() >>> for ii in range(1,5): ... ax = fig.add_subplot(4,1,ii) ... ax.stem(F[:,ii-1]) ... <Container object of 3 artists> <Container object of 3 artists> <Container object of 3 artists> <Container object of 3 artists> >>> plt.show()
- References:
- [RY90][Wickerhauser94]
dctiii¶
This module contains dctIII function
Ported from ltfat_2.1.0/fourier/dctiii.m
-
ltfatpy.fourier.dctiii.
dctiii
(f, L=None, dim=None)[source]¶ Discrete Cosine Transform type III
Usage:
c = dctiii(f)
c = dctiii(f,L,dim)
Input parameters:
Parameters: - f (numpy.ndarray) – Input data. f dtype has to be float64 or complex128.
- L (int) – Length of the output vector. Default is the length of f.
- dim (int) – dimension along which the transformation is applied. Default is the first non-singleton dimension.
- Output parameter:
Returns: c
Return type: numpy.ndarray dctiii(f)
computes the discrete cosine transform of type III of the input signal f. If f is a matrix then the transformation is applied to each column. For N-D arrays, the transformation is applied to the first non-singleton dimension.dctiii(f,L)
zero-pads or truncates f to length L before doing the transformation.dctiii(f,dim=dim)
ordctiii(f,L,dim)
applies the transformation along dimension dim.The transform is real (output is real if input is real) and it is orthonormal.
This is the inverse of |dctii|.
Let f be a signal of length L, let and define the vector w of length L by
Then
- Examples:
The following figures show the first 4 basis functions of the dctiii of length 20:
>>> import numpy as np >>> # The dctiii is its own adjoint. >>> F = dctiii(np.eye(20, dtype=np.float64)) >>> import matplotlib.pyplot as plt >>> plt.close('all') >>> fig = plt.figure() >>> for ii in range(1,5): ... ax = fig.add_subplot(4,1,ii) ... ax.stem(F[:,ii-1]) ... <Container object of 3 artists> <Container object of 3 artists> <Container object of 3 artists> <Container object of 3 artists> >>> plt.show()
- References:
- [RY90][Wickerhauser94]
dctiv¶
This module contains dctIV function
Ported from ltfat_2.1.0/fourier/dctiv.m
-
ltfatpy.fourier.dctiv.
dctiv
(f, L=None, dim=None)[source]¶ Discrete Cosine Transform type IV
Usage:
c = dctiv(f)
c = dctiv(f,L,dim)
Input parameters:
Parameters: - f (numpy.ndarray) – Input data. f dtype has to be float64 or complex128.
- L (int) – Length of the output vector. Default is the length of f.
- dim (int) – dimension along which the transformation is applied. Default is the first non-singleton dimension.
- Output parameter:
Returns: c
Return type: numpy.ndarray dctiv(f)
computes the discrete cosine transform of type IV of the input signal f. If f is a matrix then the transformation is applied to each column. For N-D arrays, the transformation is applied to the first non-singleton dimension.dctiv(f,L)
zero-pads or truncates f to length L before doing the transformation.dctiv(f,dim=dim)
ordctiv(f,L,dim)
applies the transformation along dimension dim.The transform is real (output is real if input is real) and it is orthonormal. It is its own inverse.
Let f be a signal of length L and let then:
- Examples:
The following figures show the first 4 basis functions of the dctiv of length 20:
>>> import numpy as np >>> # The dctiv is its own adjoint. >>> F = dctiv(np.eye(20, dtype=np.float64)) >>> import matplotlib.pyplot as plt >>> plt.close('all') >>> fig = plt.figure() >>> for ii in range(1,5): ... ax = fig.add_subplot(4,1,ii) ... ax.stem(F[:,ii-1]) ... <Container object of 3 artists> <Container object of 3 artists> <Container object of 3 artists> <Container object of 3 artists> >>> plt.show()
- References:
- [RY90][Wickerhauser94]
dsti¶
This module contains DSTI function
Ported from ltfat_2.1.0/fourier/dsti.m
-
ltfatpy.fourier.dsti.
dsti
(f, L=None, dim=None)[source]¶ Discrete Sine Transform type I
Usage:
c = dsti(f)
c = dsti(f,L,dim)
Input parameters:
Parameters: - f (numpy.ndarray) – Input data. f dtype has to be float64 or complex128.
- L (int) – Length of the output vector. Default is the length of f.
- dim (int) – dimension along which the transformation is applied. Default is the first non-singleton dimension.
- Output parameter:
Returns: c
Return type: numpy.ndarray dsti(f)
computes the discrete sine transform of type I of the input signal f. If f is multi-dimensional, the transformation is applied along the first non-singleton dimension.dsti(f,L)
zero-pads or truncates f to length L before doing the transformation.dsti(f,[],dim)
ordsti(f,L,dim)
applies the transformation along dimension dim.The transform is real (output is real if input is real) and orthonormal.
This transform is its own inverse.
Let f be a signal of length L and let
c=dsti(f)
. ThenThe implementation of this functions uses a simple algorithm that requires an FFT of length $2N+2$, which might potentially be the product of a large prime number. This may cause the function to sometimes execute slowly. If guaranteed high speed is a concern, please consider using one of the other DST transforms.
- Examples:
The following figures show the first 4 basis functions of the DSTI of length 20:
>>> import numpy as np >>> # The dsti is its own adjoint. >>> F = dsti(np.eye(20, dtype=np.float64)) >>> import matplotlib.pyplot as plt >>> plt.close('all') >>> fig = plt.figure() >>> for ii in range(1,5): ... ax = fig.add_subplot(4,1,ii) ... ax.stem(F[:,ii-1]) ... <Container object of 3 artists> <Container object of 3 artists> <Container object of 3 artists> <Container object of 3 artists> >>> plt.show()
- References:
- [RY90][Wickerhauser94]
dstii¶
This module contains DSTII function
Ported from ltfat_2.1.0/fourier/dstii.m
-
ltfatpy.fourier.dstii.
dstii
(f, L=None, dim=None)[source]¶ Discrete Sine Transform type II
Usage:
c = dstii(f)
c = dstii(f,L,dim)
Input parameters:
Parameters: - f (numpy.ndarray) – Input data. f dtype has to be float64 or complex128.
- L (int) – Length of the output vector. Default is the length of f.
- dim (int) – dimension along which the transformation is applied. Default is the first non-singleton dimension.
- Output parameter:
Returns: c
Return type: numpy.ndarray dstii(f)
computes the discrete sine transform of type I of the input signal f. If f is multi-dimensional, the transformation is applied along the first non-singleton dimension.dstii(f,L)
zero-pads or truncates f to length L before doing the transformation.dstii(f,[],dim)
ordstii(f,L,dim)
applies the transformation along dimension dim.The transform is real (output is real if input is real) and orthonormal.
The inverse transform of |dstii| is |dstiii|.
Let f be a signal of length L, let
c=dstii(f)
and define the vector w of length L byThen
- Examples:
The following figures show the first 4 basis functions of the DSTII of length 20:
>>> import numpy as np >>> # The dstii is its own adjoint. >>> F = dstii(np.eye(20, dtype=np.float64)) >>> import matplotlib.pyplot as plt >>> plt.close('all') >>> fig = plt.figure() >>> for ii in range(1,5): ... ax = fig.add_subplot(4,1,ii) ... ax.stem(F[:,ii-1]) ... <Container object of 3 artists> <Container object of 3 artists> <Container object of 3 artists> <Container object of 3 artists> >>> plt.show()
- References:
- [RY90][Wickerhauser94]
dstiii¶
This module contains DSTIII function
Ported from ltfat_2.1.0/fourier/dstiii.m
-
ltfatpy.fourier.dstiii.
dstiii
(f, L=None, dim=None)[source]¶ Discrete Sine Transform type III
Usage:
c = dstiii(f)
c = dstiii(f,L,dim)
Input parameters:
Parameters: - f (numpy.ndarray) – Input data. f dtype has to be float64 or complex128.
- L (int) – Length of the output vector. Default is the length of f.
- dim (int) – dimension along which the transformation is applied. Default is the first non-singleton dimension.
- Output parameter:
Returns: c
Return type: numpy.ndarray dstiii(f)
computes the discrete sine transform of type I of the input signal f. If f is multi-dimensional, the transformation is applied along the first non-singleton dimension.dstiii(f,L)
zero-pads or truncates f to length L before doing the transformation.dstiii(f,[],dim)
ordstiii(f,L,dim)
applies the transformation along dimension dim.The transform is real (output is real if input is real) and orthonormal.
The inverse transform of |dstiii| is |dstii|.
Let f be a signal of length L, let
c=dstiii(f)
and define the vector w of length L byThen
- Examples:
The following figures show the first 4 basis functions of the DSTIII of length 20:
>>> import numpy as np >>> # The dstiii is its own adjoint. >>> F = dstiii(np.eye(20, dtype=np.float64)) >>> import matplotlib.pyplot as plt >>> plt.close('all') >>> fig = plt.figure() >>> for ii in range(1,5): ... ax = fig.add_subplot(4,1,ii) ... ax.stem(F[:,ii-1]) ... <Container object of 3 artists> <Container object of 3 artists> <Container object of 3 artists> <Container object of 3 artists> >>> plt.show()
- References:
- [RY90][Wickerhauser94]
dstiv¶
This module contains DSTIV function
Ported from ltfat_2.1.0/fourier/dstiv.m
-
ltfatpy.fourier.dstiv.
dstiv
(f, L=None, dim=None)[source]¶ Discrete Sine Transform type IV
Usage:
c = dstiv(f)
c = dstiv(f,L,dim)
Input parameters:
Parameters: - f (numpy.ndarray) – Input data. f dtype has to be float64 or complex128.
- L (int) – Length of the output vector. Default is the length of f.
- dim (int) – dimension along which the transformation is applied. Default is the first non-singleton dimension.
Output parameter:
return: c
rtype: numpy.ndarray
dstiv(f)
computes the discrete sine transform of type I of the input signal f. If f is multi-dimensional, the transformation is applied along the first non-singleton dimension.dstiv(f,L)
zero-pads or truncates f to length L before doing the transformation.dstiv(f,[],dim)
ordstiv(f,L,dim)
applies the transformation along dimension dim.The transform is real (output is real if input is real) and orthonormal.
This transform is its own inverse.
Let f be a signal of length L and let
c=dstiv(f)
. Then- Examples:
The following figures show the first 4 basis functions of the DSTIV of length 20:
>>> import numpy as np >>> # The dstiv is its own adjoint. >>> F = dstiv(np.eye(20, dtype=np.float64)) >>> import matplotlib.pyplot as plt >>> plt.close('all') >>> fig = plt.figure() >>> for ii in range(1,5): ... ax = fig.add_subplot(4,1,ii) ... ax.stem(F[:,ii-1]) ... <Container object of 3 artists> <Container object of 3 artists> <Container object of 3 artists> <Container object of 3 artists> >>> plt.show()
- References:
- [RY90][Wickerhauser94]