當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python cusignal.spectral_analysis.spectral.istft用法及代碼示例

用法:

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 ,該值取決於 Zxxinput_onesided 的形狀。如果 input_onesidedTruenperseg=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] - 1nfft 也采用該值。這種情況允許使用 nfft=None 正確反轉 odd-length 未填充的 STFT。默認為 None

input_onesided布爾型,可選

如果 True ,將輸入數組解釋為 one-sided FFT,例如由 stftreturn_onesided=Truenumpy.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()

相關用法


注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cusignal.spectral_analysis.spectral.istft。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。