diff --git a/src/STFT.jl b/src/STFT.jl index 0508906..1614b97 100644 --- a/src/STFT.jl +++ b/src/STFT.jl @@ -3,5 +3,29 @@ module STFT using FFTW +_fft(x::AbstractMatrix{<:Real}, d) = rfft(x, d) +_fft(x::AbstractMatrix{<:Complex}, d) = fft(x, d) + + + +function analysis( + x::AbstractVector{T}, + w::AbstractVector{T}, + L::Integer = 0, + N::Integer = length(w); +)::AbstractMatrix{<:Complex} where {T<:Number} + X = length(x) # Length of the signal in samples + W = length(w) # Length of the window in samples + H = W - L # Hop + S = (X-L) ÷ H # Number of segments + N = N < W ? W : N # DFT size + sc = zeros(T, N, S) # Allocate container for signal segments + + for s ∈ 1:S, n ∈ 1:W # Slice the signal + sc[n, s] = w[n] * x[(s-1)*H+n] + end + _fft(sc, 1) # Convert segments to frequency-domain +end + end # module