1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] fftshift or convolve from NumPy module incorrect operation

Discussão em 'Python' iniciado por Stack, Setembro 27, 2024 às 14:12.

  1. Stack

    Stack Membro Participativo

    I'm trying to show in Python equivalence of two signals multiplication in time domain to convolution of them in frequency domain.

    Thanks to Baddioes in this post, it was shown that such equivalence can be shown by using fftshift function, but the example was done in Matlab. I expected to get absolutely the same result in Python, but it is not the same, the code is below:

    f = 2e6
    t = np.linspace(0,1,64)

    x = np.sin(2*np.pi*f*t)
    y = np.sin(2*np.pi*0.5*f*t)

    # multiplication in time domain
    signal_xy = x*y

    # Fourier of multiplied signals and individual signal
    FFT_xy = np.fft.fft(signal_xy)
    FFT_x = np.fft.fft(x)
    FFT_y = np.fft.fft(y)

    # plot the result
    plt.plot(abs(FFT_xy))
    plt.plot(np.fft.fftshift(abs(np.convolve(np.fft.fftshift(FFT_x),np.fft.fftshift(FFT_y), 'same')))/len(FFT_x), linestyle='--')


    [​IMG]

    I also tried to use fftshift and convolve from scipy module, but the result is absolutely the same.

    Does fftshift and convolve functions work correctly in Python?

    Continue reading...

Compartilhe esta Página