From b81fcd14ac29ca5d5b38abeabe1048d3e574723b Mon Sep 17 00:00:00 2001 From: "Documenter.jl" Date: Fri, 6 Dec 2024 15:36:09 +0000 Subject: [PATCH] build based on dee1e7b --- dev/.documenter-siteinfo.json | 2 +- dev/appendix/index.html | 2 +- dev/convolutions/index.html | 4 +-- dev/estimation/index.html | 4 +-- dev/filters/index.html | 16 +++++------ dev/index.html | 2 +- dev/internals/index.html | 6 ++--- dev/lpc/index.html | 4 +-- dev/periodograms/index.html | 50 +++++++++++++++++------------------ dev/util/index.html | 14 +++++----- dev/windows/index.html | 26 +++++++++--------- 11 files changed, 65 insertions(+), 65 deletions(-) diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 7d364f98..beb9f28f 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.11.2","generation_timestamp":"2024-12-06T06:45:14","documenter_version":"1.8.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.11.2","generation_timestamp":"2024-12-06T15:36:04","documenter_version":"1.8.0"}} \ No newline at end of file diff --git a/dev/appendix/index.html b/dev/appendix/index.html index f9752fce..93adcad0 100644 --- a/dev/appendix/index.html +++ b/dev/appendix/index.html @@ -1,2 +1,2 @@ -Index · DSP.jl

Index

+Index · DSP.jl

Index

diff --git a/dev/convolutions/index.html b/dev/convolutions/index.html index da533967..e48c854e 100644 --- a/dev/convolutions/index.html +++ b/dev/convolutions/index.html @@ -1,9 +1,9 @@ -Convolutions - similarity methods · DSP.jl

Convolutions - similarity methods

DSP.convFunction
conv(u, v; algorithm)

Convolution of two arrays. A convolution algorithm is automatically chosen among direct convolution, FFT, or FFT overlap-save, depending on the size of the input, unless explicitly specified with the algorithm keyword argument; see conv! for details.

source
conv(u,v,A)

2-D convolution of the matrix A with the 2-D separable kernel generated by the vector u and row-vector v. Uses 2-D FFT algorithm.

source
DSP.conv!Function
conv!(out, u, v; algorithm=:auto)

Convolution of two arrays u and v with the result stored in out. out must be large enough to store the entire result; if it is even larger, the excess entries will be zeroed.

out, u, and v can be N-dimensional arrays, with arbitrary indexing offsets. If none of them has offset axes, size(out,d) ≥ size(u,d) + size(v,d) - 1 must hold. If both input and output have offset axes, firstindex(out,d) ≤ firstindex(u,d) + firstindex(v,d) and lastindex(out,d) ≥ lastindex(u,d) + lastindex(v,d) must hold (for d = 1,...,N). A mix of offset and non-offset axes is not permitted.

The algorithm keyword allows choosing the algorithm to use:

  • :direct: Evaluates the convolution sum in time domain.
  • :fft_simple: Evaluates the convolution as a product in the frequency domain.
  • :fft_overlapsave: Evaluates the convolution block-wise as a product in the frequency domain, overlapping the resulting blocks.
  • :fft: Selects the faster of :fft_simple and :fft_overlapsave (as estimated from the input size).
  • :fast: Selects the fastest of :direct, :fft_simple and :fft_overlapsave (as estimated from the input size).
  • :auto (default): Equivalent to :fast if the data type is known to be suitable for FFT-based computation, equivalent to :direct otherwise.
Warning

The choices made by :fft, :fast, and :auto are based on performance heuristics which may not result in the fastest algorithm in all cases. If best performance for a certain size/type combination is required, it is advised to do individual benchmarking and explicitly specify the desired algorithm.

source
DSP.deconvFunction
deconv(b,a) -> c

Construct vector c such that b = conv(a,c) + r. Equivalent to polynomial division.

source
DSP.xcorrFunction
xcorr(u; padmode::Symbol=:none, scaling::Symbol=:none)
+Convolutions - similarity methods · DSP.jl

Convolutions - similarity methods

DSP.convFunction
conv(u, v; algorithm)

Convolution of two arrays. A convolution algorithm is automatically chosen among direct convolution, FFT, or FFT overlap-save, depending on the size of the input, unless explicitly specified with the algorithm keyword argument; see conv! for details.

source
conv(u,v,A)

2-D convolution of the matrix A with the 2-D separable kernel generated by the vector u and row-vector v. Uses 2-D FFT algorithm.

source
DSP.conv!Function
conv!(out, u, v; algorithm=:auto)

Convolution of two arrays u and v with the result stored in out. out must be large enough to store the entire result; if it is even larger, the excess entries will be zeroed.

out, u, and v can be N-dimensional arrays, with arbitrary indexing offsets. If none of them has offset axes, size(out,d) ≥ size(u,d) + size(v,d) - 1 must hold. If both input and output have offset axes, firstindex(out,d) ≤ firstindex(u,d) + firstindex(v,d) and lastindex(out,d) ≥ lastindex(u,d) + lastindex(v,d) must hold (for d = 1,...,N). A mix of offset and non-offset axes is not permitted.

The algorithm keyword allows choosing the algorithm to use:

  • :direct: Evaluates the convolution sum in time domain.
  • :fft_simple: Evaluates the convolution as a product in the frequency domain.
  • :fft_overlapsave: Evaluates the convolution block-wise as a product in the frequency domain, overlapping the resulting blocks.
  • :fft: Selects the faster of :fft_simple and :fft_overlapsave (as estimated from the input size).
  • :fast: Selects the fastest of :direct, :fft_simple and :fft_overlapsave (as estimated from the input size).
  • :auto (default): Equivalent to :fast if the data type is known to be suitable for FFT-based computation, equivalent to :direct otherwise.
Warning

The choices made by :fft, :fast, and :auto are based on performance heuristics which may not result in the fastest algorithm in all cases. If best performance for a certain size/type combination is required, it is advised to do individual benchmarking and explicitly specify the desired algorithm.

source
DSP.deconvFunction
deconv(b,a) -> c

Construct vector c such that b = conv(a,c) + r. Equivalent to polynomial division.

source
DSP.xcorrFunction
xcorr(u; padmode::Symbol=:none, scaling::Symbol=:none)
 xcorr(u, v; padmode::Symbol=:none, scaling::Symbol=:none)

With two arguments, compute the cross-correlation of two vectors, by calculating the similarity between u and v with various offsets of v. Delaying u relative to v will shift the result to the right. If one argument is provided, calculate xcorr(u, u; kwargs...).

The size of the output depends on the padmode keyword argument: with padmode = :none the length of the result will be length(u) + length(v) - 1, as with conv. With padmode = :longest, the shorter of the arguments will be padded so they are of equal length. This gives a result with length 2*max(length(u), length(v))-1, with the zero-lag condition at the center.

The keyword argument scaling can be provided. Possible arguments are the default :none and :biased. :biased is valid only if the vectors have the same length, or only one vector is provided, dividing the result by length(u).

Examples

julia> xcorr([1,2,3],[1,2,3])
 5-element Vector{Int64}:
   3
   8
  14
   8
-  3
source
+ 3
source
diff --git a/dev/estimation/index.html b/dev/estimation/index.html index acd19c7f..538af118 100644 --- a/dev/estimation/index.html +++ b/dev/estimation/index.html @@ -8,8 +8,8 @@ julia> esprit(x, M, p, Fs) 2-element Vector{Float64}: 2502.2704154274957 -399.8420984461712source
DSP.Estimation.jacobsenFunction
jacobsen(x::AbstractVector, Fs::Real = 1.0)

Estimate the largest frequency in the complex signal x using Jacobsen's algorithm [Jacobsen2007]. Argument Fs is the sampling frequency. All frequencies are expressed in Hz.

If the signal x is real, the estimated frequency is guaranteed to be positive, but it may be highly inaccurate (especially for frequencies close to zero or to Fs/2).

If the sampling frequency Fs is not provided, then it is assumed that Fs = 1.0.

source
DSP.Estimation.quinnFunction
quinn(x::Vector, f0::Real, Fs::Real = 1.0 ; tol = 1e-6, maxiters = 20)
+399.8420984461712
source
DSP.Estimation.jacobsenFunction
jacobsen(x::AbstractVector, Fs::Real = 1.0)

Estimate the largest frequency in the complex signal x using Jacobsen's algorithm [Jacobsen2007]. Argument Fs is the sampling frequency. All frequencies are expressed in Hz.

If the signal x is real, the estimated frequency is guaranteed to be positive, but it may be highly inaccurate (especially for frequencies close to zero or to Fs/2).

If the sampling frequency Fs is not provided, then it is assumed that Fs = 1.0.

source
DSP.Estimation.quinnFunction
quinn(x::Vector, f0::Real, Fs::Real = 1.0 ; tol = 1e-6, maxiters = 20)
 
 quinn(x::Vector, Fs::Real = 1.0 ; kwargs...)
 
-quinn(x::Vector ; kwargs...)

Algorithms by Quinn and Quinn & Fernandes for frequency estimation. Given a signal x and an initial guess f0, estimate and return the frequency of the largest sinusoid in x. Fs is the sampling frequency. All frequencies are expressed in Hz.

If the initial guess f0 is not provided, then a guess is calculated using Jacobsen's estimator. If the sampling frequency Fs is not provided, then it is assumed that Fs = 1.0.

The following keyword arguments control the algorithm's behavior:

  • tol: the algorithm stops when the absolute value of the difference between two consecutive estimates is less than tol. Defaults to 1e-6.
  • maxiters: the maximum number of iterations to run. Defaults to 20.

Returns a tuple (estimate, reachedmaxiters), where estimate is the estimated frequency, and reachedmaxiters is true if the algorithm finished after running for maxiters iterations (this may indicate that the algorithm did not converge).

If the signal x is real, then the algorithm used is [Quinn1991]. If the signal is complex, the algorithm is [Quinn2009].

source
+quinn(x::Vector ; kwargs...)

Algorithms by Quinn and Quinn & Fernandes for frequency estimation. Given a signal x and an initial guess f0, estimate and return the frequency of the largest sinusoid in x. Fs is the sampling frequency. All frequencies are expressed in Hz.

If the initial guess f0 is not provided, then a guess is calculated using Jacobsen's estimator. If the sampling frequency Fs is not provided, then it is assumed that Fs = 1.0.

The following keyword arguments control the algorithm's behavior:

Returns a tuple (estimate, reachedmaxiters), where estimate is the estimated frequency, and reachedmaxiters is true if the algorithm finished after running for maxiters iterations (this may indicate that the algorithm did not converge).

If the signal x is real, then the algorithm used is [Quinn1991]. If the signal is complex, the algorithm is [Quinn2009].

source
diff --git a/dev/filters/index.html b/dev/filters/index.html index f7549622..de19bcf7 100644 --- a/dev/filters/index.html +++ b/dev/filters/index.html @@ -1,9 +1,9 @@ -Filters - filter design and filtering · DSP.jl

Filters - filter design and filtering

DSP.jl differentiates between filter coefficients and stateful filters. Filter coefficient objects specify the response of the filter in one of several standard forms. Stateful filter objects carry the state of the filter together with filter coefficients in an implementable form (PolynomialRatio, Biquad, or SecondOrderSections). When invoked on a filter coefficient object, filt does not preserve state.

Filter coefficient objects

DSP.jl supports common filter representations. Filter coefficients can be converted from one type to another using convert.

DSP.Filters.ZeroPoleGainType
ZeroPoleGain(z::Vector, p::Vector, k::Number)

Filter representation in terms of zeros z, poles p, and gain k:

\[H(x) = k\frac{(x - \verb!z[1]!) \ldots (x - \verb!z[m]!)}{(x - \verb!p[1]!) \ldots (x - \verb!p[n]!)}\]

source
DSP.Filters.PolynomialRatioType
PolynomialRatio(b::Union{Number, Vector{<:Number}}, a::Union{Number, Vector{<:Number}})

Filter representation in terms of the coefficients of the numerator b and denominator a in the z or s domain where b and a are vectors ordered from highest power to lowest.

Inputs that are Numbers are treated as one-element Vectors.

Filter with:

  • Transfer function in z domain (zero & negative z powers):

\[H(z) = \frac{\verb!b[1]! + \ldots + \verb!b[m]! z^{-m+1}}{\verb!a[1]! + \ldots + \verb!a[n]! z^{-n+1}}\]

returns PolynomialRatio object with a[1] = 1 and other specified coefficients divided by a[1].

julia> PolynomialRatio([1,1],[1,2])
+Filters - filter design and filtering · DSP.jl

Filters - filter design and filtering

DSP.jl differentiates between filter coefficients and stateful filters. Filter coefficient objects specify the response of the filter in one of several standard forms. Stateful filter objects carry the state of the filter together with filter coefficients in an implementable form (PolynomialRatio, Biquad, or SecondOrderSections). When invoked on a filter coefficient object, filt does not preserve state.

Filter coefficient objects

DSP.jl supports common filter representations. Filter coefficients can be converted from one type to another using convert.

DSP.Filters.ZeroPoleGainType
ZeroPoleGain(z::Vector, p::Vector, k::Number)

Filter representation in terms of zeros z, poles p, and gain k:

\[H(x) = k\frac{(x - \verb!z[1]!) \ldots (x - \verb!z[m]!)}{(x - \verb!p[1]!) \ldots (x - \verb!p[n]!)}\]

source
DSP.Filters.PolynomialRatioType
PolynomialRatio(b::Union{Number, Vector{<:Number}}, a::Union{Number, Vector{<:Number}})

Filter representation in terms of the coefficients of the numerator b and denominator a in the z or s domain where b and a are vectors ordered from highest power to lowest.

Inputs that are Numbers are treated as one-element Vectors.

Filter with:

  • Transfer function in z domain (zero & negative z powers):

\[H(z) = \frac{\verb!b[1]! + \ldots + \verb!b[m]! z^{-m+1}}{\verb!a[1]! + \ldots + \verb!a[n]! z^{-n+1}}\]

returns PolynomialRatio object with a[1] = 1 and other specified coefficients divided by a[1].

julia> PolynomialRatio([1,1],[1,2])
 PolynomialRatio{:z, Float64}(LaurentPolynomial(1.0*z⁻¹ + 1.0), LaurentPolynomial(2.0*z⁻¹ + 1.0))
 julia> PolynomialRatio{:z}([1,2,3],[2,3,4])
 PolynomialRatio{:z, Float64}(LaurentPolynomial(1.5*z⁻² + 1.0*z⁻¹ + 0.5), LaurentPolynomial(2.0*z⁻² + 1.5*z⁻¹ + 1.0))
  • Transfer function in s domain (zero & positive s powers):

\[H(s) = \frac{\verb!b[1]! s^{m-1} + \ldots + \verb!b[m]!}{\verb!a[1]! s^{n-1} + \ldots + \verb!a[n]!}\]

returns PolynomialRatio object with specified b and a coefficients.

julia> PolynomialRatio{:s}([1,2,3],[2,3,4])
-PolynomialRatio{:s, Int64}(LaurentPolynomial(3 + 2*s + s²), LaurentPolynomial(4 + 3*s + 2*s²))
source
DSP.Filters.BiquadType
Biquad(b0::T, b1::T, b2::T, a1::T, a2::T) where T <: Number

Filter representation in terms of the transfer function of a single second-order section given by:

\[H(s) = \frac{\verb!b0! s^2+\verb!b1! s+\verb!b2!}{s^2+\verb!a1! s + \verb!a2!}\]

or equivalently:

\[H(z) = \frac{\verb!b0!+\verb!b1! z^{-1}+\verb!b2! z^{-2}}{1+\verb!a1! z^{-1} + \verb!a2! z^{-2}}\]

source
DSP.Filters.SecondOrderSectionsType
SecondOrderSections(biquads::Vector{<:Biquad}, gain::Number)

Filter representation in terms of a cascade of second-order sections and gain. biquads must be specified as a vector of Biquads.

source

These filter coefficient objects support the following arithmetic operations: inversion (inv), multiplication (*) for series connection, and integral power (^) for repeated multiplication with itself. For example:

julia> H = PolynomialRatio([1.0], [1.0, 0.3])
+PolynomialRatio{:s, Int64}(LaurentPolynomial(3 + 2*s + s²), LaurentPolynomial(4 + 3*s + 2*s²))
source
DSP.Filters.BiquadType
Biquad(b0::T, b1::T, b2::T, a1::T, a2::T) where T <: Number

Filter representation in terms of the transfer function of a single second-order section given by:

\[H(s) = \frac{\verb!b0! s^2+\verb!b1! s+\verb!b2!}{s^2+\verb!a1! s + \verb!a2!}\]

or equivalently:

\[H(z) = \frac{\verb!b0!+\verb!b1! z^{-1}+\verb!b2! z^{-2}}{1+\verb!a1! z^{-1} + \verb!a2! z^{-2}}\]

source
DSP.Filters.SecondOrderSectionsType
SecondOrderSections(biquads::Vector{<:Biquad}, gain::Number)

Filter representation in terms of a cascade of second-order sections and gain. biquads must be specified as a vector of Biquads.

source

These filter coefficient objects support the following arithmetic operations: inversion (inv), multiplication (*) for series connection, and integral power (^) for repeated multiplication with itself. For example:

julia> H = PolynomialRatio([1.0], [1.0, 0.3])
 PolynomialRatio{:z, Float64}(LaurentPolynomial(1.0), LaurentPolynomial(0.3*z⁻¹ + 1.0))
 
 julia> inv(H)
@@ -20,11 +20,11 @@
 

Stateful filter objects

DSP.Filters.DF2TFilterType
DF2TFilter(coef::FilterCoefficients{:z})
 DF2TFilter(coef::FilterCoefficients{:z}, coldims::Tuple)
 DF2TFilter(coef::FilterCoefficients{:z}, sitype::Type, coldims::Tuple = ())
-DF2TFilter(coef::FilterCoefficients{:z}, si)

Construct a stateful direct form II transposed filter with coefficients coef.

The initial filter state defaults to zeros (of a type derived from coef) suitable for vector input. Another element type of the state can be specified with sitype.

To allow column-wise filtering of higher-dimensional input, the size of the extra dimensions have to be given in coldims. To e.g. column-wise filter an input with size (L, N1, N2), set coldims to (N1, N2).

Alternatively, an array representing the initial filter state can be passed as si.

If coef is a PolynomialRatio, Biquad, or SecondOrderSections, filtering is implemented directly. If coef is a ZeroPoleGain object, it is first converted to a SecondOrderSections object.

source

DSP.jl's FIRFilter type maintains state between calls to filt, allowing you to filter a signal of indefinite length in RAM-friendly chunks. FIRFilter contains nothing more that the state of the filter, and a FIRKernel. There are five different kinds of FIRKernel for single rate, up-sampling, down-sampling, rational resampling, and arbitrary sample-rate conversion. You need not specify the type of kernel. The FIRFilter constructor selects the correct kernel based on input parameters.

DSP.Filters.FIRFilterType
FIRFilter(h::Vector[, ratio::Union{Integer,Rational}])

Construct a stateful FIRFilter object from the vector of filter taps h. ratio is an optional rational integer which specifies the input to output sample rate relationship (e.g. 147//160 for converting recorded audio from 48 KHz to 44.1 KHz).

source
FIRFilter(h::Vector, rate::AbstractFloat[, Nϕ::Integer=32])

Returns a polyphase FIRFilter object from the vector of filter taps h. rate is a floating point number that specifies the input to output sample-rate relationship $\frac{fs_{out}}{fs_{in}}$. is an optional parameter which specifies the number of phases created from h. defaults to 32.

source

Filter application

DSP.filtFunction
filt(b::Union{AbstractVector,Number},
+DF2TFilter(coef::FilterCoefficients{:z}, si)

Construct a stateful direct form II transposed filter with coefficients coef.

The initial filter state defaults to zeros (of a type derived from coef) suitable for vector input. Another element type of the state can be specified with sitype.

To allow column-wise filtering of higher-dimensional input, the size of the extra dimensions have to be given in coldims. To e.g. column-wise filter an input with size (L, N1, N2), set coldims to (N1, N2).

Alternatively, an array representing the initial filter state can be passed as si.

If coef is a PolynomialRatio, Biquad, or SecondOrderSections, filtering is implemented directly. If coef is a ZeroPoleGain object, it is first converted to a SecondOrderSections object.

source

DSP.jl's FIRFilter type maintains state between calls to filt, allowing you to filter a signal of indefinite length in RAM-friendly chunks. FIRFilter contains nothing more that the state of the filter, and a FIRKernel. There are five different kinds of FIRKernel for single rate, up-sampling, down-sampling, rational resampling, and arbitrary sample-rate conversion. You need not specify the type of kernel. The FIRFilter constructor selects the correct kernel based on input parameters.

DSP.Filters.FIRFilterType
FIRFilter(h::Vector[, ratio::Union{Integer,Rational}])

Construct a stateful FIRFilter object from the vector of filter taps h. ratio is an optional rational integer which specifies the input to output sample rate relationship (e.g. 147//160 for converting recorded audio from 48 KHz to 44.1 KHz).

source
FIRFilter(h::Vector, rate::AbstractFloat[, Nϕ::Integer=32])

Returns a polyphase FIRFilter object from the vector of filter taps h. rate is a floating point number that specifies the input to output sample-rate relationship $\frac{fs_{out}}{fs_{in}}$. is an optional parameter which specifies the number of phases created from h. defaults to 32.

source

Filter application

DSP.filtFunction
filt(b::Union{AbstractVector,Number},
      a::Union{AbstractVector,Number},
-     x::AbstractArray)

Apply filter described by vectors a and b to vector x.

Inputs that are Numbers are treated as one-element Vectors.

source
filt(f::FilterCoefficients{:z}, x::AbstractArray)

Apply filter or filter coefficients f along the first dimension of array x. If f is a PolynomialRatio, Biquad, or SecondOrderSections, filtering is implemented directly. If f is a ZeroPoleGain object, it is first converted to a SecondOrderSections object. If f is a Vector, it is interpreted as an FIR filter, and a naïve or FFT-based algorithm is selected based on the data and filter length.

source
filt(f::DF2TFilter{<:FilterCoefficients{:z},<:Array{T}}, x::AbstractArray{V}) where {T,V}

Apply the stateful filter f on x.

Warning

The output array has eltype promote_type(T, V), where T is the eltype of the filter state.

For more control over the output type, provide a preallocated output array out to filt!(out, f, x).

source
DSP.filt!Function
filt!(out, b, a, x)

Same as filt but writes the result into the out argument, which may alias the input x to modify it in-place.

source
filt!(out, f, x)

Same as filt() but writes the result into the out argument. Output array out may not be an alias of x, i.e. filtering may not be done in place.

source
DSP.Filters.filtfiltFunction
filtfilt(coef::FilterCoefficients, x::AbstractArray)
+     x::AbstractArray)

Apply filter described by vectors a and b to vector x.

Inputs that are Numbers are treated as one-element Vectors.

source
filt(f::FilterCoefficients{:z}, x::AbstractArray)

Apply filter or filter coefficients f along the first dimension of array x. If f is a PolynomialRatio, Biquad, or SecondOrderSections, filtering is implemented directly. If f is a ZeroPoleGain object, it is first converted to a SecondOrderSections object. If f is a Vector, it is interpreted as an FIR filter, and a naïve or FFT-based algorithm is selected based on the data and filter length.

source
filt(f::DF2TFilter{<:FilterCoefficients{:z},<:Array{T}}, x::AbstractArray{V}) where {T,V}

Apply the stateful filter f on x.

Warning

The output array has eltype promote_type(T, V), where T is the eltype of the filter state.

For more control over the output type, provide a preallocated output array out to filt!(out, f, x).

source
DSP.filt!Function
filt!(out, b, a, x)

Same as filt but writes the result into the out argument, which may alias the input x to modify it in-place.

source
filt!(out, f, x)

Same as filt() but writes the result into the out argument. Output array out may not be an alias of x, i.e. filtering may not be done in place.

source
DSP.Filters.filtfiltFunction
filtfilt(coef::FilterCoefficients, x::AbstractArray)
 filtfilt(b::AbstractVector, x::AbstractArray)
-filtfilt(b::AbstractVector, a::AbstractVector, x::AbstractArray)

Filter x in the forward and reverse directions using either a FilterCoefficients object coef, or the coefficients b and optionally a as in filt. The initial state of the filter is computed so that its response to a step function is steady state. Before filtering, the data is extrapolated at both ends with an odd-symmetric extension of length min(3*(max(length(b), length(a))-1), size(x, 1) - 1).

Because filtfilt applies the given filter twice, the effective filter order is twice the order of coef. The resulting signal has zero phase distortion.

source
DSP.Filters.fftfiltFunction
fftfilt(h::AbstractVector{<:Real}, x::AbstractArray{<:Real})

Apply FIR filter taps h along the first dimension of array x using an FFT-based overlap-save algorithm.

source
DSP.Filters.fftfilt!Function
fftfilt!(out::AbstractArray, h::AbstractVector, x::AbstractArray)

Like fftfilt but writes result into out array.

source
DSP.Filters.tdfiltFunction
tdfilt(h::AbstractVector, x::AbstractArray)

Apply filter or filter coefficients h along the first dimension of array x using a naïve time-domain algorithm

source
DSP.Filters.tdfilt!Function
tdfilt!(out::AbstractArray, h::AbstractVector, x::AbstractArray)

Like tdfilt, but writes the result into array out. Output array out may not be an alias of x, i.e. filtering may not be done in place.

source
DSP.Filters.resampleFunction
resample(x::AbstractVector, rate::Real[, coef::Vector])

Resample x at rational or arbitrary rate. coef is an optional vector of FIR filter taps. If coef is not provided, the taps will be computed using a Kaiser window.

Internally, resample uses a polyphase FIRFilter object, but performs additional operations to make resampling a signal easier. It compensates for the FIRFilter's delay (ramp-up), and appends zeros to x. The result is that when the input and output signals are plotted on top of each other, they correlate very well, but one signal will have more samples than the other.

source
resample(x::AbstractArray, rate::Real, h::Vector = resample_filter(rate); dims)

Resample an array x along dimension dims.

source

Filter design

Most analog and digital filters are constructed by composing response types, which determine the frequency response of the filter, with design methods, which determine how the filter is constructed.

The response type is Lowpass, Highpass, Bandpass or Bandstop and includes the edges of the bands.

The design method is Butterworth, Chebyshev1, Chebyshev2, Elliptic, or FIRWindow, and includes any necessary parameters for the method that affect the shape of the response, such as filter order, ripple, and attenuation.

Filter order estimation methods are available in buttord, cheb1ord, cheb2ord, and ellipord if the corner frequencies for different IIR filter types are known. remezord can be used for an initial FIR filter order estimate.

DSP.Filters.analogfilterFunction
analogfilter(responsetype::FilterType, designmethod::FilterCoefficients)

Construct an analog filter. See below for possible response and filter types.

source
DSP.Filters.digitalfilterFunction
digitalfilter(responsetype::FilterType, designmethod::FilterCoefficients[; fs::Real])

Construct a digital filter. See below for possible response and filter types.

source

For some filters, the design method is more general or inherently implies a response type; these direct design methods include remez which designs equiripple FIR filters of all types, and iirnotch which designs a 2nd order "biquad" IIR notch filter.

For a more general application of creating a digital filter from s-domain representation of an analog filter, one can use bilinear:

DSP.Filters.bilinearFunction
bilinear(f::FilterCoefficients{:s}, fs::Real)

Calculate the digital filter (z-domain) ZPK representation of an analog filter defined in s-domain using bilinear transform with sampling frequency fs. The s-domain representation is first converted to a ZPK representation in s-domain and then transformed to z-domain using bilinear transform.

source
bilinear(f::ZeroPoleGain{:s,Z,P,K}, fs::Real) where {Z,P,K}

Calculate the digital filter (z-domain) ZPK representation of an analog filter defined as a ZPK representation in s-domain using bilinear transform with sampling frequency fs.

Input s-domain representation must be a ZeroPoleGain{:s, Z, P, K} object:

\[H(s) = f.k\frac{(s - \verb!f.z[1]!) \ldots (s - \verb!f.z[m]!)}{(s - \verb!f.p[1]!) \ldots (s - \verb!f.p[n]!)}\]

Output z-domain representation is a ZeroPoleGain{:z, Z, P, K} object:

\[H(z) = K\frac{(z - \verb!Z[1]!) \ldots (z - \verb!Z[m]!)}{(z - \verb!P[1]!) \ldots (z - \verb!P[n]!)}\]

where Z, P, K are calculated as:

\[Z[i] = \frac{(2 + \verb!f.z[i]!/\verb!fs!)}{(2 - \verb!f.z[i]!/\verb!fs!)} \quad \text{for } i = 1, \ldots, m\]

\[P[i] = \frac{(2 + \verb!f.p[i]!/\verb!fs!)}{(2 - \verb!f.p[i]!/\verb!fs!)} \quad \text{for } i = 1, \ldots, n\]

\[K = f.k \ \mathcal{Re} \left[ \frac{\prod_{i=1}^m (2*fs - f.z[i])}{\prod_{i=1}^n (2*fs - f.p[i])} \right]\]

Here, m and n are respectively the numbers of zeros and poles in the s-domain representation. If m < n, then additional n-m zeros are added at z = -1.

source

Filter response types

The interpretation of the frequencies Wn, Wn1 and Wn2 depends on wether an analog or a digital filter is designed.

  1. If an analog filter is designed using analogfilter, the frequencies are interpreted as analog frequencies in radians/second.
  2. If a digital filter is designed using digitalfilter and the sampling frequency fs is specified, the frequencies of the filter response type are normalized to fs. This requires that the sampling frequency and the filter response type use the same frequency unit (Hz, radians/second, ...). If fs is not specified, the frequencies of the filter response type are interpreted as normalized frequencies in half-cycles/sample.

Filter design methods

IIR filter design methods

DSP.Filters.Chebyshev1Function
Chebyshev1(n::Integer, ripple::Real)

n pole Chebyshev type I filter with ripple dB ripple in the passband.

source
DSP.Filters.Chebyshev2Function
Chebyshev2(n::Integer, ripple::Real)

n pole Chebyshev type II filter with ripple dB ripple in the stopband.

source
DSP.Filters.EllipticFunction
Elliptic(n::Integer, rp::Real, rs::Real)

n pole elliptic (Cauer) filter with rp dB ripple in the passband and rs dB attentuation in the stopband.

source

Filter order estimation methods

IIR filter order estimation methods

DSP.Filters.buttordFunction
(N, ωn) = buttord(Wp::Tuple{Real,Real}, Ws::Tuple{Real,Real}, Rp::Real, Rs::Real; domain=:z)

Butterworth order estimate for bandpass and bandstop filter types. Wp and Ws are 2-element pass and stopband frequency edges, with no more than Rp dB passband ripple and at least Rs dB stopband attenuation. Based on the ordering of passband and bandstop edges, the Bandstop or Bandpass filter type is inferred. N is an integer indicating the lowest estimated filter order, with ωn specifying the cutoff or "-3 dB" frequencies.

If a domain of :s is specified, the passband and stopband frequencies are interpreted as radians/second, giving an order and natural frequencies for an analog filter. The default domain is :z, interpreting the input frequencies as normalized from 0 to 1, where 1 corresponds to π radians/sample.

source
(N, ωn) = buttord(Wp::Real, Ws::Real, Rp::Real, Rs::Real; domain=:z)

LPF/HPF Butterworth filter order and -3 dB frequency approximation. Wp and Ws are the passband and stopband frequencies, whereas Rp and Rs are the passband and stopband ripple attenuations in dB. If the passband is greater than stopband, the filter type is inferred to be for estimating the order of a highpass filter. N specifies the lowest possible integer filter order, whereas ωn is the cutoff or "-3 dB" frequency.

If a domain of :s is specified, the passband and stopband edges are interpreted as radians/second, giving an order and natural frequency result for an analog filter. The default domain is :z, interpreting the input frequencies as normalized from 0 to 1, where 1 corresponds to π radians/sample.

source
DSP.Filters.cheb1ordFunction
(N, ωn) = cheb1ord(Wp::Real, Ws::Real, Rp::Real, Rs::Real; domain::Symbol=:z)

Integer and natural frequency order estimation for Chebyshev Type I Filters. Wp and Ws indicate the passband and stopband frequency edges, and Rp and Rs indicate the maximum loss in the passband and the minimum attenuation in the stopband, (in dB.)

Based on the ordering of passband and stopband edges, the Lowpass or Highpass filter type is inferred. N indicates the smallest integer filter order that achieves the desired specifications, and ωn contains the natural frequency of the filter, (in this case, simply the passband edge.)

If a domain of :s is specified, the passband and stopband edges are interpreted as radians/second, giving an order and natural frequency result for an analog filter. The default domain is :z, interpreting the input frequencies as normalized from 0 to 1, where 1 corresponds to π radians/sample.

source
(N, ωn) = cheb1ord(Wp::Tuple{Real, Real}, Ws::Tuple{Real, Real}, Rp::Real, Rs::Real; domain::Symbol=:z)

Integer and natural frequency order estimation for Chebyshev Type I Filters. Wp and Ws are 2-element frequency edges for Bandpass/Bandstop cases, with Rp and Rs representing the ripple maximum loss in the passband and minimum ripple attenuation in the stopband in dB. Based on the ordering of passband and bandstop edges, the Bandstop or Bandpass filter type is inferred. N is an integer indicating the lowest estimated filter order, with ωn specifying the cutoff or "-3 dB" frequencies. If a domain of :s is specified, the passband and stopband frequencies are interpreted as radians/second, giving the order and natural frequencies for an analog filter. The default domain is :z, interpreting the input frequencies as normalized from 0 to 1, where 1 corresponds to π radians/sample.

source
DSP.Filters.cheb2ordFunction
(N, ωn) = cheb2ord(Wp::Real, Ws::Real, Rp::Real, Rs::Real; domain::Symbol=:z)

Integer and natural frequency order estimation for Chebyshev Type II (inverse) Filters. Wp and Ws are the frequency edges for Bandpass/Bandstop cases, with Rp and Rs representing the ripple maximum loss in the passband and minimum ripple attenuation in the stopband in dB.

Based on the ordering of the passband and stopband edges, the Lowpass or Highpass filter type is inferred. N is an integer indicating the lowest estimated filter order, with ωn specifying the "-3 dB" cutoff frequency.

If a domain of :s is specified, the passband and stopband frequencies are interpreted as radians/second, giving the order and natural frequencies for an analog filter. The default domain is :z, interpreting the input frequencies as normalized from 0 to 1, where 1 corresponds to π radians/sample.

source
(N, ωn) = cheb2ord(Wp::Tuple{Real, Real}, Ws::Tuple{Real, Real}, Rp::Real, Rs::Real; domain::Symbol=:z)

Integer and natural frequency order estimation for Chebyshev Type II (inverse) Filters. Wp and Ws are 2-element frequency edges for Bandpass/Bandstop cases, with Rp and Rs representing the ripple maximum loss in the passband and minimum ripple attenuation in the stopband in dB.

Based on the ordering of the passband and bandstop edges, the Bandstop or Bandpass filter type is inferred. N is an integer indicating the lowest estimated filter order, with ωn specifying the "-3 dB" cutoff frequency.

If a domain of :s is specified, the passband and stopband frequencies are interpreted as radians/second, giving the order and natural frequencies for an analog filter. The default domain is :z, interpreting the input frequencies as normalized from 0 to 1, where 1 corresponds to π radians/sample.

source
DSP.Filters.ellipordFunction
(N, ωn) = ellipord(Wp::Real, Ws::Real, Rp::Real, Rs::Real; domain::Symbol=:z)

Integer and natural frequency order estimation for Elliptic (Cauer) Filters. Wp and Ws indicate the passband and stopband frequency edges, and Rp and Rs indicate the maximum loss in the passband and the minimum attenuation in the stopband, (in dB.)

Based on the ordering of passband and stopband edges, the Lowpass or Highpass filter type is inferred. N indicates the smallest integer filter order that achieves the desired specifications, and ωn contains the natural frequency of the filter, (in this case, simply the passband edge.)

If a domain of :s is specified, the passband and stopband edges are interpreted as radians/second, giving an order and natural frequency result for an analog filter. The default domain is :z, interpreting the input frequencies as normalized from 0 to 1, where 1 corresponds to π radians/sample.

source
(N, ωn) = ellipord(Wp::Tuple{Real, Real}, Ws::Tuple{Real, Real}, Rp::Real, Rs::Real; domain::Symbol=:z)

Integer and natural frequency order estimation for Elliptic (Cauer) Filters. Wp and Ws are 2-element frequency edges for Bandpass/Bandstop cases, with Rp and Rs representing the ripple maximum loss in the passband and minimum ripple attenuation in the stopband in dB. Based on the ordering of passband and bandstop edges, the Bandstop or Bandpass filter type is inferred. N is an integer indicating the lowest estimated filter order, with ωn specifying the cutoff or "-3 dB" frequencies. If a domain of :s is specified, the passband and stopband frequencies are interpreted as radians/second, giving the order and natural frequencies for an analog filter. The default domain is :z, interpreting the input frequencies as normalized from 0 to 1, where 1 corresponds to π radians/sample.

source

FIR filter order estimation methods

DSP.Filters.remezordFunction
N = remezord(Wp::Real, Ws::Real, Rp::Real, Rs::Real)

Order estimation for lowpass digital filter cases based on the equations and coefficients in [Rabiner]. The original equation returned the minimum filter length, whereas this implementation returns the order (N=L-1). Wp and Ws are the normalized passband and stopband frequencies, with Rp indicating the passband ripple and Rs is the stopband attenuation (linear.)

NOTE: The value of N is an initial approximation. If under-estimated, the order should be increased until the design specifications are met.

source

FIR filter design methods

DSP.Filters.FIRWindowType
FIRWindow(window::Vector; scale=true)

FIR filter design using window window, a vector whose length matches the number of taps in the resulting filter.

If scale is true (default), the designed FIR filter is scaled so that the following holds:

  • For Lowpass and Bandstop filters, the frequency response is unity at 0 (DC).
  • For Highpass filters, the frequency response is unity at the Nyquist frequency.
  • For Bandpass filters, the frequency response is unity in the center of the passband.
source
FIRWindow(; transitionwidth::Real, attenuation::Real=60, scale::Bool=true)

Kaiser window FIR filter design. The required number of taps is calculated based on transitionwidth (in half-cycles/sample) and stopband attenuation (in dB). attenuation defaults to 60 dB.

source

Direct filter design methods

DSP.Filters.remezFunction
remez(numtaps::Integer, band_defs;
+filtfilt(b::AbstractVector, a::AbstractVector, x::AbstractArray)

Filter x in the forward and reverse directions using either a FilterCoefficients object coef, or the coefficients b and optionally a as in filt. The initial state of the filter is computed so that its response to a step function is steady state. Before filtering, the data is extrapolated at both ends with an odd-symmetric extension of length min(3*(max(length(b), length(a))-1), size(x, 1) - 1).

Because filtfilt applies the given filter twice, the effective filter order is twice the order of coef. The resulting signal has zero phase distortion.

source
DSP.Filters.fftfiltFunction
fftfilt(h::AbstractVector{<:Real}, x::AbstractArray{<:Real})

Apply FIR filter taps h along the first dimension of array x using an FFT-based overlap-save algorithm.

source
DSP.Filters.fftfilt!Function
fftfilt!(out::AbstractArray, h::AbstractVector, x::AbstractArray)

Like fftfilt but writes result into out array.

source
DSP.Filters.tdfiltFunction
tdfilt(h::AbstractVector, x::AbstractArray)

Apply filter or filter coefficients h along the first dimension of array x using a naïve time-domain algorithm

source
DSP.Filters.tdfilt!Function
tdfilt!(out::AbstractArray, h::AbstractVector, x::AbstractArray)

Like tdfilt, but writes the result into array out. Output array out may not be an alias of x, i.e. filtering may not be done in place.

source
DSP.Filters.resampleFunction
resample(x::AbstractVector, rate::Real[, coef::Vector])

Resample x at rational or arbitrary rate. coef is an optional vector of FIR filter taps. If coef is not provided, the taps will be computed using a Kaiser window.

Internally, resample uses a polyphase FIRFilter object, but performs additional operations to make resampling a signal easier. It compensates for the FIRFilter's delay (ramp-up), and appends zeros to x. The result is that when the input and output signals are plotted on top of each other, they correlate very well, but one signal will have more samples than the other.

source
resample(x::AbstractArray, rate::Real, h::Vector = resample_filter(rate); dims)

Resample an array x along dimension dims.

source

Filter design

Most analog and digital filters are constructed by composing response types, which determine the frequency response of the filter, with design methods, which determine how the filter is constructed.

The response type is Lowpass, Highpass, Bandpass or Bandstop and includes the edges of the bands.

The design method is Butterworth, Chebyshev1, Chebyshev2, Elliptic, or FIRWindow, and includes any necessary parameters for the method that affect the shape of the response, such as filter order, ripple, and attenuation.

Filter order estimation methods are available in buttord, cheb1ord, cheb2ord, and ellipord if the corner frequencies for different IIR filter types are known. remezord can be used for an initial FIR filter order estimate.

DSP.Filters.analogfilterFunction
analogfilter(responsetype::FilterType, designmethod::FilterCoefficients)

Construct an analog filter. See below for possible response and filter types.

source
DSP.Filters.digitalfilterFunction
digitalfilter(responsetype::FilterType, designmethod::FilterCoefficients[; fs::Real])

Construct a digital filter. See below for possible response and filter types.

source

For some filters, the design method is more general or inherently implies a response type; these direct design methods include remez which designs equiripple FIR filters of all types, and iirnotch which designs a 2nd order "biquad" IIR notch filter.

For a more general application of creating a digital filter from s-domain representation of an analog filter, one can use bilinear:

DSP.Filters.bilinearFunction
bilinear(f::FilterCoefficients{:s}, fs::Real)

Calculate the digital filter (z-domain) ZPK representation of an analog filter defined in s-domain using bilinear transform with sampling frequency fs. The s-domain representation is first converted to a ZPK representation in s-domain and then transformed to z-domain using bilinear transform.

source
bilinear(f::ZeroPoleGain{:s,Z,P,K}, fs::Real) where {Z,P,K}

Calculate the digital filter (z-domain) ZPK representation of an analog filter defined as a ZPK representation in s-domain using bilinear transform with sampling frequency fs.

Input s-domain representation must be a ZeroPoleGain{:s, Z, P, K} object:

\[H(s) = f.k\frac{(s - \verb!f.z[1]!) \ldots (s - \verb!f.z[m]!)}{(s - \verb!f.p[1]!) \ldots (s - \verb!f.p[n]!)}\]

Output z-domain representation is a ZeroPoleGain{:z, Z, P, K} object:

\[H(z) = K\frac{(z - \verb!Z[1]!) \ldots (z - \verb!Z[m]!)}{(z - \verb!P[1]!) \ldots (z - \verb!P[n]!)}\]

where Z, P, K are calculated as:

\[Z[i] = \frac{(2 + \verb!f.z[i]!/\verb!fs!)}{(2 - \verb!f.z[i]!/\verb!fs!)} \quad \text{for } i = 1, \ldots, m\]

\[P[i] = \frac{(2 + \verb!f.p[i]!/\verb!fs!)}{(2 - \verb!f.p[i]!/\verb!fs!)} \quad \text{for } i = 1, \ldots, n\]

\[K = f.k \ \mathcal{Re} \left[ \frac{\prod_{i=1}^m (2*fs - f.z[i])}{\prod_{i=1}^n (2*fs - f.p[i])} \right]\]

Here, m and n are respectively the numbers of zeros and poles in the s-domain representation. If m < n, then additional n-m zeros are added at z = -1.

source

Filter response types

The interpretation of the frequencies Wn, Wn1 and Wn2 depends on wether an analog or a digital filter is designed.

  1. If an analog filter is designed using analogfilter, the frequencies are interpreted as analog frequencies in radians/second.
  2. If a digital filter is designed using digitalfilter and the sampling frequency fs is specified, the frequencies of the filter response type are normalized to fs. This requires that the sampling frequency and the filter response type use the same frequency unit (Hz, radians/second, ...). If fs is not specified, the frequencies of the filter response type are interpreted as normalized frequencies in half-cycles/sample.

Filter design methods

IIR filter design methods

DSP.Filters.Chebyshev1Function
Chebyshev1(n::Integer, ripple::Real)

n pole Chebyshev type I filter with ripple dB ripple in the passband.

source
DSP.Filters.Chebyshev2Function
Chebyshev2(n::Integer, ripple::Real)

n pole Chebyshev type II filter with ripple dB ripple in the stopband.

source
DSP.Filters.EllipticFunction
Elliptic(n::Integer, rp::Real, rs::Real)

n pole elliptic (Cauer) filter with rp dB ripple in the passband and rs dB attentuation in the stopband.

source

Filter order estimation methods

IIR filter order estimation methods

DSP.Filters.buttordFunction
(N, ωn) = buttord(Wp::Tuple{Real,Real}, Ws::Tuple{Real,Real}, Rp::Real, Rs::Real; domain=:z)

Butterworth order estimate for bandpass and bandstop filter types. Wp and Ws are 2-element pass and stopband frequency edges, with no more than Rp dB passband ripple and at least Rs dB stopband attenuation. Based on the ordering of passband and bandstop edges, the Bandstop or Bandpass filter type is inferred. N is an integer indicating the lowest estimated filter order, with ωn specifying the cutoff or "-3 dB" frequencies.

If a domain of :s is specified, the passband and stopband frequencies are interpreted as radians/second, giving an order and natural frequencies for an analog filter. The default domain is :z, interpreting the input frequencies as normalized from 0 to 1, where 1 corresponds to π radians/sample.

source
(N, ωn) = buttord(Wp::Real, Ws::Real, Rp::Real, Rs::Real; domain=:z)

LPF/HPF Butterworth filter order and -3 dB frequency approximation. Wp and Ws are the passband and stopband frequencies, whereas Rp and Rs are the passband and stopband ripple attenuations in dB. If the passband is greater than stopband, the filter type is inferred to be for estimating the order of a highpass filter. N specifies the lowest possible integer filter order, whereas ωn is the cutoff or "-3 dB" frequency.

If a domain of :s is specified, the passband and stopband edges are interpreted as radians/second, giving an order and natural frequency result for an analog filter. The default domain is :z, interpreting the input frequencies as normalized from 0 to 1, where 1 corresponds to π radians/sample.

source
DSP.Filters.cheb1ordFunction
(N, ωn) = cheb1ord(Wp::Real, Ws::Real, Rp::Real, Rs::Real; domain::Symbol=:z)

Integer and natural frequency order estimation for Chebyshev Type I Filters. Wp and Ws indicate the passband and stopband frequency edges, and Rp and Rs indicate the maximum loss in the passband and the minimum attenuation in the stopband, (in dB.)

Based on the ordering of passband and stopband edges, the Lowpass or Highpass filter type is inferred. N indicates the smallest integer filter order that achieves the desired specifications, and ωn contains the natural frequency of the filter, (in this case, simply the passband edge.)

If a domain of :s is specified, the passband and stopband edges are interpreted as radians/second, giving an order and natural frequency result for an analog filter. The default domain is :z, interpreting the input frequencies as normalized from 0 to 1, where 1 corresponds to π radians/sample.

source
(N, ωn) = cheb1ord(Wp::Tuple{Real, Real}, Ws::Tuple{Real, Real}, Rp::Real, Rs::Real; domain::Symbol=:z)

Integer and natural frequency order estimation for Chebyshev Type I Filters. Wp and Ws are 2-element frequency edges for Bandpass/Bandstop cases, with Rp and Rs representing the ripple maximum loss in the passband and minimum ripple attenuation in the stopband in dB. Based on the ordering of passband and bandstop edges, the Bandstop or Bandpass filter type is inferred. N is an integer indicating the lowest estimated filter order, with ωn specifying the cutoff or "-3 dB" frequencies. If a domain of :s is specified, the passband and stopband frequencies are interpreted as radians/second, giving the order and natural frequencies for an analog filter. The default domain is :z, interpreting the input frequencies as normalized from 0 to 1, where 1 corresponds to π radians/sample.

source
DSP.Filters.cheb2ordFunction
(N, ωn) = cheb2ord(Wp::Real, Ws::Real, Rp::Real, Rs::Real; domain::Symbol=:z)

Integer and natural frequency order estimation for Chebyshev Type II (inverse) Filters. Wp and Ws are the frequency edges for Bandpass/Bandstop cases, with Rp and Rs representing the ripple maximum loss in the passband and minimum ripple attenuation in the stopband in dB.

Based on the ordering of the passband and stopband edges, the Lowpass or Highpass filter type is inferred. N is an integer indicating the lowest estimated filter order, with ωn specifying the "-3 dB" cutoff frequency.

If a domain of :s is specified, the passband and stopband frequencies are interpreted as radians/second, giving the order and natural frequencies for an analog filter. The default domain is :z, interpreting the input frequencies as normalized from 0 to 1, where 1 corresponds to π radians/sample.

source
(N, ωn) = cheb2ord(Wp::Tuple{Real, Real}, Ws::Tuple{Real, Real}, Rp::Real, Rs::Real; domain::Symbol=:z)

Integer and natural frequency order estimation for Chebyshev Type II (inverse) Filters. Wp and Ws are 2-element frequency edges for Bandpass/Bandstop cases, with Rp and Rs representing the ripple maximum loss in the passband and minimum ripple attenuation in the stopband in dB.

Based on the ordering of the passband and bandstop edges, the Bandstop or Bandpass filter type is inferred. N is an integer indicating the lowest estimated filter order, with ωn specifying the "-3 dB" cutoff frequency.

If a domain of :s is specified, the passband and stopband frequencies are interpreted as radians/second, giving the order and natural frequencies for an analog filter. The default domain is :z, interpreting the input frequencies as normalized from 0 to 1, where 1 corresponds to π radians/sample.

source
DSP.Filters.ellipordFunction
(N, ωn) = ellipord(Wp::Real, Ws::Real, Rp::Real, Rs::Real; domain::Symbol=:z)

Integer and natural frequency order estimation for Elliptic (Cauer) Filters. Wp and Ws indicate the passband and stopband frequency edges, and Rp and Rs indicate the maximum loss in the passband and the minimum attenuation in the stopband, (in dB.)

Based on the ordering of passband and stopband edges, the Lowpass or Highpass filter type is inferred. N indicates the smallest integer filter order that achieves the desired specifications, and ωn contains the natural frequency of the filter, (in this case, simply the passband edge.)

If a domain of :s is specified, the passband and stopband edges are interpreted as radians/second, giving an order and natural frequency result for an analog filter. The default domain is :z, interpreting the input frequencies as normalized from 0 to 1, where 1 corresponds to π radians/sample.

source
(N, ωn) = ellipord(Wp::Tuple{Real, Real}, Ws::Tuple{Real, Real}, Rp::Real, Rs::Real; domain::Symbol=:z)

Integer and natural frequency order estimation for Elliptic (Cauer) Filters. Wp and Ws are 2-element frequency edges for Bandpass/Bandstop cases, with Rp and Rs representing the ripple maximum loss in the passband and minimum ripple attenuation in the stopband in dB. Based on the ordering of passband and bandstop edges, the Bandstop or Bandpass filter type is inferred. N is an integer indicating the lowest estimated filter order, with ωn specifying the cutoff or "-3 dB" frequencies. If a domain of :s is specified, the passband and stopband frequencies are interpreted as radians/second, giving the order and natural frequencies for an analog filter. The default domain is :z, interpreting the input frequencies as normalized from 0 to 1, where 1 corresponds to π radians/sample.

source

FIR filter order estimation methods

DSP.Filters.remezordFunction
N = remezord(Wp::Real, Ws::Real, Rp::Real, Rs::Real)

Order estimation for lowpass digital filter cases based on the equations and coefficients in [Rabiner]. The original equation returned the minimum filter length, whereas this implementation returns the order (N=L-1). Wp and Ws are the normalized passband and stopband frequencies, with Rp indicating the passband ripple and Rs is the stopband attenuation (linear.)

NOTE: The value of N is an initial approximation. If under-estimated, the order should be increased until the design specifications are met.

source

FIR filter design methods

DSP.Filters.FIRWindowType
FIRWindow(window::Vector; scale=true)

FIR filter design using window window, a vector whose length matches the number of taps in the resulting filter.

If scale is true (default), the designed FIR filter is scaled so that the following holds:

  • For Lowpass and Bandstop filters, the frequency response is unity at 0 (DC).
  • For Highpass filters, the frequency response is unity at the Nyquist frequency.
  • For Bandpass filters, the frequency response is unity in the center of the passband.
source
FIRWindow(; transitionwidth::Real, attenuation::Real=60, scale::Bool=true)

Kaiser window FIR filter design. The required number of taps is calculated based on transitionwidth (in half-cycles/sample) and stopband attenuation (in dB). attenuation defaults to 60 dB.

source

Direct filter design methods

DSP.Filters.remezFunction
remez(numtaps::Integer, band_defs;
       Hz::Real=1.0,
       neg::Bool=false,
       maxiter::Integer=25,
@@ -37,7 +37,7 @@
 julia> grid()

Examples from the unittests - standard (even) symmetry.

Length 151 LPF (Low Pass Filter).

julia> h = remez(151, [(0, 0.475) => 1, (0.5, 1.0) => 0]; Hz=2.0);

Length 152 LPF. Non-default "weight" input.

julia> h = remez(152, [(0, 0.475) => (1, 1), (0.5, 1.0) => (0, 2)]; Hz=2.0);

Length 51 HPF (High Pass Filter).

julia> h = remez(51, [(0, 0.75) => 0, (0.8, 1.0) => 1]; Hz=2.0);

Length 180 BPF (Band Pass Filter).

julia> h = remez(180, [(0, 0.375) => 0, (0.4, 0.5) => 1, (0.525, 1.0) => 0]; Hz=2.0, maxiter=30);

Examples from the unittests - Odd-symmetric filters - hilbert and differentiators type.

Even length - has a much better approximation since the response is not constrained to 0 at the nyquist frequency. Length 20 Hilbert transformer.

julia> h = remez(20, [(0.1, 0.95) => 1]; neg=true, Hz=2.0);

Length 21 Hilbert transformer.

julia> h = remez(21, [(0.1, 0.95) => 1]; neg=true, Hz=2.0);

Length 200 differentiator.

julia> h = remez(200, [(0.01, 0.99) => (f -> f/2, f -> 1/f)]; neg=true, Hz=2.0);

Length 201 differentiator.

julia> h = remez(201, [(0.05, 0.95) => (f -> f/2, f -> 1/f)]; neg=true, Hz=2.0);

Inverse sinc filter - custom response function

julia> L = 64; Fs = 4800*L;
 julia> passband_response_function = f -> (f==0) ? 1.0 : abs.((π*f/4800) ./ sin.(π*f/4800));
 julia> h = remez(201, [(    0.0, 2880.0) => (passband_response_function, 1.0),
-                (10000.0,   Fs/2) => (0.0, 100.0)]; Hz=Fs);
source
remez(numtaps::Integer,
+                (10000.0,   Fs/2) => (0.0, 100.0)]; Hz=Fs);
source
remez(numtaps::Integer,
       bands::Vector,
       desired::Vector;
       weight::Vector=[],
@@ -56,7 +56,7 @@
 
julia> h = remez(200, [(0.01, 0.99) => (f -> f/2, f -> 1/f)]; neg=true, Hz=2.0);
 
 julia> h = remez(200, [0.01, 0.99], [1]; filter_type=filter_type_differentiator, Hz=2.0);
-
source
DSP.Filters.iirnotchFunction
iirnotch(Wn::Real, bandwidth::Real[; fs=2])

Second-order digital IIR notch filter [Orfanidis] at frequency Wn with bandwidth bandwidth. If fs is not specified, Wn is interpreted as a normalized frequency in half-cycles/sample.

source

Filter response

DSP.Filters.freqrespFunction
H, w = freqresp(filter::FilterCoefficients)

Frequency response H of a filter at (normalized) frequencies w in radians/sample for a digital filter or radians/second for an analog filter chosen as a reasonable default.

source
freqresp(filter::FilterCoefficients{:z}, w)

Frequency response of digital filter at normalized frequency or frequencies w in radians/sample.

source
freqresp(filter::FilterCoefficients{:s}, w)

Frequency response of analog filter at frequency or frequencies w in radians/second.

source
DSP.Filters.phaserespFunction
phi, w = phaseresp(filter::FilterCoefficients)

Phase response phi of a filter at (normalized) frequencies w in radians/sample for a digital filter or radians/second for an analog filter chosen as a reasonable default.

source
phaseresp(filter::FilterCoefficients, w)

Phase response of a filter at (normalized) frequency or frequencies w in radians/sample for a digital filter or radians/second for an analog filter.

source
DSP.Filters.grpdelayFunction
tau, w = grpdelay(filter::FilterCoefficients)

Group delay tau of a filter at (normalized) frequencies w in radians/sample for a digital filter or radians/second for an analog filter chosen as a reasonable default.

source
grpdelay(filter::FilterCoefficients{:z}, w)

Group delay of a digital filter at normalized frequency or frequencies w in radians/sample.

source
DSP.Filters.imprespFunction
impresp(filter::FilterCoefficients{:z}, n=100)

Impulse response of a digital filter with n points.

source
DSP.Filters.steprespFunction
stepresp(filter::FilterCoefficients{:z}, n=100)

Step response of a digital filter with n points.

source

Miscellaneous

DSP.Filters.coefbFunction
coefb(f::PolynomialRatio)

Coefficients of the numerator of a PolynomialRatio object, highest power first, i.e., the b passed to filt()

source
DSP.Filters.coefaFunction
coefa(f::PolynomialRatio)

Coefficients of the denominator of a PolynomialRatio object, highest power first, i.e., the a passed to filt()

source

Examples

Construct a 4th order elliptic lowpass filter with normalized cutoff frequency 0.2, 0.5 dB of passband ripple, and 30 dB attentuation in the stopband and extract the coefficients of the numerator and denominator of the transfer function:

responsetype = Lowpass(0.2)
+
source
DSP.Filters.iirnotchFunction
iirnotch(Wn::Real, bandwidth::Real[; fs=2])

Second-order digital IIR notch filter [Orfanidis] at frequency Wn with bandwidth bandwidth. If fs is not specified, Wn is interpreted as a normalized frequency in half-cycles/sample.

source

Filter response

DSP.Filters.freqrespFunction
H, w = freqresp(filter::FilterCoefficients)

Frequency response H of a filter at (normalized) frequencies w in radians/sample for a digital filter or radians/second for an analog filter chosen as a reasonable default.

source
freqresp(filter::FilterCoefficients{:z}, w)

Frequency response of digital filter at normalized frequency or frequencies w in radians/sample.

source
freqresp(filter::FilterCoefficients{:s}, w)

Frequency response of analog filter at frequency or frequencies w in radians/second.

source
DSP.Filters.phaserespFunction
phi, w = phaseresp(filter::FilterCoefficients)

Phase response phi of a filter at (normalized) frequencies w in radians/sample for a digital filter or radians/second for an analog filter chosen as a reasonable default.

source
phaseresp(filter::FilterCoefficients, w)

Phase response of a filter at (normalized) frequency or frequencies w in radians/sample for a digital filter or radians/second for an analog filter.

source
DSP.Filters.grpdelayFunction
tau, w = grpdelay(filter::FilterCoefficients)

Group delay tau of a filter at (normalized) frequencies w in radians/sample for a digital filter or radians/second for an analog filter chosen as a reasonable default.

source
grpdelay(filter::FilterCoefficients{:z}, w)

Group delay of a digital filter at normalized frequency or frequencies w in radians/sample.

source
DSP.Filters.imprespFunction
impresp(filter::FilterCoefficients{:z}, n=100)

Impulse response of a digital filter with n points.

source
DSP.Filters.steprespFunction
stepresp(filter::FilterCoefficients{:z}, n=100)

Step response of a digital filter with n points.

source

Miscellaneous

DSP.Filters.coefbFunction
coefb(f::PolynomialRatio)

Coefficients of the numerator of a PolynomialRatio object, highest power first, i.e., the b passed to filt()

source
DSP.Filters.coefaFunction
coefa(f::PolynomialRatio)

Coefficients of the denominator of a PolynomialRatio object, highest power first, i.e., the a passed to filt()

source

Examples

Construct a 4th order elliptic lowpass filter with normalized cutoff frequency 0.2, 0.5 dB of passband ripple, and 30 dB attentuation in the stopband and extract the coefficients of the numerator and denominator of the transfer function:

responsetype = Lowpass(0.2)
 designmethod = Elliptic(4, 0.5, 30)
 tf = convert(PolynomialRatio, digitalfilter(responsetype, designmethod))
 numerator_coefs = coefb(tf)
@@ -64,4 +64,4 @@
 designmethod = Butterworth(4)
 filt(digitalfilter(responsetype, designmethod; fs=1000), x)

Filter the data in x, sampled at 50 Hz, with a 64 tap Hanning window FIR lowpass filter at 5 Hz:

responsetype = Lowpass(5)
 designmethod = FIRWindow(hanning(64))
-filt(digitalfilter(responsetype, designmethod; fs=50), x)

Estimate a Lowpass Elliptic filter order with a normalized passband cutoff frequency of 0.2, a stopband cutoff frequency of 0.4, 3 dB of passband ripple, and 40 dB attenuation in the stopband:

(N, ωn) = ellipord(0.2, 0.4, 3, 40)
  • RabinerHerrmann, O., Lawrence R. Rabiner, and D. S. K. Chan. "Practical design rules for optimum finite impulse response lowpass digital filters." Bell System Technical Journal 52.6 (1973): 769-799.
  • McClellan1973aJ. H. McClellan and T. W. Parks, A unified approach to the design of optimum FIR linear phase digital filters, IEEE Trans. Circuit Theory, vol. CT-20, pp. 697-701, 1973.
  • McClellan1973bJ. H. McClellan, T. W. Parks and L. R. Rabiner, A Computer Program for Designing Optimum FIR Linear Phase Digital Filters, IEEE Trans. Audio Electroacoust., vol. AU-21, pp. 506-525, 1973.
  • OrfanidisOrfanidis, S. J. (1996). Introduction to signal processing. Englewood Cliffs, N.J: Prentice Hall, p. 370.
+filt(digitalfilter(responsetype, designmethod; fs=50), x)

Estimate a Lowpass Elliptic filter order with a normalized passband cutoff frequency of 0.2, a stopband cutoff frequency of 0.4, 3 dB of passband ripple, and 40 dB attenuation in the stopband:

(N, ωn) = ellipord(0.2, 0.4, 3, 40)
diff --git a/dev/index.html b/dev/index.html index 9b48ab96..01fae61e 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,2 +1,2 @@ -Home · DSP.jl
+Home · DSP.jl
diff --git a/dev/internals/index.html b/dev/internals/index.html index cf219f7c..64d994e9 100644 --- a/dev/internals/index.html +++ b/dev/internals/index.html @@ -1,10 +1,10 @@ -Internals · DSP.jl

Internals

Functions here are not exported.

DSP.os_fft_complexityFunction

Estimate the number of floating point multiplications per output sample for an overlap-save algorithm with fft size nfft, and filter size nb.

source
DSP.os_prepare_convFunction

Prepare buffers and FFTW plans for convolution. The two buffers, tdbuff and fdbuff may be an alias of each other, because complex convolution only requires one buffer. The plans are mutating where possible, and the inverse plan is unnormalized.

source
DSP.os_conv_block!Function

Take a block of data, and convolve it with the smaller convolution input. This may modify the contents of tdbuff and fdbuff, and the result will be in tdbuff.

source

Like the real version, but only operates on one buffer

source
DSP.os_filter_transform!Function

Transform the smaller convolution input to frequency domain, and return it in a new array. However, the contents of buff may be modified.

source
DSP.Windows.makewindowFunction
makewindow(winfunc::Function, n::Integer, padding::Integer, zerophase::Bool)

Generate a discrete window vector of the given length with padding zeros. winfunc should be a function giving the window value in the range of [-0.5, 0.5]. The function is assumed to be 0 outside of this range.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

Example:

function hanning(n::Integer; padding::Integer=0, zerophase::Bool=false)
+Internals · DSP.jl

Internals

Functions here are not exported.

DSP.os_fft_complexityFunction

Estimate the number of floating point multiplications per output sample for an overlap-save algorithm with fft size nfft, and filter size nb.

source
DSP.os_prepare_convFunction

Prepare buffers and FFTW plans for convolution. The two buffers, tdbuff and fdbuff may be an alias of each other, because complex convolution only requires one buffer. The plans are mutating where possible, and the inverse plan is unnormalized.

source
DSP.os_conv_block!Function

Take a block of data, and convolve it with the smaller convolution input. This may modify the contents of tdbuff and fdbuff, and the result will be in tdbuff.

source

Like the real version, but only operates on one buffer

source
DSP.os_filter_transform!Function

Transform the smaller convolution input to frequency domain, and return it in a new array. However, the contents of buff may be modified.

source
DSP.Windows.makewindowFunction
makewindow(winfunc::Function, n::Integer, padding::Integer, zerophase::Bool)

Generate a discrete window vector of the given length with padding zeros. winfunc should be a function giving the window value in the range of [-0.5, 0.5]. The function is assumed to be 0 outside of this range.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

Example:

function hanning(n::Integer; padding::Integer=0, zerophase::Bool=false)
     makewindow(n, padding, zerophase) do x
         0.5*(1+cos(2pi*x))
     end
-end
source
DSP.Windows.padplotFunction
padplot(plotstr)

Takes a multiline string and pre-pads it so that it shows up as preformatted code when included in a docstring.

source
DSP._zeropadFunction
_zeropad(u, padded_size, [data_dest, data_region])

Creates and returns a new base-1 index array of size padded_size, with the section of u specified by data_region copied into the region of the new array as specified by data_dest. All other values will be initialized to zero.

If either data_dest or data_region is not specified, then the defaults described in _zeropad! will be used.

source
DSP.Windows.padplotFunction
padplot(plotstr)

Takes a multiline string and pre-pads it so that it shows up as preformatted code when included in a docstring.

source
DSP._zeropadFunction
_zeropad(u, padded_size, [data_dest, data_region])

Creates and returns a new base-1 index array of size padded_size, with the section of u specified by data_region copied into the region of the new array as specified by data_dest. All other values will be initialized to zero.

If either data_dest or data_region is not specified, then the defaults described in _zeropad! will be used.

source
DSP._zeropad!Function
_zeropad!(padded::AbstractVector,
           u::AbstractVector,
           padded_axes = axes(padded),
           data_dest::Tuple = (1,),
-          data_region = CartesianIndices(u))

Place the portion of u specified by data_region into padded, starting at location data_dest. Sets the rest of padded to zero. This will mutate padded. padded_axes must correspond to the axes of padded.

source
DSP.Filters._polyprepFunction
_polyprep(D::Symbol, x::Union{T,Vector{T}}, ::Type) where {T<:Number}

Converts x to polynomial form. If x is a Number, it has to be converted into a Vector, otherwise LaurentPolynomial dispatch goes into stack overflow trying to collect a 0-d array into a Vector.

Warning

The DSP convention for Laplace domain is highest power first.

The Polynomials.jl convention is lowest power first.

source
DSP.Filters.freq_evalFunction
function freq_eval(xf, x::AbstractVector, y::AbstractVector, ad::AbstractVector)

FUNCTION: freq_eval (gee) FUNCTION TO EVALUATE THE FREQUENCY RESPONSE USING THE LAGRANGE INTERPOLATION FORMULA IN THE BARYCENTRIC FORM


source
DSP.Filters.lagrange_interpFunction
lagrange_interp(k::Integer, n::Integer, m::Integer, x::AbstractVector)

CALCULATE THE LAGRANGE INTERPOLATION COEFFICIENTS

source
DSP.Periodograms.coherence_from_cs!Function
coherence_from_cs!(output::AbstractArray, cs_matrix)

Compute the pairwise channel coherences from a cross spectral matrix, storing the result in output.

source
DSP.optimalfftfiltlengthFunction

Determine the length of FFT that minimizes the number of multiplications per output sample for an overlap-save convolution of vectors of size nb and nx.

source
+ data_region = CartesianIndices(u))

Place the portion of u specified by data_region into padded, starting at location data_dest. Sets the rest of padded to zero. This will mutate padded. padded_axes must correspond to the axes of padded.

source
DSP.Filters._polyprepFunction
_polyprep(D::Symbol, x::Union{T,Vector{T}}, ::Type) where {T<:Number}

Converts x to polynomial form. If x is a Number, it has to be converted into a Vector, otherwise LaurentPolynomial dispatch goes into stack overflow trying to collect a 0-d array into a Vector.

Warning

The DSP convention for Laplace domain is highest power first.

The Polynomials.jl convention is lowest power first.

source
DSP.Filters.freq_evalFunction
function freq_eval(xf, x::AbstractVector, y::AbstractVector, ad::AbstractVector)

FUNCTION: freq_eval (gee) FUNCTION TO EVALUATE THE FREQUENCY RESPONSE USING THE LAGRANGE INTERPOLATION FORMULA IN THE BARYCENTRIC FORM


source
DSP.Filters.lagrange_interpFunction
lagrange_interp(k::Integer, n::Integer, m::Integer, x::AbstractVector)

CALCULATE THE LAGRANGE INTERPOLATION COEFFICIENTS

source
DSP.Periodograms.coherence_from_cs!Function
coherence_from_cs!(output::AbstractArray, cs_matrix)

Compute the pairwise channel coherences from a cross spectral matrix, storing the result in output.

source
DSP.optimalfftfiltlengthFunction

Determine the length of FFT that minimizes the number of multiplications per output sample for an overlap-save convolution of vectors of size nb and nx.

source
diff --git a/dev/lpc/index.html b/dev/lpc/index.html index 494b3549..1f57e514 100644 --- a/dev/lpc/index.html +++ b/dev/lpc/index.html @@ -1,8 +1,8 @@ -LPC - Linear Predictive Coding · DSP.jl

LPC - Linear Predictive Coding

DSP.LPC.lpcFunction
lpc(x::AbstractVector, p::Integer, [LPCBurg()])

Given input signal x and prediction order p, returns IIR coefficients a and average reconstruction error prediction_err. Note that this method does NOT return the leading $1$ present in the true autocorrelative estimate; it omits it as it is implicit in every LPC estimate, and must be manually reintroduced if the returned vector should be treated as a polynomial.

The algorithm used is determined by the last optional parameter, and can be either LPCBurg (arburg) or LPCLevinson (levinson).

source
DSP.LPC.arburgFunction
arburg(x::AbstractVector, p::Integer)

LPC (Linear Predictive Coding) estimation, using the Burg method. This function implements the mathematics published in [Lagrange], and the recursion relation as noted in [Vos], in turn referenced from [Andersen].

source
DSP.LPC.levinsonFunction
levinson(x::AbstractVector, p::Integer)

Implements Levinson recursion, as described in [Levinson], to find the solution a of the linear equation

\[\mathbf{T} (-\vec{a}) +LPC - Linear Predictive Coding · DSP.jl

LPC - Linear Predictive Coding

DSP.LPC.lpcFunction
lpc(x::AbstractVector, p::Integer, [LPCBurg()])

Given input signal x and prediction order p, returns IIR coefficients a and average reconstruction error prediction_err. Note that this method does NOT return the leading $1$ present in the true autocorrelative estimate; it omits it as it is implicit in every LPC estimate, and must be manually reintroduced if the returned vector should be treated as a polynomial.

The algorithm used is determined by the last optional parameter, and can be either LPCBurg (arburg) or LPCLevinson (levinson).

source
DSP.LPC.arburgFunction
arburg(x::AbstractVector, p::Integer)

LPC (Linear Predictive Coding) estimation, using the Burg method. This function implements the mathematics published in [Lagrange], and the recursion relation as noted in [Vos], in turn referenced from [Andersen].

source
DSP.LPC.levinsonFunction
levinson(x::AbstractVector, p::Integer)

Implements Levinson recursion, as described in [Levinson], to find the solution a of the linear equation

\[\mathbf{T} (-\vec{a}) = \begin{bmatrix} x_2 \\ \vdots \\ x_{p+1} -\end{bmatrix}\]

in the case where $\mathbf{T}$ is Hermitian and Toeplitz, with first column x[1:p]. This function can be used for LPC (Linear Predictive Coding) estimation, by providing LPCLevinson() as an argument to lpc.

source
+\end{bmatrix}\]

in the case where $\mathbf{T}$ is Hermitian and Toeplitz, with first column x[1:p]. This function can be used for LPC (Linear Predictive Coding) estimation, by providing LPCLevinson() as an argument to lpc.

source
diff --git a/dev/periodograms/index.html b/dev/periodograms/index.html index e9bcbd01..5cd74136 100644 --- a/dev/periodograms/index.html +++ b/dev/periodograms/index.html @@ -29,7 +29,7 @@ 3-element Vector{Float64}: 3.0 4.0 - 5.0source
DSP.Periodograms.ArraySplitType
ArraySplit{T<:AbstractVector,S,W} <: AbstractVector{Vector{S}}

ArraySplit object with fields

  • s::T
  • buf::Vector{S}
  • n::Int
  • noverlap::Int
  • window::W
  • k::Int

where buf: buffer, k: number of split arrays, and s, n, noverlap, window are as per arguments in arraysplit.

source
DSP.Periodograms.periodogramFunction
periodogram(s::AbstractVector; onesided=eltype(s)<:Real, nfft=nextfastfft(length(s)), fs=1, window=nothing)

Computes periodogram of a 1-d signal s by FFT and returns a Periodogram object.

Arguments

  • onesided: For real signals, the two-sided periodogram is symmetric and this function returns a one-sided (real only) periodogram by default. A two-sided periodogram can be obtained by setting onesided=false.
  • nfft: Specifies the number of points to use for the Fourier transform. If length(s) < nfft, then the input is padded with zeros. By default, nfft is the closest size for which the Fourier transform can be computed with maximal efficiency.
  • fs: The sample rate of the original signal.
  • window: An optional window function or vector to be applied to the original signal before computing the Fourier transform. The computed periodogram is normalized so that the area under the periodogram is equal to the uncentered variance (or average power) of the original signal.

Returns

A Periodogram object with the 2 computed fields: power, freq.

Examples

Frequency estimate of cos(2π(25)t) with a 1-sided periodogram.

julia> Fs = 100;                     # Sampling frequency
+ 5.0
source
DSP.Periodograms.ArraySplitType
ArraySplit{T<:AbstractVector,S,W} <: AbstractVector{Vector{S}}

ArraySplit object with fields

  • s::T
  • buf::Vector{S}
  • n::Int
  • noverlap::Int
  • window::W
  • k::Int

where buf: buffer, k: number of split arrays, and s, n, noverlap, window are as per arguments in arraysplit.

source
DSP.Periodograms.periodogramFunction
periodogram(s::AbstractVector; onesided=eltype(s)<:Real, nfft=nextfastfft(length(s)), fs=1, window=nothing)

Computes periodogram of a 1-d signal s by FFT and returns a Periodogram object.

Arguments

  • onesided: For real signals, the two-sided periodogram is symmetric and this function returns a one-sided (real only) periodogram by default. A two-sided periodogram can be obtained by setting onesided=false.
  • nfft: Specifies the number of points to use for the Fourier transform. If length(s) < nfft, then the input is padded with zeros. By default, nfft is the closest size for which the Fourier transform can be computed with maximal efficiency.
  • fs: The sample rate of the original signal.
  • window: An optional window function or vector to be applied to the original signal before computing the Fourier transform. The computed periodogram is normalized so that the area under the periodogram is equal to the uncentered variance (or average power) of the original signal.

Returns

A Periodogram object with the 2 computed fields: power, freq.

Examples

Frequency estimate of cos(2π(25)t) with a 1-sided periodogram.

julia> Fs = 100;                     # Sampling frequency
 
 julia> t = (1:Fs)/Fs;                # 100 time samples
 
@@ -45,7 +45,7 @@
 julia> pxx = periodogram(x; onesided=false, nfft=512, fs=1000, window=hamming);
 
 julia> round(maximum(pxx.power), digits=4)  # Expect max power to be close to 0Hz for a DC signal
-0.0182
source
periodogram(s::AbstractMatrix; nfft::NTuple{2,Int}=nextfastfft(size(s)), fs=1, radialsum=false, radialavg=false)

Computes periodogram of a 2-d signal using the 2-d FFT and returns a Periodogram2 or Periodogram object.

Arguments

  • nfft: A 2-tuple specifying the number of points to use for the Fourier transform for each respective dimension. If size(s) < nfft, then the input is padded with zeros. By default, nfft is the closest size for which the Fourier transform can be computed with maximal efficiency.
  • fs: The sample rate of the original signal in both directions.
  • radialsum: For radialsum=true, the value of power[k] is proportional to $\frac{1}{N}\sum_{k\leq |k'|<k+1} |X[k']|^2$.
  • radialavg: For radialavg=true, the value of power[k] is proportional to $\frac{1}{N \#\{k\leq |k'|<k+1\}} \sum_{k\leq |k'|<k+1} |X[k']|^2$. The computation of |k'| takes into account non-square signals by scaling the coordinates of the wavevector accordingly.

Returns

  • A Periodogram2 object by default with the 3 computed fields: power, freq1, freq2.
  • A Periodogram object is returned for a radially summed or averaged periodogram (if radialsum or radialavg is true, respectively). Only one of radialsum or radialavg can be set to true in the function.

Examples

julia> x = [1 1; 0 1; 0 0];
+0.0182
source
periodogram(s::AbstractMatrix; nfft::NTuple{2,Int}=nextfastfft(size(s)), fs=1, radialsum=false, radialavg=false)

Computes periodogram of a 2-d signal using the 2-d FFT and returns a Periodogram2 or Periodogram object.

Arguments

  • nfft: A 2-tuple specifying the number of points to use for the Fourier transform for each respective dimension. If size(s) < nfft, then the input is padded with zeros. By default, nfft is the closest size for which the Fourier transform can be computed with maximal efficiency.
  • fs: The sample rate of the original signal in both directions.
  • radialsum: For radialsum=true, the value of power[k] is proportional to $\frac{1}{N}\sum_{k\leq |k'|<k+1} |X[k']|^2$.
  • radialavg: For radialavg=true, the value of power[k] is proportional to $\frac{1}{N \#\{k\leq |k'|<k+1\}} \sum_{k\leq |k'|<k+1} |X[k']|^2$. The computation of |k'| takes into account non-square signals by scaling the coordinates of the wavevector accordingly.

Returns

  • A Periodogram2 object by default with the 3 computed fields: power, freq1, freq2.
  • A Periodogram object is returned for a radially summed or averaged periodogram (if radialsum or radialavg is true, respectively). Only one of radialsum or radialavg can be set to true in the function.

Examples

julia> x = [1 1; 0 1; 0 0];
 
 julia> pxx = periodogram(x; nfft=(3, 2));   # Returns Periodogram2
 
@@ -62,7 +62,7 @@
 DSP.Periodograms.Periodogram{Float64, AbstractFFTs.Frequencies{Float64}, Vector{Float64}}([6.25, 4.75], [0.0, 0.5])
 
 julia> periodogram(x; radialavg=true)  # Returns Periodogram
-DSP.Periodograms.Periodogram{Float64, AbstractFFTs.Frequencies{Float64}, Vector{Float64}}([6.25, 1.5833333333333333], [0.0, 0.5])
source
DSP.Periodograms.PeriodogramType
Periodogram{T, F<:Union{Frequencies,AbstractRange}, V<:AbstractVector{T}} <: TFR{T}

A Periodogram object with fields:

  • power::V
  • freq::F.

See power and freq for further details.

source
DSP.Periodograms.Periodogram2Type
Periodogram2{T, F1<:Union{Frequencies,AbstractRange}, F2<:Union{Frequencies,AbstractRange}, M<:AbstractMatrix{T}} <: TFR{T}

A Periodogram2 object with fields:

  • power::M
  • freq1::F1
  • freq2::F2

See power and freq for further details.

source
DSP.Periodograms.welch_pgramFunction
welch_pgram(s::AbstractVector, n=div(length(s), 8), noverlap=div(n, 2); onesided=eltype(s)<:Real,
+DSP.Periodograms.Periodogram{Float64, AbstractFFTs.Frequencies{Float64}, Vector{Float64}}([6.25, 1.5833333333333333], [0.0, 0.5])
source
DSP.Periodograms.PeriodogramType
Periodogram{T, F<:Union{Frequencies,AbstractRange}, V<:AbstractVector{T}} <: TFR{T}

A Periodogram object with fields:

  • power::V
  • freq::F.

See power and freq for further details.

source
DSP.Periodograms.Periodogram2Type
Periodogram2{T, F1<:Union{Frequencies,AbstractRange}, F2<:Union{Frequencies,AbstractRange}, M<:AbstractMatrix{T}} <: TFR{T}

A Periodogram2 object with fields:

  • power::M
  • freq1::F1
  • freq2::F2

See power and freq for further details.

source
DSP.Periodograms.welch_pgramFunction
welch_pgram(s::AbstractVector, n=div(length(s), 8), noverlap=div(n, 2); onesided=eltype(s)<:Real,
             nfft=nextfastfft(n), fs=1, window)

Computes the Welch periodogram of a signal s based on segments with n samples with overlap of noverlap samples, and returns a Periodogram object.

welch_pgram by default divides s into 8 segments with 50% overlap between them. For a Bartlett periodogram, set noverlap=0.

See periodogram for description of optional keyword arguments.

Examples

julia> x = rect(10; padding=20);
 
 julia> power(welch_pgram(x; window=nothing))                    # 1-sided periodogram
@@ -94,11 +94,11 @@
 
 julia> x = sin.(2π*f.*t)*A + randn(1000); # Noise corrupted x signal
 
-julia> pxx = welch_pgram(x, 100; fs=Fs, nfft=512, window=hamming);
source
welch_pgram(s::AbstractVector, config::WelchConfig)

Computes the Welch periodogram of the given signal s using a predefined WelchConfig object.

Examples

julia> x = rect(10; padding=20);
+julia> pxx = welch_pgram(x, 100; fs=Fs, nfft=512, window=hamming);
source
welch_pgram(s::AbstractVector, config::WelchConfig)

Computes the Welch periodogram of the given signal s using a predefined WelchConfig object.

Examples

julia> x = rect(10; padding=20);
 
 julia> wconfig = WelchConfig(x; fs=1000, window=hamming);
 
-julia> welch_pgram(x, wconfig);
source
DSP.Periodograms.welch_pgram!Function
welch_pgram!(out::AbstractVector, s::AbstractVector, n=div(length(s), 8),
+julia> welch_pgram(x, wconfig);
source
DSP.Periodograms.welch_pgram!Function
welch_pgram!(out::AbstractVector, s::AbstractVector, n=div(length(s), 8),
              noverlap=div(n, 2); onesided=eltype(s)<:Real, nfft=nextfastfft(n),
              fs=1, window=nothing)

Computes the Welch periodogram of a signal s, based on segments with n samples with overlap of noverlap samples, and returns a Periodogram object. The Power Spectral Density (PSD) of Welch periodogram is stored in out.

welch_pgram! by default divides s into 8 segments with 50% overlap between them. For a Bartlett periodogram, set noverlap=0.

See periodogram for description of optional keyword arguments.

Examples

julia> Fs = 100;                     # Sampling frequency
 
@@ -113,7 +113,7 @@
 julia> pxx = welch_pgram!(y, x, 10; onesided=false, nfft=nfft, fs=Fs);
 
 julia> y == power(pxx)
-true
source
welch_pgram!(out::AbstractVector, s::AbstractVector, config::WelchConfig)

Computes the Welch periodogram of the given signal s, using a predefined WelchConfig object. The Power Spectral Density (PSD) of Welch periodogram is stored in out.

Examples

julia> Fs = 100;                     # Sampling frequency
+true
source
welch_pgram!(out::AbstractVector, s::AbstractVector, config::WelchConfig)

Computes the Welch periodogram of the given signal s, using a predefined WelchConfig object. The Power Spectral Density (PSD) of Welch periodogram is stored in out.

Examples

julia> Fs = 100;                     # Sampling frequency
 
 julia> t = (1:Fs)/Fs;                # 100 time samples
 
@@ -128,7 +128,7 @@
 julia> pxx = welch_pgram!(y, x, wconfig);
 
 julia> y == power(pxx)
-true
source
DSP.Periodograms.spectrogramFunction
spectrogram(s, n=div(length(s), 8), noverlap=div(n, 2); onesided=eltype(s)<:Real, nfft=nextfastfft(n), fs=1, window=nothing)

Computes the spectrogram of a signal s based on segments with n samples with overlap of noverlap samples, and returns a Spectrogram object.

spectrogram by default divides s into 8 segments with 50% overlap between them. See periodogram for description of optional keyword arguments.

The returned Spectrogram object stores the 3 computed fields: power, freq and time. See power, freq and time for further details.

Examples

julia> Fs = 1000;
+true
source
DSP.Periodograms.spectrogramFunction
spectrogram(s, n=div(length(s), 8), noverlap=div(n, 2); onesided=eltype(s)<:Real, nfft=nextfastfft(n), fs=1, window=nothing)

Computes the spectrogram of a signal s based on segments with n samples with overlap of noverlap samples, and returns a Spectrogram object.

spectrogram by default divides s into 8 segments with 50% overlap between them. See periodogram for description of optional keyword arguments.

The returned Spectrogram object stores the 3 computed fields: power, freq and time. See power, freq and time for further details.

Examples

julia> Fs = 1000;
 
 julia> t = 0:1/Fs:1-1/Fs;
 
@@ -143,7 +143,7 @@
 (63,)
 
 julia> time(spec)
-0.0625:0.063:0.8815
source
DSP.Periodograms.SpectrogramType
Spectrogram{T, F<:Union{Frequencies,AbstractRange}, M<:AbstractMatrix{T}} <: TFR{T}

A Spectrogram object with fields:

  • power::M
  • freq::F
  • time::Float64Range

See power, freq and time for further details.

source
DSP.Periodograms.stftFunction
stft(s, n=div(length(s), 8), noverlap=div(n, 2); onesided=eltype(s)<:Real, nfft=nextfastfft(n), fs=1, window=nothing)

Computes the Short Time Fourier Transform (STFT) of a signal s based on segments with n samples with overlap of noverlap samples, and returns a matrix containing the STFT coefficients.

stft by default divides s into 8 segments with 50% overlap between them. See periodogram for description of optional keyword arguments.

The STFT computes the DFT over K sliding windows (segments) of the signal s. This returns a J x K matrix where J is the number of DFT coefficients and K the number of windowed segments. The kth column of the returned matrix contains the DFT coefficients for the kth segment.

Examples

julia> Fs = 1000;
+0.0625:0.063:0.8815
source
DSP.Periodograms.SpectrogramType
Spectrogram{T, F<:Union{Frequencies,AbstractRange}, M<:AbstractMatrix{T}} <: TFR{T}

A Spectrogram object with fields:

  • power::M
  • freq::F
  • time::Float64Range

See power, freq and time for further details.

source
DSP.Periodograms.stftFunction
stft(s, n=div(length(s), 8), noverlap=div(n, 2); onesided=eltype(s)<:Real, nfft=nextfastfft(n), fs=1, window=nothing)

Computes the Short Time Fourier Transform (STFT) of a signal s based on segments with n samples with overlap of noverlap samples, and returns a matrix containing the STFT coefficients.

stft by default divides s into 8 segments with 50% overlap between them. See periodogram for description of optional keyword arguments.

The STFT computes the DFT over K sliding windows (segments) of the signal s. This returns a J x K matrix where J is the number of DFT coefficients and K the number of windowed segments. The kth column of the returned matrix contains the DFT coefficients for the kth segment.

Examples

julia> Fs = 1000;
 
 julia> t = 0:1/Fs:5-1/Fs;
 
@@ -153,28 +153,28 @@
 (313, 14)
 
 julia> size(stft(x, 500, 250; onesided=false, window=hanning))
-(500, 19)
source
DSP.Periodograms.freqFunction
freq(p)

Returns the frequency bin centers for a given Periodogram, Spectrogram, CrossPowerSpectra, or Coherence object.

Returns a tuple of frequency bin centers for a given Periodogram2 object.

Examples

julia> freq(periodogram([1, 2, 3]; fs=210))
+(500, 19)
source
DSP.Periodograms.freqFunction
freq(p)

Returns the frequency bin centers for a given Periodogram, Spectrogram, CrossPowerSpectra, or Coherence object.

Returns a tuple of frequency bin centers for a given Periodogram2 object.

Examples

julia> freq(periodogram([1, 2, 3]; fs=210))
 2-element AbstractFFTs.Frequencies{Float64}:
   0.0
- 70.0
source
DSP.Periodograms.powerFunction
power(p)

For a Periodogram, returns the computed power spectral density (PSD) as a Vector.

For a Spectrogram, returns the computed power spectral density (PSD) at each frequency and time bin as a Matrix. Dimensions are frequency × time.

For a CrossPowerSpectra, returns the pairwise cross power spectral density (CPSD) between each pair of channels at each frequency. Dimensions are channel x channel x frequency.

Examples

julia> power(periodogram([1, 2, 3]; fs=210))
+ 70.0
source
DSP.Periodograms.powerFunction
power(p)

For a Periodogram, returns the computed power spectral density (PSD) as a Vector.

For a Spectrogram, returns the computed power spectral density (PSD) at each frequency and time bin as a Matrix. Dimensions are frequency × time.

For a CrossPowerSpectra, returns the pairwise cross power spectral density (CPSD) between each pair of channels at each frequency. Dimensions are channel x channel x frequency.

Examples

julia> power(periodogram([1, 2, 3]; fs=210))
 2-element Vector{Float64}:
  0.05714285714285714
- 0.009523809523809525
source
Base.Libc.timeFunction
time(p)

Returns the time bin centers for a given Spectrogram object.

Examples

julia> time(spectrogram(0:1/20:1; fs=8000))
-0.000125:0.000125:0.0025
source
DSP.Periodograms.coherenceFunction
coherence(c::Coherence)

Given an Coherence object, returns an n_channels x n_channels x length(freq(c)) array consisting of the pairwise coherences between each channel for each frequency.

source
DSP.Periodograms.CoherenceType
Coherence{T, F, A<:AbstractArray{T, 3}}

Holds an n_channels x n_channels x length(freq) array consisting of the pairwise coherences between each channel for each frequency which is accessed by coherence, as well as the frequencies accessed by freq.

See also mt_coherence and mt_coherence!.

source

Multitaper periodogram estimation

DSP.Periodograms.mt_pgramFunction
mt_pgram(s; onesided=eltype(s)<:Real, nfft=nextfastfft(n), fs=1, nw=4, ntapers=iceil(2nw)-1, window=dpss(length(s), nw, ntapers))
-mt_pgram(signal::AbstractVector, config::MTConfig)

Computes the multitaper periodogram of a signal s.

If window is not specified, the signal is tapered with ntapers discrete prolate spheroidal sequences with time-bandwidth product nw. Each sequence is equally weighted; adaptive multitaper is not (yet) supported.

If window is specified, each column is applied as a taper. The sum of periodograms is normalized by the total sum of squares of window.

Returns a Periodogram.

See also mt_pgram! and MTConfig.

source
DSP.Periodograms.mt_pgram!Function
mt_pgram!(output, s::AbstractVector{T}; onesided::Bool=eltype(s)<:Real,
+ 0.009523809523809525
source
Base.Libc.timeFunction
time(p)

Returns the time bin centers for a given Spectrogram object.

Examples

julia> time(spectrogram(0:1/20:1; fs=8000))
+0.000125:0.000125:0.0025
source
DSP.Periodograms.coherenceFunction
coherence(c::Coherence)

Given an Coherence object, returns an n_channels x n_channels x length(freq(c)) array consisting of the pairwise coherences between each channel for each frequency.

source
DSP.Periodograms.CoherenceType
Coherence{T, F, A<:AbstractArray{T, 3}}

Holds an n_channels x n_channels x length(freq) array consisting of the pairwise coherences between each channel for each frequency which is accessed by coherence, as well as the frequencies accessed by freq.

See also mt_coherence and mt_coherence!.

source

Multitaper periodogram estimation

DSP.Periodograms.mt_pgramFunction
mt_pgram(s; onesided=eltype(s)<:Real, nfft=nextfastfft(n), fs=1, nw=4, ntapers=iceil(2nw)-1, window=dpss(length(s), nw, ntapers))
+mt_pgram(signal::AbstractVector, config::MTConfig)

Computes the multitaper periodogram of a signal s.

If window is not specified, the signal is tapered with ntapers discrete prolate spheroidal sequences with time-bandwidth product nw. Each sequence is equally weighted; adaptive multitaper is not (yet) supported.

If window is specified, each column is applied as a taper. The sum of periodograms is normalized by the total sum of squares of window.

Returns a Periodogram.

See also mt_pgram! and MTConfig.

source
DSP.Periodograms.mt_pgram!Function
mt_pgram!(output, s::AbstractVector{T}; onesided::Bool=eltype(s)<:Real,
     nfft::Int=nextfastfft(length(s)), fs::Real=1,
     nw::Real=4, ntapers::Int=ceil(Int, 2nw)-1,
     window::Union{AbstractMatrix,Nothing}=nothing) where T<:Number
-mt_pgram!(output::AbstractVector, signal::AbstractVector, config::MTConfig) -> Periodogram

Computes a multitapered periodogram, storing the output in output. Arguments:

  • signal::AbstractVector: should be of length config.n_samples
  • output::AbstractVector: should be of length length(config.freq)

Optionally pass an MTConfig object to preallocate temporary variables and choose configuration settings; otherwise, keyword arguments may be passed to choose those settings.

Returns a Periodogram.

See also mt_pgram and MTConfig.

source
DSP.Periodograms.mt_spectrogramFunction
mt_spectrogram(signal::AbstractVector{T}, n::Int=length(s) >> 3,
+mt_pgram!(output::AbstractVector, signal::AbstractVector, config::MTConfig) -> Periodogram

Computes a multitapered periodogram, storing the output in output. Arguments:

  • signal::AbstractVector: should be of length config.n_samples
  • output::AbstractVector: should be of length length(config.freq)

Optionally pass an MTConfig object to preallocate temporary variables and choose configuration settings; otherwise, keyword arguments may be passed to choose those settings.

Returns a Periodogram.

See also mt_pgram and MTConfig.

source
DSP.Periodograms.mt_spectrogramFunction
mt_spectrogram(signal::AbstractVector{T}, n::Int=length(s) >> 3,
                               n_overlap::Int=n >> 1; fs=1,
                               onesided::Bool=T <: Real, kwargs...) where {T}
-mt_spectrogram(signal::AbstractVector, config::MTSpectrogramConfig)

Compute a multitaper spectrogram, returning a Spectrogram object. Optionally pass a MTSpectrogramConfig object; otherwise, any additional keyword arguments accepted by MTConfig may be passed to configure the tapering.

Returns a Spectrogram.

See also mt_spectrogram!.

source
DSP.Periodograms.mt_spectrogram!Function
mt_spectrogram!(output, signal::AbstractVector{T}, n::Int=length(signal) >> 3,
+mt_spectrogram(signal::AbstractVector, config::MTSpectrogramConfig)

Compute a multitaper spectrogram, returning a Spectrogram object. Optionally pass a MTSpectrogramConfig object; otherwise, any additional keyword arguments accepted by MTConfig may be passed to configure the tapering.

Returns a Spectrogram.

See also mt_spectrogram!.

source
DSP.Periodograms.mt_spectrogram!Function
mt_spectrogram!(output, signal::AbstractVector{T}, n::Int=length(signal) >> 3,
     n_overlap::Int=n >> 1; fs=1, onesided::Bool=T <: Real, kwargs...) where {T}
-mt_spectrogram!(destination::AbstractMatrix, signal::AbstractVector, config::MTSpectrogramConfig)

Computes a multitaper spectrogram using the parameters specified in config. Arguments:

  • destination: length(config.mt_config.freq) x length(config.time) matrix. This can be created by DSP.allocate_output(config).
  • signal: vector of length config.n_samples
  • config: optionally, pass an MTSpectrogramConfig object to hold temporary variables and configuration settings. Otherwise, settings arguments may be passed directly.

Returns a Spectrogram.

See also mt_spectrogram.

source
DSP.Periodograms.mt_cross_power_spectraFunction
mt_cross_power_spectra(signal::AbstractMatrix{T}; fs=1, kwargs...) where {T}
-mt_cross_power_spectra(signal::AbstractMatrix, config::MTCrossSpectraConfig)

Computes multitapered cross power spectra between channels of a signal. Arguments:

  • signal: n_channels x n_samples
  • Optionally pass an MTCrossSpectraConfig object to preallocate temporary variables

and choose configuration settings. Otherwise, any keyword arguments accepted by MTCrossSpectraConfig may be passed here.

Produces a CrossPowerSpectra object holding the n_channels x n_channels x n_frequencies output array (accessed by power) and the corresponding frequencies (accessed by freq).

See also mt_cross_power_spectra! and MTCrossSpectraConfig.

source
DSP.Periodograms.mt_cross_power_spectra!Function
mt_cross_power_spectra!(output, signal::AbstractMatrix; fs=1, kwargs...)
-mt_cross_power_spectra!(output, signal::AbstractMatrix, config::MTCrossSpectraConfig)

Computes multitapered cross power spectra between channels of a signal. Arguments:

  • output: n_channels x n_channels x length(config.freq). Can be created by DSP.allocate_output(config).
  • signal: n_channels x n_samples
  • config: MTCrossSpectraConfig{T}: optionally pass a MTCrossSpectraConfig to preallocate temporary and choose configuration settings. Otherwise, one may pass any keyword arguments accepted by this object.

Produces a CrossPowerSpectra object holding the n_channels x n_channels x n_frequencies output array and the corresponding frequencies (accessed by freq).

See also mt_cross_power_spectra and MTCrossSpectraConfig.

source
DSP.Periodograms.CrossPowerSpectraType
CrossPowerSpectra{T,F,A<:AbstractArray{T, 3}}

Access the cross power spectral density (an n_channels x n_channels x length(freq) array) via the function power, and the frequencies by the function freq.

See also mt_cross_power_spectra and mt_cross_power_spectra!.

source
DSP.Periodograms.mt_coherenceFunction
mt_coherence(signal::AbstractMatrix{T}; fs=1, freq_range = nothing, demean=false, kwargs...) where T
-mt_coherence(signal::AbstractMatrix, config::MTCoherenceConfig)

Arguments:

  • signal: n_channels x n_samples matrix
  • Optionally pass an MTCoherenceConfig to pre-allocate temporary variables and choose configuration settings, otherwise, see MTCrossSpectraConfig for the meaning of the keyword arguments.

Returns a Coherence object.

See also mt_coherence and MTCoherenceConfig.

source
DSP.Periodograms.mt_coherence!Function
mt_coherence!(output, signal::AbstractMatrix; fs=1, freq_range=nothing, demean=false, kwargs...)
-mt_coherence!(output, signal::AbstractMatrix, config::MTCoherenceConfig)

Computes the pairwise coherences between channels.

  • output: n_channels x n_channels matrix
  • signal: n_samples x n_channels matrix
  • config: optional configuration object that pre-allocates temporary variables and choose settings.

Returns a Coherence object.

See also mt_coherence and MTCoherenceConfig.

source

Configuration objects

DSP.Periodograms.WelchConfigType
WelchConfig(s::AbstractArray; n=size(s, ndims(s))>>3, noverlap=n>>1,
+mt_spectrogram!(destination::AbstractMatrix, signal::AbstractVector, config::MTSpectrogramConfig)

Computes a multitaper spectrogram using the parameters specified in config. Arguments:

  • destination: length(config.mt_config.freq) x length(config.time) matrix. This can be created by DSP.allocate_output(config).
  • signal: vector of length config.n_samples
  • config: optionally, pass an MTSpectrogramConfig object to hold temporary variables and configuration settings. Otherwise, settings arguments may be passed directly.

Returns a Spectrogram.

See also mt_spectrogram.

source
DSP.Periodograms.mt_cross_power_spectraFunction
mt_cross_power_spectra(signal::AbstractMatrix{T}; fs=1, kwargs...) where {T}
+mt_cross_power_spectra(signal::AbstractMatrix, config::MTCrossSpectraConfig)

Computes multitapered cross power spectra between channels of a signal. Arguments:

  • signal: n_channels x n_samples
  • Optionally pass an MTCrossSpectraConfig object to preallocate temporary variables

and choose configuration settings. Otherwise, any keyword arguments accepted by MTCrossSpectraConfig may be passed here.

Produces a CrossPowerSpectra object holding the n_channels x n_channels x n_frequencies output array (accessed by power) and the corresponding frequencies (accessed by freq).

See also mt_cross_power_spectra! and MTCrossSpectraConfig.

source
DSP.Periodograms.mt_cross_power_spectra!Function
mt_cross_power_spectra!(output, signal::AbstractMatrix; fs=1, kwargs...)
+mt_cross_power_spectra!(output, signal::AbstractMatrix, config::MTCrossSpectraConfig)

Computes multitapered cross power spectra between channels of a signal. Arguments:

  • output: n_channels x n_channels x length(config.freq). Can be created by DSP.allocate_output(config).
  • signal: n_channels x n_samples
  • config: MTCrossSpectraConfig{T}: optionally pass a MTCrossSpectraConfig to preallocate temporary and choose configuration settings. Otherwise, one may pass any keyword arguments accepted by this object.

Produces a CrossPowerSpectra object holding the n_channels x n_channels x n_frequencies output array and the corresponding frequencies (accessed by freq).

See also mt_cross_power_spectra and MTCrossSpectraConfig.

source
DSP.Periodograms.CrossPowerSpectraType
CrossPowerSpectra{T,F,A<:AbstractArray{T, 3}}

Access the cross power spectral density (an n_channels x n_channels x length(freq) array) via the function power, and the frequencies by the function freq.

See also mt_cross_power_spectra and mt_cross_power_spectra!.

source
DSP.Periodograms.mt_coherenceFunction
mt_coherence(signal::AbstractMatrix{T}; fs=1, freq_range = nothing, demean=false, kwargs...) where T
+mt_coherence(signal::AbstractMatrix, config::MTCoherenceConfig)

Arguments:

  • signal: n_channels x n_samples matrix
  • Optionally pass an MTCoherenceConfig to pre-allocate temporary variables and choose configuration settings, otherwise, see MTCrossSpectraConfig for the meaning of the keyword arguments.

Returns a Coherence object.

See also mt_coherence and MTCoherenceConfig.

source
DSP.Periodograms.mt_coherence!Function
mt_coherence!(output, signal::AbstractMatrix; fs=1, freq_range=nothing, demean=false, kwargs...)
+mt_coherence!(output, signal::AbstractMatrix, config::MTCoherenceConfig)

Computes the pairwise coherences between channels.

  • output: n_channels x n_channels matrix
  • signal: n_samples x n_channels matrix
  • config: optional configuration object that pre-allocates temporary variables and choose settings.

Returns a Coherence object.

See also mt_coherence and MTCoherenceConfig.

source

Configuration objects

DSP.Periodograms.WelchConfigType
WelchConfig(s::AbstractArray; n=size(s, ndims(s))>>3, noverlap=n>>1,
          onesided=eltype(s)<:Real, nfft=nextfastfft(n),
          fs=1, window)
 
@@ -184,18 +184,18 @@
 
 julia> wconfig1 = WelchConfig(x; n=length(x), noverlap=0, window=hanning, nfft=16);
 
-julia> wconfig2 = WelchConfig(8, Float64; n=length(x), noverlap=0, window=hanning, nfft=16);
source
DSP.Periodograms.MTConfigType
MTConfig{T}(n_samples; fs=1,
+julia> wconfig2 = WelchConfig(8, Float64; n=length(x), noverlap=0, window=hanning, nfft=16);
source
DSP.Periodograms.MTConfigType
MTConfig{T}(n_samples; fs=1,
         nfft = nextpow(2, n_samples),
         window = nothing,
         nw = 4,
         ntapers = 2 * nw - 1,
         taper_weights = fill(1/ntapers, ntapers),
         onesided::Bool=T<:Real,
-        fft_flags = FFTW.MEASURE)

Creates a config object which holds the configuration state and temporary variables used in multitaper computations, e.g. mt_pgram!, mt_spectrogram, MTSpectrogramConfig, MTCrossSpectraConfig, and MTCoherenceConfig.

An MTConfig can be re-used between computations as long as none of the input arguments change.

  • n_samples: the number of samples to be used as input when computing multitaper periodograms with this configuration. Used for pre-allocating temporary buffers.
  • fs: the number of samples per second of the input signal
  • nfft: length of input vector to the FFT; if nfft > n_samples, then the input signal will be zero-padded until it is of length nfft.
  • window: window function to use for tapering. If left at the default of nothing, window will be set to dpss(n_samples, nw, ntapers).
  • ntapers: the number of tapers to use.
  • taper_weights = fill(1/ntapers, ntapers): how to weight the contribution of each taper. The default setting is to simply average them.
  • onesided: whether or not to compute a "one-sided" FFT by using that real signal data yields conjugate-symmetry in Fourier space.
  • fft_flags: flags to control how the FFT plan is generated.
source
DSP.Periodograms.MTSpectrogramConfigType
MTSpectrogramConfig(n_samples, mt_config::MTConfig{T}, n_overlap_samples) where {T}
-MTSpectrogramConfig{T}(n_samples, samples_per_window, n_overlap_samples; fs=1, kwargs...) where {T}

Creates a MTSpectrogramConfig which holds configuration and temporary variables for mt_spectrogram and mt_spectrogram!. Any keyword arguments accepted by MTConfig may be passed here, or an MTConfig object itself.

source
DSP.Periodograms.MTCrossSpectraConfigType
MTCrossSpectraConfig{T}(n_channels, n_samples; fs=1, demean=false, freq_range=nothing,
+        fft_flags = FFTW.MEASURE)

Creates a config object which holds the configuration state and temporary variables used in multitaper computations, e.g. mt_pgram!, mt_spectrogram, MTSpectrogramConfig, MTCrossSpectraConfig, and MTCoherenceConfig.

An MTConfig can be re-used between computations as long as none of the input arguments change.

  • n_samples: the number of samples to be used as input when computing multitaper periodograms with this configuration. Used for pre-allocating temporary buffers.
  • fs: the number of samples per second of the input signal
  • nfft: length of input vector to the FFT; if nfft > n_samples, then the input signal will be zero-padded until it is of length nfft.
  • window: window function to use for tapering. If left at the default of nothing, window will be set to dpss(n_samples, nw, ntapers).
  • ntapers: the number of tapers to use.
  • taper_weights = fill(1/ntapers, ntapers): how to weight the contribution of each taper. The default setting is to simply average them.
  • onesided: whether or not to compute a "one-sided" FFT by using that real signal data yields conjugate-symmetry in Fourier space.
  • fft_flags: flags to control how the FFT plan is generated.
source
DSP.Periodograms.MTSpectrogramConfigType
MTSpectrogramConfig(n_samples, mt_config::MTConfig{T}, n_overlap_samples) where {T}
+MTSpectrogramConfig{T}(n_samples, samples_per_window, n_overlap_samples; fs=1, kwargs...) where {T}

Creates a MTSpectrogramConfig which holds configuration and temporary variables for mt_spectrogram and mt_spectrogram!. Any keyword arguments accepted by MTConfig may be passed here, or an MTConfig object itself.

source
DSP.Periodograms.MTCrossSpectraConfigType
MTCrossSpectraConfig{T}(n_channels, n_samples; fs=1, demean=false, freq_range=nothing,
                         ensure_aligned = T == Float32 || T == Complex{Float32}, kwargs...) where {T}
 MTCrossSpectraConfig(n_channels, mt_config::MTConfig{T}; demean=false, freq_range=nothing,
-                     ensure_aligned = T == Float32 || T == Complex{Float32})

Creates a configuration object used for mt_cross_power_spectra and mt_cross_power_spectra!.

  • n_channels: the number of channels of the input.
  • n_samples: the number of samples for each channel of the input.
  • demean: if true, the channelwise mean will be subtracted from the input signals before the cross spectral powers are computed.
  • freq_range: if nothing, all frequencies are retained. Otherwise, only frequencies between first(freq_range) and last(freq_range) are retained.
  • ensure_aligned = T == Float32 || T == Complex{Float32}: perform an extra copy to ensure that the FFT output is memory-aligned
  • Additionally, either pass an MTConfig object, or keyword arguments such as fs accepted by MTConfig.

Returns a CrossPowerSpectra object.

source
DSP.Periodograms.MTCoherenceConfigType
MTCoherenceConfig{T}(n_channels, n_samples; fs=1, demean=false, freq_range=nothing, kwargs...) where T
+                     ensure_aligned = T == Float32 || T == Complex{Float32})

Creates a configuration object used for mt_cross_power_spectra and mt_cross_power_spectra!.

  • n_channels: the number of channels of the input.
  • n_samples: the number of samples for each channel of the input.
  • demean: if true, the channelwise mean will be subtracted from the input signals before the cross spectral powers are computed.
  • freq_range: if nothing, all frequencies are retained. Otherwise, only frequencies between first(freq_range) and last(freq_range) are retained.
  • ensure_aligned = T == Float32 || T == Complex{Float32}: perform an extra copy to ensure that the FFT output is memory-aligned
  • Additionally, either pass an MTConfig object, or keyword arguments such as fs accepted by MTConfig.

Returns a CrossPowerSpectra object.

source
DSP.Periodograms.MTCoherenceConfigType
MTCoherenceConfig{T}(n_channels, n_samples; fs=1, demean=false, freq_range=nothing, kwargs...) where T
 MTCoherenceConfig(cs_config::MTCrossSpectraConfig{T}) where {T}
 MTCoherenceConfig(n_channels, mt_config::MTConfig{T}; demean=false, freq_range=nothing,
-    ensure_aligned = T == Float32 || T == Complex{Float32}) where {T}

Creates a configuration object for coherences from a MTCrossSpectraConfig. Provides a helper method with the same arugments as MTCrossSpectraConfig to construct the MTCrossSpectraConfig object.

See also mt_coherence and mt_coherence!.

source
+ ensure_aligned = T == Float32 || T == Complex{Float32}) where {T}

Creates a configuration object for coherences from a MTCrossSpectraConfig. Provides a helper method with the same arugments as MTCrossSpectraConfig to construct the MTCrossSpectraConfig object.

See also mt_coherence and mt_coherence!.

source diff --git a/dev/util/index.html b/dev/util/index.html index 435b6221..c064657b 100644 --- a/dev/util/index.html +++ b/dev/util/index.html @@ -1,15 +1,15 @@ -Util - utility functions · DSP.jl

Util - utility functions

Note

As of version 0.6.1 of DSP.jl, fftfreq and rfftfreq have been moved from DSP.jl to AbstractFFTs.jl version 0.5 and above. You can also access these functions through FFTW.jl version 1.1 and above.

DSP.Unwrap.unwrapFunction
unwrap(m; kwargs...)

Assumes m to be a sequence of values that has been wrapped to be inside the given range (centered around zero), and undoes the wrapping by identifying discontinuities. If a single dimension is passed to dims, then m is assumed to have wrapping discontinuities only along that dimension. If a range of dimensions, as in 1:ndims(m), is passed to dims, then m is assumed to have wrapping discontinuities across all ndims(m) dimensions.

A common usage for unwrapping across a singleton dimension is for a phase measurement over time, such as when comparing successive frames of a short-time-fourier-transform, as each frame is wrapped to stay within (-pi, pi].

A common usage for unwrapping across multiple dimensions is for a phase measurement of a scene, such as when retrieving the phase information of of an image, as each pixel is wrapped to stay within (-pi, pi].

Arguments

  • m::AbstractArray{T, N}: Array to unwrap.
  • dims=nothing: Dimensions along which to unwrap. If dims is an integer, then unwrap is called on that dimension. If dims=1:ndims(m), then m is unwrapped across all dimensions.
  • range=2pi: Range of wrapped array.
  • circular_dims=(false, ...): When an element of this tuple is true, the unwrapping process will consider the edges along the corresponding axis of the array to be connected.
  • rng=default_rng(): Unwrapping of arrays with dimension > 1 uses a random initialization. A user can pass their own RNG through this argument.
source
DSP.Util.hilbertFunction
hilbert(x)

Computes the analytic representation of x, $x_a = x + j \hat{x}$, where $\hat{x}$ is the Hilbert transform of x, along the first dimension of x.

source
DSP.Util.nextfastfftFunction
nextfastfft(n::Integer)
-nextfastfft(ns::Tuple)

Return an estimate for the padded size of an array that is optimal for the performance of an n-dimensional FFT.

For Tuple inputs, this returns a Tuple that is the size of the padded array.

For Integer inputs, this returns the closest product of 2, 3, 5, and 7 greater than or equal to n. FFTW contains optimized kernels for these sizes and computes Fourier transforms of inputs that are a product of these sizes faster than for inputs of other sizes.

Warning

Currently, nextfastfft(ns::Tuple) is implemented as nextfastfft.(ns). This may change in future releases if a better estimation model is found.

It is recommended to use nextfastfft.(ns) to obtain a tuple of padded lengths for 1D FFTs.

source
DSP.Util.pow2dbFunction
pow2db(a)

Convert a power ratio to dB (decibel), or $10\log_{10}(a)$. The inverse of db2pow.

source
DSP.Util.amp2dbFunction
amp2db(a)

Convert an amplitude ratio to dB (decibel), or $20 \log_{10}(a)=10\log_{10}(a^2)$. The inverse of db2amp.

source
DSP.Util.db2powFunction
db2pow(a)

Convert dB to a power ratio. This function call also be called using a*dB, i.e. 3dB == db2pow(3). The inverse of pow2db.

source
DSP.Util.db2ampFunction
db2amp(a)

Convert dB to an amplitude ratio. This function call also be called using a*dBa, i.e. 3dBa == db2amp(3). The inverse of amp2db.

source
DSP.Util.rmsFunction
rms(s; dims)

Return the root mean square (rms) of signal s. Optional keyword parameter dims can be used to specify the dimensions along which to compue the rms.

source
DSP.Util.rmsfftFunction
rmsfft(f)

Return the root mean square of signal s given the FFT transform f = fft(s). Equivalent to rms(ifft(f)).

source
DSP.Util.meanfreqFunction
meanfreq(x, fs)

Calculate the mean power frequency of x with a sampling frequency of fs, defined as:

\[MPF = \frac{\sum_{i=1}^{F} f_i X_i^2 }{\sum_{i=0}^{F} X_i^2 } Hz\]

where $F$ is the Nyquist frequency, and $X$ is the power spectral density.

source
DSP.Util.finddelayFunction
finddelay(x, y)

Estimate the delay of x with respect to y by locating the peak of their cross-correlation.

The output delay will be positive when x is delayed with respect y, negative if advanced, 0 otherwise.

Example

julia> finddelay([0, 0, 1, 2, 3], [1, 2, 3])
+Util - utility functions · DSP.jl

Util - utility functions

Note

As of version 0.6.1 of DSP.jl, fftfreq and rfftfreq have been moved from DSP.jl to AbstractFFTs.jl version 0.5 and above. You can also access these functions through FFTW.jl version 1.1 and above.

DSP.Unwrap.unwrapFunction
unwrap(m; kwargs...)

Assumes m to be a sequence of values that has been wrapped to be inside the given range (centered around zero), and undoes the wrapping by identifying discontinuities. If a single dimension is passed to dims, then m is assumed to have wrapping discontinuities only along that dimension. If a range of dimensions, as in 1:ndims(m), is passed to dims, then m is assumed to have wrapping discontinuities across all ndims(m) dimensions.

A common usage for unwrapping across a singleton dimension is for a phase measurement over time, such as when comparing successive frames of a short-time-fourier-transform, as each frame is wrapped to stay within (-pi, pi].

A common usage for unwrapping across multiple dimensions is for a phase measurement of a scene, such as when retrieving the phase information of of an image, as each pixel is wrapped to stay within (-pi, pi].

Arguments

  • m::AbstractArray{T, N}: Array to unwrap.
  • dims=nothing: Dimensions along which to unwrap. If dims is an integer, then unwrap is called on that dimension. If dims=1:ndims(m), then m is unwrapped across all dimensions.
  • range=2pi: Range of wrapped array.
  • circular_dims=(false, ...): When an element of this tuple is true, the unwrapping process will consider the edges along the corresponding axis of the array to be connected.
  • rng=default_rng(): Unwrapping of arrays with dimension > 1 uses a random initialization. A user can pass their own RNG through this argument.
source
DSP.Util.hilbertFunction
hilbert(x)

Computes the analytic representation of x, $x_a = x + j \hat{x}$, where $\hat{x}$ is the Hilbert transform of x, along the first dimension of x.

source
DSP.Util.nextfastfftFunction
nextfastfft(n::Integer)
+nextfastfft(ns::Tuple)

Return an estimate for the padded size of an array that is optimal for the performance of an n-dimensional FFT.

For Tuple inputs, this returns a Tuple that is the size of the padded array.

For Integer inputs, this returns the closest product of 2, 3, 5, and 7 greater than or equal to n. FFTW contains optimized kernels for these sizes and computes Fourier transforms of inputs that are a product of these sizes faster than for inputs of other sizes.

Warning

Currently, nextfastfft(ns::Tuple) is implemented as nextfastfft.(ns). This may change in future releases if a better estimation model is found.

It is recommended to use nextfastfft.(ns) to obtain a tuple of padded lengths for 1D FFTs.

source
DSP.Util.pow2dbFunction
pow2db(a)

Convert a power ratio to dB (decibel), or $10\log_{10}(a)$. The inverse of db2pow.

source
DSP.Util.amp2dbFunction
amp2db(a)

Convert an amplitude ratio to dB (decibel), or $20 \log_{10}(a)=10\log_{10}(a^2)$. The inverse of db2amp.

source
DSP.Util.db2powFunction
db2pow(a)

Convert dB to a power ratio. This function call also be called using a*dB, i.e. 3dB == db2pow(3). The inverse of pow2db.

source
DSP.Util.db2ampFunction
db2amp(a)

Convert dB to an amplitude ratio. This function call also be called using a*dBa, i.e. 3dBa == db2amp(3). The inverse of amp2db.

source
DSP.Util.rmsFunction
rms(s; dims)

Return the root mean square (rms) of signal s. Optional keyword parameter dims can be used to specify the dimensions along which to compue the rms.

source
DSP.Util.rmsfftFunction
rmsfft(f)

Return the root mean square of signal s given the FFT transform f = fft(s). Equivalent to rms(ifft(f)).

source
DSP.Util.meanfreqFunction
meanfreq(x, fs)

Calculate the mean power frequency of x with a sampling frequency of fs, defined as:

\[MPF = \frac{\sum_{i=1}^{F} f_i X_i^2 }{\sum_{i=0}^{F} X_i^2 } Hz\]

where $F$ is the Nyquist frequency, and $X$ is the power spectral density.

source
DSP.Util.finddelayFunction
finddelay(x, y)

Estimate the delay of x with respect to y by locating the peak of their cross-correlation.

The output delay will be positive when x is delayed with respect y, negative if advanced, 0 otherwise.

Example

julia> finddelay([0, 0, 1, 2, 3], [1, 2, 3])
 2
 
 julia> finddelay([1, 2, 3], [0, 0, 1, 2, 3])
--2
source
DSP.Util.shiftin!Function
shiftin!(a::AbstractVector{T}, b::AbstractVector{T}) where T

Shifts b into the end of a.

julia> shiftin!([1,2,3,4], [5, 6])
+-2
source
DSP.Util.shiftin!Function
shiftin!(a::AbstractVector{T}, b::AbstractVector{T}) where T

Shifts b into the end of a.

julia> shiftin!([1,2,3,4], [5, 6])
 4-element Vector{Int64}:
  3
  4
  5
- 6
source
DSP.Util.shiftsignalFunction
shiftsignal(x, s)

Shift elements of signal x in time by a given amount s of samples and fill the spaces with zeros. For circular shifting, use circshift.

Example

julia> shiftsignal([1, 2, 3], 2)
+ 6
source
DSP.Util.shiftsignalFunction
shiftsignal(x, s)

Shift elements of signal x in time by a given amount s of samples and fill the spaces with zeros. For circular shifting, use circshift.

Example

julia> shiftsignal([1, 2, 3], 2)
 3-element Vector{Int64}:
  0
  0
@@ -19,13 +19,13 @@
 3-element Vector{Int64}:
  3
  0
- 0

See also shiftsignal!.

source
DSP.Util.alignsignalsFunction
alignsignals(x, y)

Use finddelay() and shiftsignal() to time align x to y. Also return the delay of x with respect to y.

Example

julia> alignsignals([0, 0, 1, 2, 3], [1, 2, 3])
+ 0

See also shiftsignal!.

source
DSP.Util.alignsignalsFunction
alignsignals(x, y)

Use finddelay() and shiftsignal() to time align x to y. Also return the delay of x with respect to y.

Example

julia> alignsignals([0, 0, 1, 2, 3], [1, 2, 3])
 ([1, 2, 3, 0, 0], 2)
 
 julia> alignsignals([1, 2, 3], [0, 0, 1, 2, 3])
-([0, 0, 1], -2)

See also alignsignals!.

source
DSP.diricFunction
kernel = diric(Ω::Real, n::Integer)

Dirichlet kernel, also known as periodic sinc function, where n should be a positive integer.

Typically returns $\frac{\sin(Ω \cdot n/2)}{n * \sin(Ω / 2)}$, but returns $±1$ when Ω is a multiple of 2π.

In the usual case where n is odd, the output is equivalent to $\frac{1}{n} \sum_{k=-(n-1)/2}^{(n-1)/2} e^{i k Ω}$, which is the discrete-time Fourier transform (DTFT) of a n-point moving average filter.

When n is odd or even, the function is 2π or 4π periodic, respectively. The formula for general n is

\[\mathrm{diric}(Ω,n) = \frac{e^{-i (n-1) Ω/2}}{n} \sum_{k=0}^{n-1} e^{i k Ω}\]

which is a real and symmetric function of Ω.

As of 2021-03-19, the Wikipedia definition has different factors. The definition here is consistent with scipy and other software frameworks.

Examples

julia> round.(diric.((-2:0.5:2)*π, 5), digits=9)'
+([0, 0, 1], -2)

See also alignsignals!.

source
DSP.diricFunction
kernel = diric(Ω::Real, n::Integer)

Dirichlet kernel, also known as periodic sinc function, where n should be a positive integer.

Typically returns $\frac{\sin(Ω \cdot n/2)}{n * \sin(Ω / 2)}$, but returns $±1$ when Ω is a multiple of 2π.

In the usual case where n is odd, the output is equivalent to $\frac{1}{n} \sum_{k=-(n-1)/2}^{(n-1)/2} e^{i k Ω}$, which is the discrete-time Fourier transform (DTFT) of a n-point moving average filter.

When n is odd or even, the function is 2π or 4π periodic, respectively. The formula for general n is

\[\mathrm{diric}(Ω,n) = \frac{e^{-i (n-1) Ω/2}}{n} \sum_{k=0}^{n-1} e^{i k Ω}\]

which is a real and symmetric function of Ω.

As of 2021-03-19, the Wikipedia definition has different factors. The definition here is consistent with scipy and other software frameworks.

Examples

julia> round.(diric.((-2:0.5:2)*π, 5), digits=9)'
 1×9 adjoint(::Vector{Float64}) with eltype Float64:
  1.0  -0.2  0.2  -0.2  1.0  -0.2  0.2  -0.2  1.0
 
 julia> diric(0, 4)
-1.0
source
+1.0
source
diff --git a/dev/windows/index.html b/dev/windows/index.html index 0d754711..b2a66050 100644 --- a/dev/windows/index.html +++ b/dev/windows/index.html @@ -19,7 +19,7 @@ 1 69 rect(n::Integer; padding::Integer=0, zerophase::Bool=false) -rect(dims; padding=0, zerophase=false)

Rectangular window of length n, padded with padding zeros. This window is 1 within the window, and 0 outside of it.

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.hanningFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
+rect(dims; padding=0, zerophase=false)

Rectangular window of length n, padded with padding zeros. This window is 1 within the window, and 0 outside of it.

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.hanningFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
 1 │                             ▄▄▀▀▀▀▀▀▀▀▄▄                             │ 
   │                          ▗▄▀            ▀▄▖                          │ 
   │                        ▗▞▘                ▝▚▖                        │ 
@@ -41,7 +41,7 @@
 hanning(n::Integer; padding::Integer=0, zerophase::Bool=false)
 hanning(dims; padding=0, zerophase=false)

Hanning window of length n with padding zeros. The Hanning (or Hann) window is a raised-cosine window that reaches zero at the endpoints.

The window is defined by sampling the continuous function:

       1 + cos(2πx)
 w(x) = ──────────── = cos²(πx)
-            2

in the range [-0.5, 0.5]

The hanning window satisfies the Constant Overlap-Add (COLA) property with a hop of 0.5, which means that adding together a sequence of delayed windows with 50% overlap will result in a constant signal. This is useful when synthesizing a signal from a number of overlapping frames (each with a roughly rectangular window), to eliminate windowing amplitude modulation.

While this windowing function was originally named after its inventor Julius Von Hann, colloquial usage has adjusted to refer to it as the "Hanning" window, to better match the similarly-named "Hamming" window. Because of this, both hann() and hanning() are exported from this module.

Note that the hanning window is the cosine window squared.

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.hammingFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
+            2

in the range [-0.5, 0.5]

The hanning window satisfies the Constant Overlap-Add (COLA) property with a hop of 0.5, which means that adding together a sequence of delayed windows with 50% overlap will result in a constant signal. This is useful when synthesizing a signal from a number of overlapping frames (each with a roughly rectangular window), to eliminate windowing amplitude modulation.

While this windowing function was originally named after its inventor Julius Von Hann, colloquial usage has adjusted to refer to it as the "Hanning" window, to better match the similarly-named "Hamming" window. Because of this, both hann() and hanning() are exported from this module.

Note that the hanning window is the cosine window squared.

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.hammingFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
 1 │                             ▄▞▀▀▀▀▀▀▀▀▚▄                             │ 
   │                          ▗▞▀            ▀▚▖                          │ 
   │                        ▗▞▘                ▝▀▄                        │ 
@@ -61,7 +61,7 @@
    1                                                                   69  
 
 hamming(n::Integer; padding::Integer=0, zerophase::Bool=false)
-hamming(dims; padding=0, zerophase=false)

Hamming window of length n with padding zeros. The Hamming window does not reach zero at the endpoints and so has a shallower frequency roll-off when compared to the Hanning window, but is designed to cancel the first side-lobe.

The window is defined by sampling the continuous function:

w(x) = 0.54 + 0.46*cos(2pi*x)

in the range [-0.5, 0.5]

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.tukeyFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
+hamming(dims; padding=0, zerophase=false)

Hamming window of length n with padding zeros. The Hamming window does not reach zero at the endpoints and so has a shallower frequency roll-off when compared to the Hanning window, but is designed to cancel the first side-lobe.

The window is defined by sampling the continuous function:

w(x) = 0.54 + 0.46*cos(2pi*x)

in the range [-0.5, 0.5]

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.tukeyFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
 1 │           ▗▞▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜▖           │ 
   │          ▗▘                                              ▝▖          │ 
   │         ▗▘                                                ▝▖         │ 
@@ -95,7 +95,7 @@
        ⎜      1 + cos ⎜── ⎜x - ─────⎟⎟           1 - α
        ⎜              ⎝ α ⎝      2  ⎠⎠       x > ─────
        ⎜      ─────────────────────────            2
-       ⎝                  2

in the range [-0.5, 0.5]

Providing a dims Tuple rather than a single n constructs a 2D window. α, padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.cosineFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
+       ⎝                  2

in the range [-0.5, 0.5]

Providing a dims Tuple rather than a single n constructs a 2D window. α, padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.cosineFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
 1 │                           ▄▄▀▀▀▀▀▀▀▀▀▀▀▀▄▄                           │ 
   │                       ▗▄▀▀                ▀▀▄▖                       │ 
   │                     ▄▀▘                      ▝▀▄                     │ 
@@ -115,7 +115,7 @@
    1                                                                   69  
 
 cosine(n::Integer; padding::Integer=0, zerophase::Bool=false)
-cosine(dims; padding=0, zerophase=false)

Cosine window of length n with padding zeros. The cosine window is the first lobe of a cosine function (with the zero crossings at +/- π as endpoints). Also called the sine window.

The window is defined by sampling the continuous function:

w(x) = cos(πx)

in the range [-0.5, 0.5]

Note that the cosine window is the square root of the hanning window, so it is sometimes used when you are applying the window twice, such as the analysis and synthesis steps of an STFT.

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.lanczosFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
+cosine(dims; padding=0, zerophase=false)

Cosine window of length n with padding zeros. The cosine window is the first lobe of a cosine function (with the zero crossings at +/- π as endpoints). Also called the sine window.

The window is defined by sampling the continuous function:

w(x) = cos(πx)

in the range [-0.5, 0.5]

Note that the cosine window is the square root of the hanning window, so it is sometimes used when you are applying the window twice, such as the analysis and synthesis steps of an STFT.

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.lanczosFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
 1 │                            ▄▄▀▀▀▀▀▀▀▀▀▀▄▄                            │ 
   │                         ▄▞▀              ▀▀▄                         │ 
   │                      ▗▞▀                    ▀▚▖                      │ 
@@ -137,7 +137,7 @@
 lanczos(n::Integer; padding::Integer=0, zerophase::Bool=false)
 lanczos(dims; padding=0, zerophase=false)

Lanczos window of length n with padding zeros. The Lanczos window is the main lobe of a sinc function.

The window is defined by sampling the continuous function:

                  sin(2πx)
 w(x) = sinc(2x) = ────────
-                     2πx

in the range [-0.5, 0.5]

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.triangFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
+                     2πx

in the range [-0.5, 0.5]

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.triangFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
 1 │                                ▄▞▀▀▀▄▖                               │ 
   │                            ▗▄▞▀      ▝▀▄▖                            │ 
   │                         ▗▄▀▘            ▝▀▄▖                         │ 
@@ -163,7 +163,7 @@
 w(x) =  ⎜
         ⎜    2(n-1)
         ⎜1 - ────── abs(x)     n is odd
-        ⎝     n+1

in the range [-0.5, 0.5].

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

When zerophase is true substitute n+1 for n in the above window expressions.

source
DSP.Windows.bartlettFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
+        ⎝     n+1

in the range [-0.5, 0.5].

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

When zerophase is true substitute n+1 for n in the above window expressions.

source
DSP.Windows.bartlettFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
 1 │                                ▗▞▀▀▚▖                                │ 
   │                              ▄▞▘    ▝▚▄                              │ 
   │                            ▄▀          ▀▄                            │ 
@@ -183,7 +183,7 @@
    1                                                                   69  
 
 bartlett(n::Integer; padding::Integer=0, zerophase::Bool=false)
-bartlett(dims; padding=0, zerophase=false)

Bartlett window of length n. The Bartlett window is a triangular window that reaches 0 at the endpoints. This is equivalent to convolving two rectangular windows of length (n-1)/2 and adding the zero endpoints. See triang for a window that does not reach zero at the endpoints.

The window is defined by sampling the continuous function:

1 - abs(2x)

in the range [-0.5, 0.5]

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.gaussianFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
+bartlett(dims; padding=0, zerophase=false)

Bartlett window of length n. The Bartlett window is a triangular window that reaches 0 at the endpoints. This is equivalent to convolving two rectangular windows of length (n-1)/2 and adding the zero endpoints. See triang for a window that does not reach zero at the endpoints.

The window is defined by sampling the continuous function:

1 - abs(2x)

in the range [-0.5, 0.5]

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.gaussianFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
 1 │                             ▗▄▞▀▀▀▀▀▀▀▄▖                             │ 
   │                           ▗▞▘          ▝▚▖                           │ 
   │                         ▗▞▘              ▝▚▖                         │ 
@@ -207,7 +207,7 @@
         ⎜-1   ⎛x⎞ ⎟
         ⎜── ⋅ ⎜─⎟ ⎟
         ⎝ 2   ⎝σ⎠ ⎠
-w(x) = e

in the range [-0.5,0.5]. This means that for σ=0.5 the endpoints of the window will correspond to 1 standard deviation away from the center.

Providing a dims Tuple rather than a single n constructs a 2D window. σ, padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.bartlett_hannFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
+w(x) = e

in the range [-0.5,0.5]. This means that for σ=0.5 the endpoints of the window will correspond to 1 standard deviation away from the center.

Providing a dims Tuple rather than a single n constructs a 2D window. σ, padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.bartlett_hannFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
 1 │                              ▄▄▀▀▀▀▀▀▄▄                              │ 
   │                           ▗▟▀          ▀▚▖                           │ 
   │                         ▗▞▘              ▝▚▖                         │ 
@@ -227,7 +227,7 @@
    1                                                                   69  
 
 bartlett_hann(n::Integer; padding::Integer=0, zerophase::Bool=false)
-bartlett_hann(dims; padding=0, zerophase=false)

Bartlett-Hann window of length n with padding zeros. The Bartlett-Hann window is a weighted sum of the Bartlett and Hann windows.

The window is defined by sampling the continuous function:

w(x) = 0.62 - 0.48*abs(x) + 0.38*cos(2π*x)

in the range [-0.5, 0.5]

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.blackmanFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
+bartlett_hann(dims; padding=0, zerophase=false)

Bartlett-Hann window of length n with padding zeros. The Bartlett-Hann window is a weighted sum of the Bartlett and Hann windows.

The window is defined by sampling the continuous function:

w(x) = 0.62 - 0.48*abs(x) + 0.38*cos(2π*x)

in the range [-0.5, 0.5]

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.blackmanFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
 1 │                              ▗▞▀▀▀▀▀▀▚▖                              │ 
   │                            ▗▞▘        ▝▚▖                            │ 
   │                           ▞▘            ▝▚                           │ 
@@ -247,7 +247,7 @@
    1                                                                   69  
 
 blackman(n::Integer; padding::Integer=0, zerophase::Bool=false)
-blackman(dims; padding=0, zerophase=false)

Approximates the "Exact" Blackman window. This is the generalized Blackman window with α = 0.16.

The window is defined by sampling the continuous function:

w(x) = 0.42 + 0.5*cos(2π*x) + 0.08*cos(4π*x)

in the range [-0.5, 0.5]

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.kaiserFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
+blackman(dims; padding=0, zerophase=false)

Approximates the "Exact" Blackman window. This is the generalized Blackman window with α = 0.16.

The window is defined by sampling the continuous function:

w(x) = 0.42 + 0.5*cos(2π*x) + 0.08*cos(4π*x)

in the range [-0.5, 0.5]

Providing a dims Tuple rather than a single n constructs a 2D window. padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.kaiserFunction
  ┌──────────────────────────────────────────────────────────────────────┐ 
 1 │                              ▗▄▀▀▀▀▀▀▄▖                              │ 
   │                            ▗▞▘        ▝▚▖                            │ 
   │                           ▄▘            ▝▄                           │ 
@@ -271,7 +271,7 @@
          ⎜  ⎜  ╱        2⎟⎟
 w(x) = I₀⎝πα⎝╲╱ 1 - (2x) ⎠⎠
        ────────────────────
-               I₀(πα)

in the range [-0.5, 0.5]

Where I₀(⋅) is the zeroth-order modified Bessel function of the first kind.

Providing a dims Tuple rather than a single n constructs a 2D window. α, padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.dpssFunction
    ┌──────────────────────────────────────────────────────────────────────┐ 
+               I₀(πα)

in the range [-0.5, 0.5]

Where I₀(⋅) is the zeroth-order modified Bessel function of the first kind.

Providing a dims Tuple rather than a single n constructs a 2D window. α, padding and zerophase can then be given either as a single value for both horizontal and vertical or a 2-tuple to specify them separately.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.dpssFunction
    ┌──────────────────────────────────────────────────────────────────────┐ 
 0.2 │                             ▗▄▞▀▀▀▀▀▀▚▄▖                             │ 
     │                           ▄▀▘          ▝▀▄                           │ 
     │                         ▄▀                ▀▄                         │ 
@@ -291,4 +291,4 @@
      1                                                                   69  
 
 dpss(n::Integer, nw::Real, ntapers::Integer=iceil(2*nw)-1;
-     padding::Integer=0, zerophase::Bool=false)

The first ntapers discrete prolate spheroid sequences (Slepian tapers) as an n × ntapers matrix. The signs of the tapers follow the convention that the first element of the skew-symmetric (odd) tapers is positive. The time-bandwidth product is given by nw.

The DPSS window maximizes the energy concentration in the main lobe.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.dpsseigFunction
dpsseig(A, nw)

Eigenvalues of the DPSS matrix, representing the ratios of the power within the main lobe to the total power (main and sidelobes). A is the output of dpss, and nw is the time-bandwidth product provided to dpss as input.

source
+ padding::Integer=0, zerophase::Bool=false)

The first ntapers discrete prolate spheroid sequences (Slepian tapers) as an n × ntapers matrix. The signs of the tapers follow the convention that the first element of the skew-symmetric (odd) tapers is positive. The time-bandwidth product is given by nw.

The DPSS window maximizes the energy concentration in the main lobe.

If zerophase is false (the default) the window is centered around index (n+1)/2, which is commonly used for FIR filter design. These are often used for FIR filter design, and usually odd-length. Note that for even-length windows this will cause the window center to be located between samples.

If zerophase is true the window is centered around index 1 (with the negative half wrapped to the end of the vector). Additionally this creates a "periodic" window, which means that if there is no padding then the left and right endpoints of the window wrap around to the same sample, so the window length is the same as an n+1-length non-zerophase window. Alternatively you can think of the continuous zerophase window being of width n and the non-zerophase window being of length n-1. zerophase windows are often used in FFT processing, and are usually even-length.

source
DSP.Windows.dpsseigFunction
dpsseig(A, nw)

Eigenvalues of the DPSS matrix, representing the ratios of the power within the main lobe to the total power (main and sidelobes). A is the output of dpss, and nw is the time-bandwidth product provided to dpss as input.

source