[Python] Stochastic Harmonic Functions

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

  1. Stack

    Stack Membro Participativo

    I'm currently writing and trying to program about shfs and shms and cant get any results.

    Trying to reproduce with psds some stochastic harmonic functions (SHFs) /methods (SHMs)

    The psd is clear, just a function about earthquakes. SHM is also clear but the function in pic 1:pic1 gives me problems.

    What is N?

    Is N the sum of t const. and omega_i iterating over all the steps before?

    Like list1 = "function1" + list1[i-1] ?


    and I'm not sure if the difference is meant or not.

    I already got the psd, looking like that:

    psd

    saved in a list.

    My shm looks in code like this:

    def SHM(psd,t, ele):
    i = 1
    y = [0]
    phi = random.uniform(0, 2 * 3.14)
    while i != ele:
    y.append((A(i, psd) * math.cos(i*t+phi)) + y[i-1)
    i = i+1
    return y


    with A being:

    def A(i, S_0):
    dw = 1
    s = (2*(S_0*dw)**0.5)
    return s


    And my inputs are:

    while z != 5000:
    while i != 80:
    psd.append(RuPe(S0,omega,omega*0.1,i,daem,daem))
    i = i+1
    #plt.plot(SHF(psd,80,10))
    z = z+1


    RuPe is the PSD Formula with z,i starting as 0

    SHM Results

    and I have no idea how to get SHF to work, so I got results like this:

    def SHF(psd, t, ele):
    i = 1
    y = [0,]
    phi = random.uniform(0, 2 * 3.14)
    while i != ele:
    if i == 0:
    a = A(i,psd)
    else:
    a = abs(A(i,psd) - A(i-1,psd))
    y.append(a * math.cos((i) * t + phi)) #'''y[i-1])'''
    i = i + 1

    return y


    SHF results

    maybe there is another guy with experience in stochastics and could help me :/

    PSD Code:

    def RuPe(S_0,w_0,w_1,w,dam,dam_1):
    o1 = (1 + 4*(dam)**2*(w/w_0)**2)
    u1 = (1-(w/w_0)**2)**2 + 4*dam**2*(w/w_0)**2
    o2 = (w/w_1)**4
    u2 = (1-(w/w_1)**2)**2 + 4*dam_1**2 * (w/w_1)**2
    s = ((o1*o2)/(u1*u2))*S_0
    return s


    with

    omega = 15.71
    daem = 0.7
    S0 = 10

    Continue reading...

Compartilhe esta Página