multichannel analysis support
This commit is contained in:
parent
22d3057a2d
commit
136d84ae9d
1 changed files with 18 additions and 9 deletions
27
src/STFT.jl
27
src/STFT.jl
|
@ -95,20 +95,29 @@ function analysis() end
|
||||||
stft(x, w, L=0, N=length(w)) = analysis(x, w, L, N)
|
stft(x, w, L=0, N=length(w)) = analysis(x, w, L, N)
|
||||||
|
|
||||||
function analysis(
|
function analysis(
|
||||||
x::AbstractVector{T},
|
x::V,
|
||||||
w::AbstractVector{T},
|
w::V,
|
||||||
L::Integer = 0,
|
L::I = zero(I),
|
||||||
N::Integer = length(w);
|
N::I = length(w);
|
||||||
)::AbstractMatrix{<:Complex} where {T<:Number}
|
)::Matrix{T |> complex} where {T<:Number, I<:Integer, V<:AbstractVector{T}}
|
||||||
X = length(x) # Length of the signal in samples
|
analysis((@view x[:,:]), w, L, N)
|
||||||
|
end
|
||||||
|
|
||||||
|
function analysis(
|
||||||
|
x::M,
|
||||||
|
w::V,
|
||||||
|
L::I = zero(I),
|
||||||
|
N::I = length(w);
|
||||||
|
) where {T<:Number, I<:Integer, V<:AbstractVector{T}, M<:AbstractMatrix{T}}
|
||||||
|
X, K = size(x) # Length of the signal in samples
|
||||||
W = length(w) # Length of the window in samples
|
W = length(w) # Length of the window in samples
|
||||||
H = W - L # Hop
|
H = W - L # Hop
|
||||||
S = (X-L) ÷ H # Number of segments
|
S = (X-L) ÷ H # Number of segments
|
||||||
N = N < W ? W : N # DFT size
|
N = N < W ? W : N # DFT size
|
||||||
sc = zeros(T, N, S) # Allocate container for signal segments
|
sc = zeros(T, N, S, K) # Allocate container for signal segments
|
||||||
|
|
||||||
@turbo for s ∈ 1:S, n ∈ 1:W # Slice the signal
|
@turbo for s ∈ 1:S, k ∈ 1:K, n ∈ 1:W
|
||||||
sc[n, s] = w[n] * x[(s-1)*H+n]
|
sc[n, s, k] = w[n] * x[(s-1)*H+n, k]
|
||||||
end
|
end
|
||||||
_fft(sc, 1) # Convert segments to frequency-domain
|
_fft(sc, 1) # Convert segments to frequency-domain
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue