From e7c5d946182ee74c1c9d66570fbd8acd5e876cf0 Mon Sep 17 00:00:00 2001 From: zymon Date: Mon, 25 Apr 2022 16:08:00 +0200 Subject: [PATCH] `STFT.synthesis` added. A function for real-valued signal synthesis from STFT-domain signal is added. --- src/STFT.jl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/STFT.jl b/src/STFT.jl index c0351a7..44e08f1 100644 --- a/src/STFT.jl +++ b/src/STFT.jl @@ -101,4 +101,34 @@ function analysis( end + + +function synthesis( + X::AbstractMatrix{<:Complex}, + w::AbstractVector{<:Real}, + L::Integer = 0, + N::Integer = length(w); +)::AbstractVector{<:Real} + S = size(X, 2) # Number of segments + W = length(w) # Length of the window in samples + H = W - L # Hop + K = H*(S-1)+W # Expected length of synthesised signal + w² = w.^2 # Squred window + xn = zeros(K) # Allocate memory for time-domain signal; numerator + xd = zeros(K) # Allocate memory for time-domain signal; denominator + + xs = irfft(X, N, 1) # Convert segments to time-domain + + for s ∈ 1:S + ss = (s-1)*H # Segment start + for k = 1:W + xn[ss+k] += xs[k, s] * w[k] + xd[ss+k] += w²[k] + end + end + xn ./ xd # Normalize +end + + + end # module