I Generated Guitar Audio in python using NUMBA

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 มี.ค. 2021
  • 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/lukepolson/youtube...

ความคิดเห็น • 60

  • @jwstc99
    @jwstc99 3 ปีที่แล้ว +48

    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 ปีที่แล้ว +7

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

  • @charliebarley94
    @charliebarley94 3 ปีที่แล้ว +2

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

  • @poga8sun
    @poga8sun 3 ปีที่แล้ว +2

    This is so cool and well explained ! Thank you !

  • @Higgsinophysics
    @Higgsinophysics 3 ปีที่แล้ว +2

    Loved the video!

  • @PaulDriessenFX
    @PaulDriessenFX 2 ปีที่แล้ว +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...

  • @danielgitlin2711
    @danielgitlin2711 3 ปีที่แล้ว +6

    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

  • @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!

  • @CagnPolat
    @CagnPolat 2 ปีที่แล้ว +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.

  • @sc0820
    @sc0820 ปีที่แล้ว

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

  • @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 :)

  • @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 .....

  • @Eighty_80_WAW
    @Eighty_80_WAW 2 ปีที่แล้ว

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

  • @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.

  • @MrGabexhun
    @MrGabexhun 3 ปีที่แล้ว

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

  • @futurisold
    @futurisold 3 ปีที่แล้ว +1

    A new star is rising.

  • @Maniclout
    @Maniclout 3 ปีที่แล้ว +1

    Love it bro

  • @chordai
    @chordai 9 หลายเดือนก่อน

    Super interesting!!

  • @gfarj
    @gfarj 2 ปีที่แล้ว +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

  • @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.

  • @MagnusAnand
    @MagnusAnand 2 ปีที่แล้ว

    Super cool!

  • @aravindhvijayanandan3010
    @aravindhvijayanandan3010 8 หลายเดือนก่อน

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

  • @simonedebellis6783
    @simonedebellis6783 3 ปีที่แล้ว +1

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

  • @MrLaxho
    @MrLaxho 3 ปีที่แล้ว +1

    Nice

  • @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 10 หลายเดือนก่อน

      @@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.

  • @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 🤣

  • @Mdroudian
    @Mdroudian ปีที่แล้ว

    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.

  • @patricior7300
    @patricior7300 3 ปีที่แล้ว

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

  • @lerp9993
    @lerp9993 3 ปีที่แล้ว +2

    I'm so down with trying this out LETS GO

  • @AJ-et3vf
    @AJ-et3vf 2 ปีที่แล้ว

    ❤️❤️❤️❤️

  • @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 11 หลายเดือนก่อน

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

  • @edusmarttv2371
    @edusmarttv2371 8 หลายเดือนก่อน

    wow😶👍

  • @Dd-wd6ip
    @Dd-wd6ip 4 หลายเดือนก่อน

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

  • @eldattackkrossa9886
    @eldattackkrossa9886 3 ปีที่แล้ว +1

    oooh

  • @derejeyonas4523
    @derejeyonas4523 2 ปีที่แล้ว

    how can I use pencil codes in python?

  • @vivekvijayan6483
    @vivekvijayan6483 6 หลายเดือนก่อน

    higher notes are unstable. any idea why?

  • @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

  • @pruthvimeka3259
    @pruthvimeka3259 10 หลายเดือนก่อน

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

  • @kartikeyyadav7259
    @kartikeyyadav7259 3 ปีที่แล้ว +2

    Subscribed bro....

  • @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 10 หลายเดือนก่อน

      Must be a typo because it is correct in the code

  • @davilipen
    @davilipen 3 ปีที่แล้ว +3

    S T R I N G S

  • @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?

  • @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. 😢

  • @rockade2408
    @rockade2408 5 หลายเดือนก่อน

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