[Python] Why is the convolution of two different frequency sine waves not 0? (Windowing help)

Discussão em 'Python' iniciado por Stack, Abril 9, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to figure out how to window two different frequency sine waves in such a way that their convolution produces a 0 signal.

    I have code that works for sine waves with integer periods:

    T = 1000
    dt = 0.001
    T_step = int(T/dt)

    w1_hz = 1/25
    w2_hz = 1/12

    T1 = (1/w1_hz)
    T2 = (1/w2_hz)

    T12 = T1*T2

    times1 = np.linspace(0, T, int((T/dt)))
    times2 = np.linspace(0, T12, int(((T12)/dt)))

    wave1 = np.sin(w1_hz*2*math.pi*times1)
    wave2 = np.sin(w2_hz*2*math.pi*times2)

    conv = signal.convolve(wave1, wave2, "same")

    plt.plot(times1, conv)
    plt.show()


    In the future I want to apply this to taking the convolution of an impulse response function and a wave surface elevation signal to generate a force based on the frequency and amplitude of the wave. The code above represents a "test" of an IRF with a single force input of 1 N/m at the frequency w2_hz and its convolution with a wave with an amplitude of 1 and a frequency of w1_hz.

    The code above produces the force signal I expect for integer periods in the case of the code 25, and 12. However if you make either of them decimals, 25.5 for example the amplitude of the resulting force signal is no longer close to 0 (in the range of hundreds to thousands).

    I found that for this to produce the results I want I needed to take a window size for wave 2 equal to the period of wave 1 * the period of wave 2. The window size of wave 1 doesn't effect the result as long as its larger then the window of wave 2. I've tried changing the phase of wave 2 but besides minorly changing the amplitude of the resulting force (less then 5%) it doesn't seem to have an effect.

    I feel like I'm misunderstanding what is actually going on in the convolution, any help would be greatly appreciated!

    Continue reading...

Compartilhe esta Página