用法:
cusignal.spectral_analysis.spectral.istft(Zxx, fs=1.0, window='hann', nperseg=None, noverlap=None, nfft=None, input_onesided=True, boundary=True, time_axis=- 1, freq_axis=- 2)
執行逆短時傅裏葉變換 (iSTFT)。參數——- Zxx:數組
要重建的信號的 STFT。如果傳遞的是純實數數組,它將被強製轉換為複雜數據類型。
- fs浮點數,可選
時間序列的采樣頻率。默認為 1.0。
- 窗戶str 或 tuple 或 數組,可選
想要使用的窗口。如果
window
是字符串或元組,則傳遞給get_window
生成窗口值,默認為DFT-even。有關窗口和所需參數的列表,請參閱get_window
。如果window
是數組,它將直接用作窗口,其長度必須為nperseg。默認為 Hann 窗口。必須與用於生成 STFT 的窗口匹配以實現忠實的反演。- npersegint 可選
每個 STFT 段對應的數據點數。如果每段的數據點數是奇數,或者如果 STFT 是通過
nfft > nperseg
填充的,則必須指定此參數。如果None
,該值取決於Zxx
和input_onesided
的形狀。如果input_onesided
是True
,nperseg=2*(Zxx.shape[freq_axis] - 1)
。否則,nperseg=Zxx.shape[freq_axis]
。默認為None
。- 重疊int 可選
段之間重疊的點數。如果
None
,則為段長度的一半。默認為None
。指定時,必須滿足 COLA 約束(請參閱下麵的注釋),並且應與用於生成 STFT 的參數匹配。默認為None
。- nfftint 可選
每個 STFT 段對應的 FFT 點數。如果 STFT 通過
nfft > nperseg
填充,則必須指定此參數。如果None
,默認值與nperseg
相同,詳見上文,但有一個異常:如果input_onesided
為 True 且nperseg==2*Zxx.shape[freq_axis] - 1
,nfft
也采用該值。這種情況允許使用nfft=None
正確反轉 odd-length 未填充的 STFT。默認為None
。- input_onesided布爾型,可選
如果
True
,將輸入數組解釋為 one-sided FFT,例如由stft
與return_onesided=True
和numpy.fft.rfft
返回。如果False
,將輸入解釋為 two-sided FFT。默認為True
。- 邊界布爾型,可選
通過向
stft
提供非None
boundary
參數來指定輸入信號是否在其邊界處擴展。默認為True
。- time_axisint 可選
STFT的時間段所在的位置;默認值為最後一個軸(即
axis=-1
)。- freq_axisint 可選
STFT的頻率軸所在的位置;默認值為倒數第二個軸(即
axis=-2
)。
- tndarray
輸出數據時間數組。
- xndarray
Zxx
的 iSTFT。
STFT:短時間傅裏葉變換check_COLA:檢查常量OverLap添加(可賭Cola)約束
滿足
check_NOLA:檢查是否滿足非零重疊相加 (NOLA) 約束 注 ---- 為了通過
istft
的反向 STFT 啟用 STFT 的反轉,信號窗口必須服從 “nonzero overlap add” (NOLA) 的約束: .. math::sum_{t}w^{2}[n-tH] ne 0 這確保了出現在 overlap-add 重建方程的分母中的歸一化因子 .. math::x[n]= frac{sum_{t}x_{t}[n]w[n-tH]}{sum_{t}w^{2}[n-tH]} 不為零。可以使用check_NOLA
函數檢查 NOLA 約束。已修改(通過掩碼或其他方式)的 STFT 不能保證對應於完全可實現的信號。此函數通過 [2] 中詳述的 least-squares 估計算法實現 iSTFT,該算法產生的信號使返回信號的 STFT 與修改後的 STFT 之間的均方誤差最小化。 .. version added::0.19.0 References ----- .. [Rb890c6d0cb06-1] Oppenheim, Alan V., Ronald W. Schafer, John R. Buck“Discrete-Time 信號處理”,Prentice Hall,1999 年。
- 2
Daniel W. Griffin, Jae S. Lim “Signal Estimation from Modified Short-Time Fourier Transform”, IEEE 1984, 10.1109/TASSP.1984.1164317
>>> from scipy import signal >>> import matplotlib.pyplot as plt Generate a test signal, a 2 Vrms sine wave at 50Hz corrupted by 0.001 V**2/Hz of white noise sampled at 1024 Hz. >>> fs = 1024 >>> N = 10*fs >>> nperseg = 512 >>> amp = 2 * np.sqrt(2) >>> noise_power = 0.001 * fs / 2 >>> time = cp.arange(N) / float(fs) >>> carrier = amp * cp.sin(2*cp.pi*50*time) >>> noise = cp.random.normal(scale=cp.sqrt(noise_power), ... size=time.shape) >>> x = carrier + noise Compute the STFT, and plot its magnitude >>> f, t, Zxx = cusignal.stft(x, fs=fs, nperseg=nperseg) >>> f = cp.asnumpy(f) >>> t = cp.asnumpy(t) >>> Zxx = cp.asnumpy(Zxx) >>> plt.figure() >>> plt.pcolormesh(t, f, np.abs(Zxx), vmin=0, vmax=amp, shading='gouraud') >>> plt.ylim([f[1], f[-1]]) >>> plt.title('STFT Magnitude') >>> plt.ylabel('Frequency [Hz]') >>> plt.xlabel('Time [sec]') >>> plt.yscale('log') >>> plt.show() Zero the components that are 10% or less of the carrier magnitude, then convert back to a time series via inverse STFT >>> Zxx = cp.where(cp.abs(Zxx) >= amp/10, Zxx, 0) >>> _, xrec = cusignal.istft(Zxx, fs) >>> xrec = cp.asnumpy(xrec) >>> x = cp.asnumpy(x) >>> time = cp.asnumpy(time) >>> carrier = cp.asnumpy(carrier) Compare the cleaned signal with the original and true carrier signals. >>> plt.figure() >>> plt.plot(time, x, time, xrec, time, carrier) >>> plt.xlim([2, 2.1])*+ >>> plt.xlabel('Time [sec]') >>> plt.ylabel('Signal') >>> plt.legend(['Carrier + Noise', 'Filtered via STFT', 'True Carrier']) >>> plt.show() Note that the cleaned signal does not start as abruptly as the original, since some of the coefficients of the transient were also removed: >>> plt.figure() >>> plt.plot(time, x, time, xrec, time, carrier) >>> plt.xlim([0, 0.1]) >>> plt.xlabel('Time [sec]') >>> plt.ylabel('Signal') >>> plt.legend(['Carrier + Noise', 'Filtered via STFT', 'True Carrier']) >>> plt.show()
相關用法
- Python cusignal.spectral_analysis.spectral.welch用法及代碼示例
- Python cusignal.spectral_analysis.spectral.spectrogram用法及代碼示例
- Python cusignal.spectral_analysis.spectral.lombscargle用法及代碼示例
- Python cusignal.spectral_analysis.spectral.periodogram用法及代碼示例
- Python cusignal.spectral_analysis.spectral.csd用法及代碼示例
- Python cusignal.spectral_analysis.spectral.coherence用法及代碼示例
- Python cusignal.spectral_analysis.spectral.stft用法及代碼示例
- Python cusignal.windows.windows.hann用法及代碼示例
- Python cusignal.windows.windows.general_gaussian用法及代碼示例
- Python cusignal.waveforms.waveforms.chirp用法及代碼示例
- Python cusignal.windows.windows.gaussian用法及代碼示例
- Python cusignal.windows.windows.hamming用法及代碼示例
- Python cusignal.windows.windows.get_window用法及代碼示例
- Python cusignal.waveforms.waveforms.gausspulse用法及代碼示例
- Python cusignal.peak_finding.peak_finding.argrelmin用法及代碼示例
- Python cusignal.windows.windows.bartlett用法及代碼示例
- Python cusignal.windows.windows.chebwin用法及代碼示例
- Python cusignal.windows.windows.general_cosine用法及代碼示例
- Python cusignal.peak_finding.peak_finding.argrelextrema用法及代碼示例
- Python cusignal.convolution.convolve.convolve2d用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cusignal.spectral_analysis.spectral.istft。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。