[Python] One frequency is absent from fourier transform representation of the addition of two...

Discussão em 'Python' iniciado por Stack, Maio 11, 2025.

  1. Stack

    Stack Membro Participativo

    I have wrote a general python code in Sage-math to find out the Fourier transform of the addition of two different frequency cosine wave in order to plot the frequency domain in a graph. The function :

    f(t) = cos(2*pi*f1*t)+cos(2*pi*f2*t) # integrate it from -infinity to +infinity


    To find the integral, I have used Sympy pacakge. Below is a sample of the resultant piecewise functions I am getting after performing integration of the Fourier transform frequency function:

    [​IMG]

    Then in order to check which frequencies are present in the resultant function, I search for existing frequency between -10 to +10 on the Fourier transform function .

    Here f1 and f2 are respective frequency of the two cosine wave. When f1 = 8 and f2 = 4, I get the following graph ( both frequency (8 & 4) is present in the graph as expected):

    [​IMG]

    But if I change any one of f1 or f2 to 7, Then only 7 is present on the graph. Here you can see that frequency 4 is absent from the graph. I have found that this issue only appears if frequency 7 is present in any one of the two cosine functions.

    [​IMG]

    Here is the code:

    from sage.all import *
    import numpy as np
    import sympy as sy
    from sympy import lambdify,re, im
    import matplotlib.pyplot as plt

    t = sy.Symbol('t')
    f = sy.Symbol('f')

    # Find Fourier Transform
    F = sy.integrate((cos(2*pi*7*t)+cos(2*pi*4*t))*(e^(-i*2*pi*f*t)), (t,-oo,oo))

    func = F.args[0][0] # extract 1st function from piecewise F

    #lambdify to evaluate function at many points
    sympy_lambda = lambdify([f],func)

    freq_arr = []
    amplitude_arr = []

    # here l (L) is frequency in x-coordinate, testing for frequency -10 to 10
    for l in np.arange(-10, 10, 0.01):
    sympy_complex = sympy_lambda(l) # get sympy complex number
    # get real part of sympy complex number
    real_part = re(sympy_complex)

    # get imaginary part of sympy complex number
    imag_part = im(sympy_complex)

    # make a sage complex number using from sympy real and imaginary
    sage_complex = ComplexNumber(real_part, imag_part)

    freq_arr.append(l)
    amplitude_arr.append(abs(sage_complex))

    Continue reading...

Compartilhe esta Página