STFT.analysis
added.
A function for signal analysis using STFT is added.
This commit is contained in:
parent
f10aa3f6ae
commit
a561d68843
1 changed files with 24 additions and 0 deletions
24
src/STFT.jl
24
src/STFT.jl
|
@ -3,5 +3,29 @@ module STFT
|
||||||
using FFTW
|
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
|
end # module
|
||||||
|
|
Loading…
Reference in a new issue