雖然曾經簡略介紹過 STFT ︰
人耳聽旋律,縱然不能分辨音高時值,卻知音符總有個先來後到。傳說莫札特絕對音感之好,即使是初聞的曲調,也能立刻譜出!!為求一次得到『兩個領域』── 時間、頻率 ── 的好處,於是人們設想了
短時距傅立葉變換
短時距傅立葉變換是傅立葉變換的一種變形,為時頻分析中其中一個重要的工具。
與傅立葉轉換在概念上的區別
將訊號做傅立葉變換後得到的結果,並不能給予關於訊號頻率隨時間改變的任何資訊。以下的例子作為說明:
傅立葉變換後的頻譜和短時距傅立葉轉換後的結果如下:
由上圖可發現,傅立葉轉換只提供了有哪些頻率成份的資訊,卻沒有提供時間資訊;而短時傅立葉轉換則清楚的提供這兩種資訊。這種時頻分析的方法有利於頻率會隨著時間改變的訊號,如音樂訊號和語音訊號等分析。
定義
數學定義
簡單來說,在連續時間的例子,一個函數可以先乘上僅在一段時間不為零的窗函數再進行一維的傅立葉變換。再將這個窗函數沿著時間軸挪移,所得到一系列的傅立葉變換結果排開則成為二維表象。數學上,這樣的操作可寫為:
另外也可用角頻率來表示:
其中是窗函數,窗函數種類有很多種,會在稍後再做仔細討論。是待變換的訊號。是的傅立葉變換。 隨著的改變,窗函數在時間軸上會有位移。經後,訊號只留下了窗函數截取的部分做最後的傅立葉轉換。
而反短時距傅立葉轉換,其數學類似傅立葉轉換,但須消除窗函數的作用:
窗函數
窗函數通常滿足下列特性:
- ,即為偶函數。
- ,即窗函數的中央通常是最大值的位置。
- ,即窗函數的值由中央開始向兩側單調遞減。
- ,即窗函數的值向兩側遞減為零。
常見的窗函數有:方形、三角形、高斯函數等,而短時距傅立葉轉換也因窗函數的不同而有不同的名稱。而加伯轉換,即為窗函數是高斯函數的短時距傅立葉轉換,通常沒有特別說明的短時距傅立葉轉換,即為加伯轉換。
……
頻譜(Spectrogram)
Spectrogram即短時傅立葉轉換後結果的絕對值平方,兩者本質上是相同的,在文獻上也常出現spectrogram這個名詞。
─── 摘自《W!o+ 的《小伶鼬工坊演義》︰神經網絡【FFT】六》
想來恐無助於應用 librosa stft API 軟件界面也︰
librosa.core.stft
librosa.core.
stft
(y, n_fft=2048, hop_length=None, win_length=None, window=’hann’, center=True, dtype=<class ‘numpy.complex64’>, pad_mode=’reflect’)- Short-time Fourier transform (STFT)
- Returns a complex-valued matrix D such that
-
np.abs(D[f, t]) is the magnitude of frequency bin f at frame t
np.angle(D[f, t]) is the phase of frequency bin f at frame t
Parameters: y : np.ndarray [shape=(n,)], real-valued
the input signal (audio time series)
n_fft : int > 0 [scalar]
FFT window size
hop_length : int > 0 [scalar]
number audio of frames between STFT columns. If unspecified, defaults win_length / 4.
win_length : int <= n_fft [scalar]
Each frame of audio is windowed by window(). The window will be of length win_length and then padded with zeros to match n_fft.
If unspecified, defaults to
win_length = n_fft
.window : string, tuple, number, function, or np.ndarray [shape=(n_fft,)]
- a window specification (string, tuple, or number); see
scipy.signal.get_window
- a window function, such as
scipy.signal.hanning
- a vector or array of length n_fft
center : boolean
- If True, the signal y is padded so that frame D[:, t] is centered at y[t * hop_length].
- If False, then D[:, t] begins at y[t * hop_length]
dtype : numeric type
Complex numeric type for D. Default is 64-bit complex.
mode : string
If center=True, the padding mode to use at the edges of the signal. By default, STFT uses reflection padding.
Returns: D : np.ndarray [shape=(1 + n_fft/2, t), dtype=dtype]
STFT matrix
※ 範例
故而特此援引 JULIUS O. SMITH III 先生之大作
SPECTRAL AUDIO SIGNAL PROCESSING
JULIUS O. SMITH III
Center for Computer Research in Music and Acoustics (CCRMA)
盼能加深認識的ㄡ◎