ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • scipy.signal.stft
    Robotics 2019. 7. 25. 18:52

    SciPy 는 수학, 과학, 그리고 엔지니어링을 위한 파이선 오픈 소스 소프트웨어라고 제시되고 있다.

    Spectral Analysis

    periodogram(x[, fs, window, nfft, detrend, …])

    Estimate power spectral density using a periodogram.

    welch(x[, fs, window, nperseg, noverlap, …])

    Estimate power spectral density using Welch’s method.

    csd(x, y[, fs, window, nperseg, noverlap, …])

    Estimate the cross power spectral density, Pxy, using Welch’s method.

    coherence(x, y[, fs, window, nperseg, …])

    Estimate the magnitude squared coherence estimate, Cxy, of discrete-time signals X and Y using Welch’s method.

    spectrogram(x[, fs, window, nperseg, …])

    Compute a spectrogram with consecutive Fourier transforms.

    lombscargle(x, y, freqs)

    Computes the Lomb-Scargle periodogram.

    vectorstrength(events, period)

    Determine the vector strength of the events corresponding to the given period.

    stft(x[, fs, window, nperseg, noverlap, …])

    Compute the Short Time Fourier Transform (STFT).

    istft(Zxx[, fs, window, nperseg, noverlap, …])

    Perform the inverse Short Time Fourier transform (iSTFT).

    check_COLA(window, nperseg, noverlap[, tol])

    Check whether the Constant OverLap Add (COLA) constraint is met

    check_NOLA(window, nperseg, noverlap[, tol])

    Check whether the Nonzero Overlap Add (NOLA) constraint is met

    Scipy 에서 제공되는 STFT 에 관해 알아보자.

    https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.stft.html

    scipy.signal.stft

    scipy.signal.stft(x,fs=1.0,window='hann',nperseg=256,noverlap=None,nfft=None,detrend=False,return\_onesided=True,boundary='zeros',padded=True,axis=-1)

    Short Time Fourier Transform (STFT) 을 계산해준다.
    STFTs 는 a nonstationary signal’s frequency and phase content가 시간에 따라서 변화하는 양을 정량화 할 수 있다 ..

    Parameters
    x: array_like
    측정치의 Time series

    fs : float, optional
    x time series 의 Sampling frequency . Defaults 는 1.0.

    window : str or tuple or array_like, optional
    바람직한 window 가 사용되어 진다. window 가 string or tuple 이라면,이는 get_window 에 window values 을 생성하기 위해서 전달한다, DFT-even 이 default 로 되었다. get_window 에서 사용 가능한 windows 리스트 들과 parameters 들이 나와 있다. 만약, window 가 array_like 이라면 바로 윈도우로 사용 될 것이다. 그리고 그것의 길이는 nperseg와 같은 것이다. Defaults 는 Hann window 이다.

    nperseg : int, optional
    각 segment의 길이, Defaults 는 256 이다.

    noverlap : int, optional
    segments 사이에 overlap 된 point 의 수. 만약 overlap 이 없다면, `noverlap = nperseg // 2`. Defaults 는 None으로 되어 있다. 만약 지정된다면, COLA constraint 가 만족해야한다. (see Notes below).

    nfft : int, optional

    zero padded FFT가 필요한 경우 FFT의 길이가 사용 됩니다. None 인 경우, FFT 길이는 nperseg입니다. 기본값은 None입니다.

    detrend : str or function or False, optional
    각 세그먼트를 detrend 하는 방법을 지정합니다. detrend가 문자열이면 detrend 함수에 the type argument 형식로 전달됩니다. 함수 인 경우 세그먼트를 가져와 detrended 세그먼트를 반환합니다. detrend가 False이면 detrending이 수행되지 않습니다. 기본값은 False입니다.

    return_onesided : bool, optional

    True이면 실제 데이터에 대해 일방적 인 스펙트럼을 반환합니다. False이면 양면 스펙트럼을 반환합니다. 기본값은 True이지만, 복잡한 데이터의 경우 양면 스펙트럼이 항상 반환됩니다.

    boundary : str or None, optional

    first input point에서 first windowed segment를 가운데 맞추기 위해 입력 신호가 양쪽 끝에서 확장되는지 여부와 새 값을 생성하는 방법을 지정합니다. 이것은 사용 된 윈도우 함수가 제로에서 시작될 때 제 1 입력 포인트의 재구성을 가능하게하는 이점을 갖는다. 유효한 옵션은 [ 'even', 'odd', 'constant', 'zeros', None]입니다. zero padding extension을 위해 기본값은 '0'입니다. I.e.. [1, 2, 3, 4]는 nperseg = 3 인 경우 [0, 1, 2, 3, 4, 0]로 확장됩니다.

    padded : bool, optional
    모든 신호가 출력에 포함되도록 신호가 정수 세그먼트의 window segments에 정확히 맞춰 지도록 입력 신호가 끝에 zero-padded 되는지 여부를 지정합니다. 기본값은 True입니다. 경계가 None이 아니고 padded가 True이면 Padding가 boundary extension 후 기본값으로, 발생합니다.

    axis : int, optional
    STFT가 계산되는 축. 기본값은 마지막 축 (즉, 축 = -1)입니다.

    Returns
    f : ndarray
    샘플 주파수의 배열.

    t : ndarray
    세그먼트 시간의 배열.

    Zxx : ndarray
    x의 STFT. 기본적으로 Zxx의 마지막 축은 세그먼트 시간에 해당합니다.

    ### 더 공부 할 것

    istft

    Inverse Short Time Fourier Transform

    check_COLA

    Check whether the Constant OverLap Add (COLA) constraint is met

    check_NOLA

    Check whether the Nonzero Overlap Add (NOLA) constraint is met

    welch

    Power spectral density by Welch’s method.

    spectrogram

    Spectrogram by Welch’s method.

    csd

    Cross spectral density by Welch’s method.

    lombscargle

    Lomb-Scargle periodogram for unevenly sampled data

    ### Notes

    istft로 역 STFT를 통한 inverse STFT을 가능하게하려면, 신호 windowing은 "Nonzero OverLap Add"(NOLA)의 제약 조건을 따라야하고, 입력 신호는 완전한 windowing coverage를 가져야합니다. (즉, (x.shape [axis ] - nperseg) % (nperseg-noverlap) == 0)`입니다.

    이를 수행하기 위해 Thepaddedargument가 사용될 수 있습니다. 주어진 시간 - 영역 신호 x [n], 윈도우 w [n], 및 hop size 인 H = nperseg - noverlap에서, 시간 인덱스 t에서의 윈도우 프레임은

    $x_t[n]=x[n]w[n−tH]$

    The overlap-add (OLA) reconstruction equation 방정식은 다음과 같이 주어진다.

    $x[n]=∑_t{x_t[n]}{w[n−tH]}∑_tw^2[n−tH]$

    NOLA 제약 조건은 OLA reconstruction 방정식의 분모에 나타나는 모든 normalization term가 0이 아니도록 보장합니다. window, nperseg 및 noverlap 중 하나를 선택하여이 제약 조건을 만족하는지 여부는 check_NOLA로 테스트 할 수 있습니다.

    References

    1

    Oppenheim, Alan V., Ronald W. Schafer, John R. Buck “Discrete-Time Signal Processing”, 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

    Examples

    from scipy import signal  
    import matplotlib.pyplot as plt  
    Generate a test signal, a 2 Vrms sine wave whose frequency is slowly modulated around 3kHz, corrupted by white noise of exponentially decreasing magnitude sampled at 10 kHz.
    
    fs = 10e3  
    N = 1e5  
    amp = 2 \* np.sqrt(2)  
    noise\_power = 0.01 \* fs / 2  
    time = np.arange(N) / float(fs)  
    mod = 500_np.cos(2_np.pi_0.25_time)  
    carrier = amp \* np.sin(2_np.pi_3e3\*time + mod)  
    noise = np.random.normal(scale=np.sqrt(noise\_power),  
    .. size=time.shape)  
    noise \*= np.exp(-time/5)  
    x = carrier + noise  
    Compute and plot the STFT’s magnitude.
    
    f, t, Zxx = signal.stft(x, fs, nperseg=1000)  
    plt.pcolormesh(t, f, np.abs(Zxx), vmin=0, vmax=amp)  
    plt.title('STFT Magnitude')  
    plt.ylabel('Frequency \[Hz\]')  
    plt.xlabel('Time \[sec\]')  
    plt.show()

    'Robotics' 카테고리의 다른 글

    [Ref] Path Planning Algorithms  (0) 2019.08.16
    PoseNet: A Convolutional Network for Real-Time 6-DOF Camera Relocalization  (1) 2019.08.02
    RL to Robotics  (0) 2019.07.04

    댓글

Designed by Tistory.