Coding Challenge 125: Fourier Series

Поділитися
Вставка
  • Опубліковано 15 чер 2024
  • In this coding challenge, I visualize a Fourier series for a square wave in JavaScript with p5.js. Code: thecodingtrain.com/challenges...
    🕹️ p5.js Web Editor Sketch: editor.p5js.org/codingtrain/s...
    🎥 Previous video: • Coding Challenge 124: ...
    🎥 Next video: • Coding Challenge #126:...
    🎥 All videos: • Coding Challenges
    References:
    🗄 Fourier Series: en.wikipedia.org/wiki/Fourier...
    📄 Purrier Series (Meow) and Making Images Speak: bilimneguzellan.net/purrier-se...
    📄 An Interactive Guide To The Fourier Transform by Better Explained: betterexplained.com/articles/...
    Videos:
    🎥 What is a Fourier Series?: • What is a Fourier Seri...
    🎥 But what is the Fourier Transform? A visual introduction: • But what is the Fourie...
    🚂 Polar Coordinates: • 3.4 Polar Coordinates ...
    🔴 Coding Train Live 163: • Coding Train Live 163:...
    Related Coding Challenges:
    🚂 #61 Fractal Spirograph: • Coding Challenge #61: ...
    🚂 #130 Drawing with Fourier Transform and Epicycles: • Coding Challenge #130....
    Timestamps:
    00:00 Welcome! Some resources on the Fourier Series
    02:44 Explain! What is a Fourier Series?
    07:00 Code! Create a dot spinning around a circle!
    11:41 Code! Draw the wave path of the dot!
    14:41 Oops! Invert the order of the wave!
    16:16 Code! Add multiple circle waves!
    23:50 Code! Draw the Fourier series!
    25:30 Code! Add slider for number of circles!
    27:39 Suggestions
    Editing by Mathieu Blanchette
    Animations by Jason Heglund
    Music from Epidemic Sound
    🚂 Website: thecodingtrain.com/
    👾 Share Your Creation! thecodingtrain.com/guides/pas...
    🚩 Suggest Topics: github.com/CodingTrain/Sugges...
    💡 GitHub: github.com/CodingTrain
    💬 Discord: thecodingtrain.com/discord
    💖 Membership: ua-cam.com/users/thecodingtrainjoin
    🛒 Store: standard.tv/codingtrain
    🖋️ Twitter: / thecodingtrain
    📸 Instagram: / the.coding.train
    🎥 Coding Challenges: • Coding Challenges
    🎥 Intro to Programming: • Start learning here!
    🔗 p5.js: p5js.org
    🔗 p5.js Web Editor: editor.p5js.org/
    🔗 Processing: processing.org
    📄 Code of Conduct: github.com/CodingTrain/Code-o...
    This description was auto-generated. If you see a problem, please open an issue: github.com/CodingTrain/thecod...
    #fourier #maths #javascript #p5js

КОМЕНТАРІ • 508

  • @vigneshwarm
    @vigneshwarm 5 років тому +975

    3blue1brown recommended this video for his Fourier transform video

    • @akremhadji7326
      @akremhadji7326 5 років тому +11

      I've just watched it, it was amazing !!!

    • @FilthyManatee
      @FilthyManatee 5 років тому +14

      I just watched his video, then I tried coding my own Fourier series. Figured I would come on here and see what I did wrong.

    • @akremhadji7326
      @akremhadji7326 5 років тому +5

      ​@@FilthyManatee In this video the Fourier series is developed in JavaScript language to be run on a normal web browser. If you want more advanced tools to work with such series you can use mathematical software (Matlab, Maple, Octave ..) they have many dedicated methods to be implemented easily. If you want to do things the hard way ;) you can download the code of the presented script in this video and try to modify the coefficients or change other parameters.

    • @FilthyManatee
      @FilthyManatee 5 років тому +4

      @@akremhadji7326 I wrote mine in the hard/fun way (javascript/canvas) already. I did it very differently than what was shown here, but was still able to learn a thing or two watching this video. It gave me a few things to think about and change in my code. I went right into the chain of alternating spinning vectors and drawing from the last point on the chain.

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

      I came here from 3 Blue 1 Brown. And, I am so happy I did! This is a great channel! :)

  • @jonnylinford
    @jonnylinford 5 років тому +206

    So happy to see you and Destin interact. This is the intersection of all the best content on UA-cam

  • @oscard4801
    @oscard4801 5 років тому +203

    I'm 11 and I'm from Mexico, and have been programming for 3 years and Coding Train is my source of inspiration and learning.

    • @TheCodingTrain
      @TheCodingTrain  5 років тому +32

      So nice to hear! Please feel free to share anything you make 🙂

    • @GodofChookie
      @GodofChookie 5 років тому +18

      it's awesome to have such a productive hobby you get enjoyment from and willingly invest your free time. especially at such a young age. keep it up

    • @philippg6023
      @philippg6023 5 років тому +3

      Awesome keep it up

    • @LongLe-nt8bv
      @LongLe-nt8bv 5 років тому +1

      b0ss thats great for his age and its called a "comment", plus he just want to say thanks to Daniel

    • @oscard4801
      @oscard4801 5 років тому +5

      ​@@don1041 I learned Javascript, p5.js, HTML and CSS

  • @carlosmorasalguero
    @carlosmorasalguero 5 років тому +299

    Wow, smarter every day in the coding train... Avengers is no longer the most ambitious crossover in the history of the world

  • @ibuucoksiregar9024
    @ibuucoksiregar9024 4 роки тому +12

    90% of my coding skill is from Coding Train.
    Everytime my friends ask me where i learned something, I always show them this channel.
    I love this channel so much❤️❤️

  • @sharphurt8753
    @sharphurt8753 5 років тому +115

    I'm Russian student and I want to express my huge thanks to The Coding Train channel! Thanks to you I have top marks in my school! The whole world loves you!!!

    • @cassandradawn780
      @cassandradawn780 5 років тому

      Я думал русских ент

    • @maximgasai1349
      @maximgasai1349 5 років тому +4

      Теперь это русский чат макс репост

    • @TheCodingTrain
      @TheCodingTrain  5 років тому +9

      Thank you!

    • @sharphurt8753
      @sharphurt8753 5 років тому +2

      @@maximgasai1349 Русские везде
      Russians everywhere

    • @user-xh9pu2wj6b
      @user-xh9pu2wj6b 5 років тому

      @@sharphurt8753 у вас в школе преподают JS? Жестко.

  • @PatrickAnimator
    @PatrickAnimator 5 років тому +15

    dude...I am obsessed. you are literally one of the best teachers Ive ever experienced.

  • @RoGeorgeRoGeorge
    @RoGeorgeRoGeorge 5 років тому +187

    @3:30 What you are calling "Amplitude" is in fact the "Peak to Peak" value. The "Amplitude" will be only half of that.

    • @TheCodingTrain
      @TheCodingTrain  5 років тому +40

      Indeed, thank you for the correction!

    • @CJBurkey
      @CJBurkey 5 років тому

      But the coefficient (often called amplitude) is the vertical peak to peak distance of the wave.

    • @NoorquackerInd
      @NoorquackerInd 4 роки тому +5

      @@CJBurkey Peak-to-Peak value isn't the coefficient or the amplitude. Peak is the absolute distance from the average of a function to either the min or max and peak-to-peak is the absolute distance from min to max. The amplitude is the peak value, and on sinusoidal functions, the peak-to-peak value is double the amplitude or peak value.
      This is more of the electrical engineer view of it, though

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

      What are you calling "peak to peak value" is in fact sometimes called "peak to peak amplitude", and what you calling "amplitude" is sometimes called "semi-amplitude".
      It's kinda similar situation as with "Natural numbers" - the name is ambiguous and it's better to refer to it either as "Positive integers" or "Non-negative integers" depending on what exactly you mean.

  • @x-lightsfs5681
    @x-lightsfs5681 5 років тому +704

    That took me -1/12 lines of code

    • @sujals7108
      @sujals7108 5 років тому +26

      Infinite lines is impossible.

    • @x-lightsfs5681
      @x-lightsfs5681 5 років тому +36

      @@sujals7108 But what if i made a code that adds a line to the js file every frame?

    • @sujals7108
      @sujals7108 5 років тому +28

      @@x-lightsfs5681 Then to make infinite lines, you would need an infinite number of frames, hence infinite time.

    • @poopmaster9984
      @poopmaster9984 5 років тому +10

      @@sujals7108 how bout making more line each frame? Then you'll get to infinity in no time :v

    • @PhoenixD
      @PhoenixD 5 років тому +16

      @@x-lightsfs5681 cant go to infinity since memory is always limited :)

  • @sirecartier7881
    @sirecartier7881 5 років тому +4

    I am a high-school student from France and I am really happy to see how great and efficient code can be with people like you!!!

  • @sobanudlz
    @sobanudlz 5 років тому +146

    *Procrastinating intensifies*

    • @AntonySimkin
      @AntonySimkin 4 роки тому

      Underrated comment lol

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

      hah, yeah

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

      hell, there are worst ways to distract yourself. programming fourier transformations is a decent way to waste your time (though time spent learning isn't wasted, I'm told)

  • @USAwizeguy
    @USAwizeguy 5 років тому +20

    As an EET major looking back at studying how to code, I love this! We look at wave forms all day. I am going to recreate this and show my fellow electrical engineers at work.

    • @SineEyed
      @SineEyed 4 роки тому

      Did you do it? Were they impressed, or at least mildly entertained?..

    • @alexandermcclure6185
      @alexandermcclure6185 Місяць тому

      please we need an update

  • @Abhishek-hy8xe
    @Abhishek-hy8xe 3 роки тому +3

    I love this channel and this guy and all the videos. Thank you .

  • @ianprado1488
    @ianprado1488 5 років тому +4

    I need to more consciously appreciate the amazing, high quality content on UA-cam. We are living in a beautiful time in history

  • @iVideo1011
    @iVideo1011 5 років тому +3

    Just stumbled across your channel. This is the best UA-cam channel I've ever seen. So many high quality videos and such great teaching and enthusiasm. I'm just speechless!

  • @snacksy7754
    @snacksy7754 4 роки тому +23

    28:28 I love that ending. *Has a good moral:* If you stumble over your words instead of trying to solve the confusion just give up, blow your flute, and say goodbye :D

  • @shashik962
    @shashik962 5 років тому +25

    My favourite channel... This is really great...

  • @HeerdyesMahapatro
    @HeerdyesMahapatro 2 роки тому +1

    Fantabulous! This needs to be taught in every DSP course!

  • @dianewilliams5830
    @dianewilliams5830 5 років тому

    Thank you. As always, you make learning so much fun. I've never been able to visualize how Fourier creates a square wave or any wave until now.

  • @zackd41
    @zackd41 5 років тому

    LOVE The Crossover with Smarter everyday, Been getting into coding because of you, thanks!

  • @oblivionronin
    @oblivionronin 4 роки тому +5

    An interesting thing that was done i think in 3blue1brown was to assign random or non-regular growing or shriking radius to the circles. Theses Fourrier series create really unique and interesting patterns, some of them event ressembing famous man made paintings.

  • @sonik382
    @sonik382 5 років тому +3

    Awesome, interesting and instructing. Thank you for all the effort you put in the channel!

  • @tmendoza6
    @tmendoza6 2 роки тому +2

    this is so freaking fantastic! I could do this all day

  • @MrSonny6155
    @MrSonny6155 4 роки тому +1

    After visualising this in the full complex form, it becomes pretty clear how higher frequencies enhance the "precision" of the wave position. I love how the whip rolls up into a tight ball with each rotation and each addition of epicycles.

  • @RicardoOliveiraRGB
    @RicardoOliveiraRGB 5 років тому +1

    It's the first video of yours i've seen, and damn! I wish my brain could think that fast for programming crazy math stuff lol. Congrats man, you got a new fan here

  • @POPO-od8jb
    @POPO-od8jb 4 роки тому +1

    Isn't it so satisfying to witness that sine waves are making rectangular wave , that ending of this video made my whole 2019 yr , and a good start of 2020 , thanks for this awesome video 🌷

  • @shannonadamj
    @shannonadamj 5 років тому +16

    Yoooo nice plugging smartereveryday. I love that channel.

  • @jonathanwalther
    @jonathanwalther 5 років тому

    Best analogy ever. Very smooth.

  • @siddhantrai7529
    @siddhantrai7529 5 років тому +1

    I love the way the best and the brightest youtube channels are inspired and motivated by each other...that is a really positive environment.... Siraj,you,smarterEveryday,3 blue 1 brown.....
    You guys really help me and many others as well .
    Thank you.

  • @gloubiboulgazeblob
    @gloubiboulgazeblob 4 роки тому

    awesome !!! The movement of all those circles radii looks so "biologic", fascinating !

  • @AliParlakci
    @AliParlakci 5 років тому +25

    1:21 Website's name actually means "science is so beautiful"

  • @izzy31337
    @izzy31337 5 років тому +34

    you always release coding challenges just when im studying a specific topic

    • @marcinkienast1134
      @marcinkienast1134 5 років тому +2

      Yeah, I'm supposed to study algorithms and time complexity proving. So... I guess I will fail the test, but I will know a bit more about FS. Totally worth it xD

    • @marcus_w0
      @marcus_w0 5 років тому +1

      Right? I was recently looking into graph plotting and stumbled upon this, too. And within a week there this video. Hee's tracking my browser history.... I have to go.

  • @jegant8216
    @jegant8216 4 роки тому

    This is a good example of coding Fourier series, thanks.

  • @maxteer2800
    @maxteer2800 5 років тому +6

    I really appreciate the goofs and slight logic mistakes on this one, it was almost more enlightening than if he had just done the thing

  • @deez_gainz
    @deez_gainz 5 років тому +7

    That refactoring song though ahah! We need 10 hour version for productive coding work!

  • @myetis1990
    @myetis1990 5 років тому +43

    You can translate
    Bilimneguzellan= Bilim+ne+ guzel +lan = Science+ what+ beautiful +guy = hey guy Science is what a beautiful thing !
    for pronounciation,
    go to google translate, select turkish , type the "Bilim ne güzel lan" and tap the voice button :)

  • @FM-kl7oc
    @FM-kl7oc 4 місяці тому

    27:18 Kinda cool illustration of aliasing that happens when the sampling rate is not a perfect multiple of the signal frequency being sampled. After increasing it to 100, sometimes you get a big spike at the corners on the square wave, sometimes not -- this is the aliasing. Sometimes you're "lucky" to sample (draw) when the tip of the pendulums are at the very top or bottom of the corner, and you get a spike. Sometimes you're "unlucky" to sample (draw) when the tip of the pendulums are not near the top or bottom, and you get a more traditional "90 degrees corner" without the spike.

  • @kavinbharathi
    @kavinbharathi 4 роки тому +1

    the slider part at the end is even more interesting as it gives even chaotic curve which when condensed give non continuous sine waves of different frequencies......*wow*

  • @MACHINEBUILDER
    @MACHINEBUILDER 5 років тому +3

    Wow awesome job it's super satisfying! :)

  • @michael-gary-scott
    @michael-gary-scott 5 років тому

    I’m actually so excited for this video

  • @HisMajesty99
    @HisMajesty99 5 років тому +2

    This was amazing, thanks for doing a video on this

  • @HardusHavenga
    @HardusHavenga 5 років тому

    Dude, you are my new hero.

  • @Wolf-gt3kd
    @Wolf-gt3kd 5 років тому +2

    This was really fun to watch that i didn't notice the video's lengh was 30min.
    Nice work really :D

  • @jerryplayz101
    @jerryplayz101 5 років тому

    4:12 - To play a musical note, the sine wave is made of multiple sine waves. You have the note you want, but you also have some overtones.

  • @eda-un8zr
    @eda-un8zr 3 роки тому +1

    I'm native Turkish and i like how you pronounce the name of the website :D and great video, thank you

  • @joecamroberon9322
    @joecamroberon9322 5 років тому

    You deserve so much more attention.

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

    Primer video que veo. Adoro!

  • @xnick_uy
    @xnick_uy 5 років тому +6

    The end result looks like a fantastic whip. WT-TSH!!

  • @user-co5ob1fv1m
    @user-co5ob1fv1m 5 років тому

    Very very useful. Thank you so much Dan

  • @shamilcarela1699
    @shamilcarela1699 5 років тому +1

    Great video, loved it.

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

    Amazing. Thank you for sharing your awesome skills.

  • @anandprakash4995
    @anandprakash4995 5 років тому

    This video inspired me to learn p5.js .Will be my new resolution to learn p5.js !!!

  • @JenishJain6
    @JenishJain6 5 років тому +1

    What a coincidence the video was suggested to me just when I was about to start Fourier series for my exam prep.👻

  • @clementlebeau484
    @clementlebeau484 5 років тому

    I’d love to see a part 2!

  • @BonsayCow
    @BonsayCow 5 років тому +1

    Fun fact at 27:20 you can see spikes on the corners of the function and this is called the Gibbs phenomenon and you can never get rid of it, due to the discontinuity of the function that you are trying to approximate.

  • @luisaisat
    @luisaisat 5 років тому +1

    thanks, yesterday i was trying this

  • @kindpotato
    @kindpotato 5 років тому

    I'm glad after a couple years of thinking about the fourier transform, I made something like what he talked about with the homer simpson being drawn,

  • @bobbymcdingdong
    @bobbymcdingdong 4 роки тому

    Brother, dude, friend Daniel, thank you!

  • @fatehaligolani7751
    @fatehaligolani7751 4 роки тому

    Thank you so much man

  • @askquestionstrythings
    @askquestionstrythings 5 років тому

    I was anticipating your video since you mentioned doing this in the smarter everyday video comments.

  • @jonathangodar4239
    @jonathangodar4239 5 років тому

    I searched on how to get the x and y values on something that had been rotated for hours. I knew that it would be something having to do with the angle and the hypotenuse, but I never found what I was looking for. I finally got the answer by some guy on Reddit this morning. Why couldn’t I have watched this video when I really needed it?

  • @mefuri_k
    @mefuri_k 5 років тому +1

    You have a great taste on youtube channels you watch

  • @AlGhifari7
    @AlGhifari7 5 років тому +20

    Hey, go to 3Blue1Browns Channel for a new video about Fourier Series!!

  • @matthewvicendese1896
    @matthewvicendese1896 5 років тому +2

    You can make
    y = negative radius sin(time) ..... because y is upside in computer land.

  • @djtygre
    @djtygre 5 років тому

    my most favorite to date

  • @Apocalypsee07
    @Apocalypsee07 5 років тому +2

    I like these Coding Challange videos :) trying to replicate these in python makes learning so much fun and also easier. Thank yyou!

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

      What do you use to draw in python? Turtle?

  • @johnnyserup5500
    @johnnyserup5500 5 років тому

    I like your approach to explanation - really interesting - cool video

  • @The.Jaynish
    @The.Jaynish 4 роки тому

    You are the best man

  • @matthewvicendese1896
    @matthewvicendese1896 5 років тому

    I am so excited !!

  • @morphyngames
    @morphyngames 5 років тому

    Thanks for making the video

  • @wesleycantarino4464
    @wesleycantarino4464 5 років тому

    this video made me study Fourier series again

  • @OonHan
    @OonHan 5 років тому

    I needed this

  • @yusufberkaygirgin9694
    @yusufberkaygirgin9694 5 років тому +7

    page's name is "bilim ne guzel lan" and it means in english "science is what a sweet thing buddy" :D

  • @engineero4945
    @engineero4945 5 років тому

    Geniuss😭. Please teach us more !

  • @anjardwisaputra1671
    @anjardwisaputra1671 5 років тому

    AMAZING!!

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

    this guy is so funny i love it

  • @buddhanag4987
    @buddhanag4987 5 років тому

    Just awesome

  • @diemirarr4728
    @diemirarr4728 5 років тому

    Amazing!

  • @aonoymousandy7467
    @aonoymousandy7467 5 років тому

    I like your train if thought, it is very helpful

  • @alajlan2012
    @alajlan2012 5 років тому +2

    this is EPIC , would you please continue uploading like this content? especially on fourier drwaing visuals?

  • @easyunderstandbanglatv7080
    @easyunderstandbanglatv7080 5 років тому

    Brother me Bangladeshi your good tips my head very easy work thank you so much brother

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

    Amazing 😄

  • @kharthigeyan
    @kharthigeyan 5 років тому

    Awesome 👍

  • @engin_karatas
    @engin_karatas 5 років тому

    I like your codding challanhes.So maybe I will learn js

  • @bobbyfinn8404
    @bobbyfinn8404 5 років тому +1

    You are amazing

  • @Amirkheir
    @Amirkheir 5 років тому

    amazing. Wow

  • @basement3301
    @basement3301 5 років тому

    this is so much fun

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

    Thanks!

  • @parvezmahmud6963
    @parvezmahmud6963 4 роки тому

    You are the bestest ❤

  • @bmw123ck
    @bmw123ck 5 років тому

    i come from 3b1b and i barely know coding, but i just subscribed...

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

    great video

  • @johnvonhorn2942
    @johnvonhorn2942 5 років тому

    This guy is the smartest guy in the neighborhood - the Mr Rogers of code.

  • @smanzoli
    @smanzoli 5 років тому

    Interesting to see the fractal tree branches being produced here by the circles radiuses 23:50

  • @alonh.4968
    @alonh.4968 4 роки тому

    OMG, I like this channel a lot! thank you and, btw, how did you cancel the auto-fill? 😂

  • @Forced2
    @Forced2 5 років тому +2

    Is it just me or is this pattern of circles rotating around eachother looking like a whip when it reaches a hundred.
    Maybe this is how a whip delivers such a fatal blow.

  • @fbubbar
    @fbubbar 4 роки тому +6

    Tries to type stroke
    Accidentally types MediaStreamTrackAudioSourceNode

  • @carlosagorreta5276
    @carlosagorreta5276 5 років тому

    that was impressive

  • @GhomezAnonimous
    @GhomezAnonimous 4 роки тому

    Attempted JAVA translation - ua-cam.com/video/H6T7dyfcXW0/v-deo.html

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

    Something interesting at 27:46 when those circles come around they almost *slap* the square wave and it changes the spikes at the corner of the square wave lol

  • @BaronVonTacocat
    @BaronVonTacocat 5 років тому

    Sweet!