I Generated Guitar Audio in python using NUMBA

Поділитися
Вставка
  • Опубліковано 28 вер 2024
  • Here we use the python package NUMBA to solve the FULL wave equation and create both animations and audio outputs.
    Code located in the link below. Go to "Python Metaphysics tutorials" and then "Vid 5"
    github.com/luk...

КОМЕНТАРІ • 60

  • @jwstc99
    @jwstc99 3 роки тому +49

    You have no clue how enjoyable these videos are. Finally someone who can connect my mechanics classes to my computational ones. Could you solve a problem with continuum mechanics next?

    • @MrPSolver
      @MrPSolver  3 роки тому +16

      Currently working on a 2D schrodinger equation one but send me a problem and I'll consider it!!!

  • @suou7938
    @suou7938 3 роки тому +8

    28:55 that sounded WAY more realistic than what i was expecting.
    thank you for such an instructive and creative video!

  • @CagnPolat
    @CagnPolat 3 роки тому +3

    Great effort! And just a suggestion: you solved the diff equation and got the time domain information of the string. Since FFT kills the time domain information of the simulated sound, I think it would be much more realistic that taking every smallest partion of the string as a seperate signal source (movement of the smallest string element in time) and combining all of the signals together. Or maybe instead of using FFT, using wavelet transformations would be more realistic.

  • @danielgitlin2711
    @danielgitlin2711 3 роки тому +7

    this has quickly become my favorite channel, i love the videos. you do an amazing job!

    • @MrPSolver
      @MrPSolver  3 роки тому +3

      Thank you, that means a lot! Look forward to lots more exciting topics in the future as well. And definitely let me know if you have any suggested topics

  • @PaulDriessenFX
    @PaulDriessenFX 3 роки тому +1

    thanks for this! I'm new to python and this is a great start.
    One thing: to make it audible, instead of the FFT, you can imagine using a virtual guitar pickup. Then your timeseries is just a chain of same positions in different rows. If you average out more positions, you can also get a bigger pickup.
    That way you can easily model the pickup for your virtual guitar...

  • @robertstathers2905
    @robertstathers2905 2 роки тому

    Complex topic explained nicely. Quite elegant in python with numba. I did something similar with the heat flow equation in fortran about 45 years ago. I set up the finite difference equations in a tridiagonal matrix then used Crank Nicholson to solve iteratively. Upper and lower boundary condtions could change over time as could physical properties of the media. I'd program the IBM punch cards, run them through the card reader in batch at night and pick up the printout the next morning. Each run cost about $25. One day a semi truck and crane turned up at the computer science building and they lifted a huge box through the roof and added 5MB of ram to the mainframe. We were in hog heaven, imagine 200x200 arrays! Can't wait to see your other videos. Thanks.

    • @ramachandranmn1
      @ramachandranmn1 Рік тому

      Wonderful memories...i also have similar experience in 90's when i created some indian music using foxpro 2.6....cherishing .....

  • @BigPython
    @BigPython 3 роки тому +3

    You're killing it with these videos! Now I'm curious how the body of the instrument would change this, if you had FEM models for different "guitar" shapes... I understand that's a much more difficult simulation though :)

  • @astropgn
    @astropgn Рік тому

    Damn, I clicked on this video just because, and then I watched through the end because it was really fascinating. I really enjoyed it, thank you!

  • @Eighty_80_WAW
    @Eighty_80_WAW 3 роки тому

    When I watch your videos, I get happiness, excitment all over my body. Really interesting!

  • @sc0820
    @sc0820 Рік тому

    This is the second time I watch this tutorial. Still very amazing to me. Thx.

  • @futurisold
    @futurisold 3 роки тому +1

    A new star is rising.

  • @aravindhvijayanandan3010
    @aravindhvijayanandan3010 10 місяців тому

    Woah !!! Just tippin' my pinkie into Python. Man !! It sure is an ocean. Your content is amazing. Thanks.
    Subs from 🇮🇳 🇮🇳 🇮🇳 India

  • @poga8sun
    @poga8sun 3 роки тому +2

    This is so cool and well explained ! Thank you !

  • @EmlynCorrin
    @EmlynCorrin 3 роки тому +9

    This is really cool! Just one thing though: you set L=0.7 m (=700 mm) and Nx=101, so shouldn't delta x be 7 mm, not 0.7 mm?

    • @MrPSolver
      @MrPSolver  3 роки тому +11

      Yes, good catch!I I will update the code.

  • @Higgsinophysics
    @Higgsinophysics 3 роки тому +2

    Loved the video!

  • @Mdroudian
    @Mdroudian 2 роки тому

    this video has accomplished 2 things for me:
    1st: It's awesome you programmed a WAV.
    2nd: Watching this made me realize I'm a moron when it comes to programming in Python.
    Still interesting to watch though.

  • @piq7275
    @piq7275 3 роки тому

    Amazing work my friend! Next I wanna see is the same thing, but using the wave function without the small angle approximation. You probably need a super computer for that, but should be interesting! :)

    • @SimulatingPhysics
      @SimulatingPhysics 3 роки тому

      We don't need a supercomputer to solve the nonlinear wave equation, the same approach he used (finite difference) should be enough. What must be careful it's about the stability of the solver.

  • @dPhi_dTau
    @dPhi_dTau 3 роки тому +4

    Excellent video again! I have one question though, why did you sum the hms list to get the waveform? The hms list just gives the amplitude associated with each harmonic right, so why should summing their amplitudes have any significance at all?

    • @MrPSolver
      @MrPSolver  3 роки тому +2

      If the solution to the wave equation is f(x,t), then the integral of sin(n pi x/L)f(x,t) tells us "how much" of the wave is at the harmonic n. This can be expressed as g(t) (we integrate over x), and g(t) will have an associated frequency that gives rise to a certain waveform.

    • @MrPSolver
      @MrPSolver  3 роки тому +2

      Let sum_n be summing over all harmonics and integral_L be integrating. Note that sum_n(integral_L(f(x,t)sin(n pi x/L))) = integral_L(sum_n(f(x,t)sin(n pi x /L))) = integral_L(f(x,t)) by Fourier theory, so if we wanted to include ALL frequencies in our final waveform, we would just sum f(x,t) over x (equivalent to integrating) at each time to get the waveform. This is also proportional to taking the average of f(x,t) over x for each time.

    • @adammusk4530
      @adammusk4530 3 роки тому

      @@MrPSolver It should be sum(integral_L*sin(c*n*pi/L * t))
      It seems like you forget adding sin(c*n*pi/L * t) the term. This should be the wave that it's added to the air, not just sum(integral_L)

    • @zsolomon408
      @zsolomon408 Рік тому

      @@adammusk4530 Maybe I'm wrong but I was thinking about the same. Glad somebody pointed it out but I couldn't understand his explanation. In the end I tried both, with the sin term there is a high-frequency envelope, so the two sounds similar. Then I recorded an actual harmonic on guitar for comparison, sadly if we zoom in, the waveform seems completely random, while our generated ones are very regular. Which means even if for some reason there shouldn't be a sin term, I won't get it, at least from experiment.

  • @simonedebellis6783
    @simonedebellis6783 3 роки тому +1

    wow man! You are sooooo clean! Well done sir!

  • @chordai
    @chordai Рік тому

    Super interesting!!

  • @vivekvijayan6483
    @vivekvijayan6483 8 місяців тому

    higher notes are unstable. any idea why?

  • @adamtaylor2142
    @adamtaylor2142 3 роки тому

    Thanks for this! Might try a 2D membrane and see if I can nail down a snare sound. Get some Navier-Stokes sims of wind in a tube with holes and we can start a band 🤣

  • @lerp9993
    @lerp9993 3 роки тому +2

    I'm so down with trying this out LETS GO

  • @suou7938
    @suou7938 3 роки тому

    why did you choose NUMBA over cython?
    was it faster or just what you were used to using?
    24:55 would probably been faster if you didn’t use loops. something like
    return (sin_arr*sol).sum(axis=0)
    maybe sin_arr needs to be manually broadcasted though, forgot the exact syntax

  • @MagnusAnand
    @MagnusAnand 2 роки тому

    Super cool!

  • @patricior7300
    @patricior7300 3 роки тому

    No way... clap clap clap youuuu youuu... yes youuu... awesome !

  • @derejeyonas4523
    @derejeyonas4523 2 роки тому

    how can I use pencil codes in python?

  • @MrLaxho
    @MrLaxho 3 роки тому +1

    Nice

  • @frankkoslowski6917
    @frankkoslowski6917 Рік тому

    If you care to measure the actual lengths of the strings on your classical guitar, you will find these to be 0.65m, rather than 0.7m as is the case with a Cello.
    This is not much of an error at the end of a long day understanding the given algorithm, but an error nonetheless.
    You seem to be fudging a lot to make a sound similar to an A3 note, however this A3 note measured to be 224Hz. 😢

  • @edusmarttv2371
    @edusmarttv2371 10 місяців тому

    wow😶👍

  • @eldattackkrossa9886
    @eldattackkrossa9886 3 роки тому +1

    oooh

  • @kartikeyyadav7259
    @kartikeyyadav7259 3 роки тому +2

    Subscribed bro....

  • @rockade2408
    @rockade2408 8 місяців тому

    i cant find the source on git, sorry i am dumb

  • @gfarj
    @gfarj 3 роки тому +3

    I really enjoy your videos. This kinda video is what I'm looking for. Python + real application science. Thank you very much for this work.
    Can you also make a video to simulate tsunami that generated by an earthquake of certain location? For example earthquake in Japan. If we can find the ETA of that particular Tsunami in some area close to that earthquake, that would be awesome

  • @charliebarley94
    @charliebarley94 3 роки тому +2

    These videos are so good man, please keep it up! This is what makes physics such a beautiful subject :)

  • @davilipen
    @davilipen 3 роки тому +3

    S T R I N G S

  • @pruthvimeka3259
    @pruthvimeka3259 Рік тому

    I am getting sol = compute_d(sol, Nt, Nx, dt, dx, l, gamma) as IndexError: Getitem out of range. any ideas.

  • @Dd-wd6ip
    @Dd-wd6ip 7 місяців тому

    Where did your equation for the stress-strain term come from? May I have the source?

  • @arts5852
    @arts5852 Рік тому

    When you approximate the fourth derivative, shouldn't you use the following scheme: [y(x+2h)- 4y(x+h) + 6y(x) - 4y(x-h)+ y(x-2h)]/h^4 instead [y(x+2h)- 4y(x+h) + 4y(x) - 4y(x-h)+ y(x-2h)]/h^4 ? Can you clarify?

    • @zsolomon408
      @zsolomon408 Рік тому

      Must be a typo because it is correct in the code

  • @Maniclout
    @Maniclout 3 роки тому +1

    Love it bro

  • @iridium1118
    @iridium1118 3 роки тому +1

    Where did you get that wave equation? I can't seem to find it anywhere online.

    • @MrPSolver
      @MrPSolver  3 роки тому +1

      The damping is just added based on the fact that there will be air resistance (see air resistance formulas). The stress strain force (1D) is common among materials that bend (i.e metal strings)

    • @iridium1118
      @iridium1118 3 роки тому

      @@MrPSolver okay I see equations where the fourth order term is multiplied by EI (the elastic modulus and second moment of area). Is that equivalent to the characteristic length?

  • @MrGabexhun
    @MrGabexhun 3 роки тому

    A bit scary that you don't blink, but it's a great content! Thumbs up!

  • @eulefranz944
    @eulefranz944 3 роки тому

    Damn numba seems very simple. Maybe I should update my simuls that way

  • @brucewernick6542
    @brucewernick6542 2 роки тому

    I would like to see your python solution to sound attenuation. In the building industry, they use baffled insulated in ducting to reduce noise from the plant room. But, there seems to be NO equation that governs the air gap between baffles. From this video I'm think that the sound wave could be modelled with different baffle gaps.

    • @joansgf7515
      @joansgf7515 Рік тому

      Is there any way I can find further information about these things you call "baffles"?

  • @AJ-et3vf
    @AJ-et3vf 3 роки тому

    ❤️❤️❤️❤️