Coding Challenge 125: Fourier Series

Sdílet
Vložit
  • čas přidán 1. 07. 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: czcams.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

Komentáře • 508

  • @vigneshwarm
    @vigneshwarm Před 5 lety +978

    3blue1brown recommended this video for his Fourier transform video

    • @akremhadji7326
      @akremhadji7326 Před 5 lety +11

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

    • @FilthyManatee
      @FilthyManatee Před 5 lety +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 Před 5 lety +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 Před 5 lety +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 Před 5 lety +3

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

  • @jonnylinford
    @jonnylinford Před 5 lety +207

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

  • @carlosmorasalguero
    @carlosmorasalguero Před 5 lety +300

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

  • @oscard4801
    @oscard4801 Před 5 lety +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  Před 5 lety +32

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

    • @GodofChookie
      @GodofChookie Před 5 lety +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 Před 5 lety +3

      Awesome keep it up

    • @LongLe-nt8bv
      @LongLe-nt8bv Před 5 lety +1

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

    • @oscard4801
      @oscard4801 Před 5 lety +5

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

  • @ibuucoksiregar9024
    @ibuucoksiregar9024 Před 4 lety +13

    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❤️❤️

  • @RoGeorgeRoGeorge
    @RoGeorgeRoGeorge Před 5 lety +185

    @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  Před 5 lety +40

      Indeed, thank you for the correction!

    • @CJBurkey
      @CJBurkey Před 5 lety

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

    • @NoorquackerInd
      @NoorquackerInd Před 4 lety +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 Před 3 lety +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 Před 5 lety +703

    That took me -1/12 lines of code

    • @sujals7108
      @sujals7108 Před 5 lety +26

      Infinite lines is impossible.

    • @x-lightsfs5681
      @x-lightsfs5681 Před 5 lety +36

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

    • @sujals7108
      @sujals7108 Před 5 lety +28

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

    • @poopmaster9984
      @poopmaster9984 Před 5 lety +10

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

    • @PhoenixD
      @PhoenixD Před 5 lety +16

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

  • @sharphurt8753
    @sharphurt8753 Před 5 lety +116

    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 Před 5 lety

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

    • @maximgasai1349
      @maximgasai1349 Před 5 lety +4

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

    • @TheCodingTrain
      @TheCodingTrain  Před 5 lety +9

      Thank you!

    • @sharphurt8753
      @sharphurt8753 Před 5 lety +2

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

    • @user-xh9pu2wj6b
      @user-xh9pu2wj6b Před 5 lety

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

  • @PatrickAnimator
    @PatrickAnimator Před 5 lety +15

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

  • @sirecartier7881
    @sirecartier7881 Před 5 lety +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!!!

  • @ianprado1488
    @ianprado1488 Před 5 lety +4

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

  • @iVideo1011
    @iVideo1011 Před 5 lety +3

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

  • @shashik962
    @shashik962 Před 5 lety +25

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

  • @USAwizeguy
    @USAwizeguy Před 5 lety +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 Před 4 lety

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

    • @alexandermcclure6185
      @alexandermcclure6185 Před měsícem

      please we need an update

  • @sobanudlz
    @sobanudlz Před 5 lety +146

    *Procrastinating intensifies*

    • @AntonySimkin
      @AntonySimkin Před 4 lety

      Underrated comment lol

    • @TheFishKing64
      @TheFishKing64 Před 3 lety

      hah, yeah

    • @unlikelysalmon786
      @unlikelysalmon786 Před 3 lety

      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)

  • @dianewilliams5830
    @dianewilliams5830 Před 5 lety

    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.

  • @Abhishek-hy8xe
    @Abhishek-hy8xe Před 3 lety +3

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

  • @zackd41
    @zackd41 Před 5 lety

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

  • @shannonadamj
    @shannonadamj Před 5 lety +16

    Yoooo nice plugging smartereveryday. I love that channel.

  • @tmendoza6
    @tmendoza6 Před 2 lety +2

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

  • @sonik382
    @sonik382 Před 5 lety +3

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

  • @HeerdyesMahapatro
    @HeerdyesMahapatro Před 2 lety +1

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

  • @RicardoOliveiraRGB
    @RicardoOliveiraRGB Před 5 lety +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 Před 4 lety +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 🌷

  • @jonathanwalther
    @jonathanwalther Před 5 lety

    Best analogy ever. Very smooth.

  • @MrSonny6155
    @MrSonny6155 Před 5 lety +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.

  • @siddhantrai7529
    @siddhantrai7529 Před 5 lety +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.

  • @MACHINEBUILDER
    @MACHINEBUILDER Před 5 lety +3

    Wow awesome job it's super satisfying! :)

  • @michael-gary-scott
    @michael-gary-scott Před 5 lety

    I’m actually so excited for this video

  • @snacksy7754
    @snacksy7754 Před 4 lety +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

  • @gloubiboulgazeblob
    @gloubiboulgazeblob Před 5 lety

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

  • @HisMajesty99
    @HisMajesty99 Před 5 lety +2

    This was amazing, thanks for doing a video on this

  • @jegant8216
    @jegant8216 Před 4 lety

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

  • @BillyBustamante
    @BillyBustamante Před 3 lety

    Primer video que veo. Adoro!

  • @oblivionronin
    @oblivionronin Před 4 lety +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.

  • @Wolf-gt3kd
    @Wolf-gt3kd Před 5 lety +2

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

  • @deez_gainz
    @deez_gainz Před 5 lety +7

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

  • @HardusHavenga
    @HardusHavenga Před 5 lety

    Dude, you are my new hero.

  • @matthewvicendese1896
    @matthewvicendese1896 Před 5 lety

    I am so excited !!

  • @maxteer2800
    @maxteer2800 Před 5 lety +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

  • @kavinbharathi
    @kavinbharathi Před 4 lety +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*

  • @joecamroberon9322
    @joecamroberon9322 Před 5 lety

    You deserve so much more attention.

  • @jerryplayz101
    @jerryplayz101 Před 5 lety

    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.

  • @bertronixtv
    @bertronixtv Před rokem

    Amazing. Thank you for sharing your awesome skills.

  • @djtygre
    @djtygre Před 5 lety

    my most favorite to date

  • @anandprakash4995
    @anandprakash4995 Před 5 lety

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

  • @AlGhifari7
    @AlGhifari7 Před 5 lety +20

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

  • @shamilcarela1699
    @shamilcarela1699 Před 5 lety +1

    Great video, loved it.

  • @mefuri_k
    @mefuri_k Před 5 lety +1

    You have a great taste on youtube channels you watch

  • @user-co5ob1fv1m
    @user-co5ob1fv1m Před 5 lety

    Very very useful. Thank you so much Dan

  • @myetis1990
    @myetis1990 Před 5 lety +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 :)

  • @fatehaligolani7751
    @fatehaligolani7751 Před 4 lety

    Thank you so much man

  • @xnick_uy
    @xnick_uy Před 5 lety +6

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

  • @askquestionstrythings
    @askquestionstrythings Před 5 lety

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

  • @The.Jaynish
    @The.Jaynish Před 4 lety

    You are the best man

  • @FM-kl7oc
    @FM-kl7oc Před 5 měsíci

    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.

  • @izzy31337
    @izzy31337 Před 5 lety +34

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

    • @marcinkienast1134
      @marcinkienast1134 Před 5 lety +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 Před 5 lety +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.

  • @Apocalypsee07
    @Apocalypsee07 Před 5 lety +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 Před rokem

      What do you use to draw in python? Turtle?

  • @kindpotato
    @kindpotato Před 5 lety

    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,

  • @AliParlakci
    @AliParlakci Před 5 lety +25

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

  • @OonHan
    @OonHan Před 5 lety

    I needed this

  • @anjardwisaputra1671
    @anjardwisaputra1671 Před 5 lety

    AMAZING!!

  • @luisaisat
    @luisaisat Před 5 lety +1

    thanks, yesterday i was trying this

  • @jonathangodar4239
    @jonathangodar4239 Před 5 lety

    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?

  • @clementlebeau484
    @clementlebeau484 Před 5 lety

    I’d love to see a part 2!

  • @johnnyserup5500
    @johnnyserup5500 Před 5 lety

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

  • @bobbymcdingdong
    @bobbymcdingdong Před 5 lety

    Brother, dude, friend Daniel, thank you!

  • @diemirarr4728
    @diemirarr4728 Před 5 lety

    Amazing!

  • @JenishJain6
    @JenishJain6 Před 5 lety +1

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

  • @morphyngames
    @morphyngames Před 5 lety

    Thanks for making the video

  • @BonsayCow
    @BonsayCow Před 5 lety +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.

  • @eda-un8zr
    @eda-un8zr Před 3 lety +1

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

  • @matthewvicendese1896
    @matthewvicendese1896 Před 5 lety +2

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

  • @rafaelamaral7756
    @rafaelamaral7756 Před 2 lety

    this guy is so funny i love it

  • @buddhanag4987
    @buddhanag4987 Před 5 lety

    Just awesome

  • @engineero4945
    @engineero4945 Před 5 lety

    Geniuss😭. Please teach us more !

  • @BaronVonTacocat
    @BaronVonTacocat Před 5 lety

    Sweet!

  • @iHardikPatel
    @iHardikPatel Před rokem

    Amazing 😄

  • @basement3301
    @basement3301 Před 5 lety

    this is so much fun

  • @aonoymousandy7467
    @aonoymousandy7467 Před 5 lety

    I like your train if thought, it is very helpful

  • @parvezmahmud6963
    @parvezmahmud6963 Před 4 lety

    You are the bestest ❤

  • @kharthigeyan
    @kharthigeyan Před 5 lety

    Awesome 👍

  • @wesleycantarino4464
    @wesleycantarino4464 Před 5 lety

    this video made me study Fourier series again

  • @engin_karatas
    @engin_karatas Před 5 lety

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

  • @alajlan2012
    @alajlan2012 Před 5 lety +2

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

  • @oxydol3456
    @oxydol3456 Před 2 lety

    Thanks!

  • @smanzoli
    @smanzoli Před 5 lety

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

  • @sidim.aourid9958
    @sidim.aourid9958 Před 5 lety

    The amplitude is from axis x to max or to min. Example if, s(t) = a sin(t), a is the amplitude. Thank you for all your videos, they are instructive and well done.

  • @Amirkheir
    @Amirkheir Před 5 lety

    amazing. Wow

  • @bobbyfinn8404
    @bobbyfinn8404 Před 5 lety +1

    You are amazing

  • @easyunderstandbanglatv7080

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

  • @leonardopotenza7379
    @leonardopotenza7379 Před 5 lety

    Love you Daniel

  • @bendunselman
    @bendunselman Před 7 měsíci

    Very nicely done! You could also add some p5.sound and explain vibrato, tremolo and other sound effects.....

  • @yusufberkaygirgin9694
    @yusufberkaygirgin9694 Před 5 lety +7

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

  • @iqbaltrojan
    @iqbaltrojan Před 4 lety +1

    27:38 - 27:40 there is a time where the line is near horizontal facing right! pause and use the , (comma) and . (period/full stop) to go back/forward by 1 frame
    edit: press 27:38 then wait for it to go right
    edit 2: 27:55 also
    edit 3: also at 27:54 it's at a very high point (right side)

    • @SreenikethanI
      @SreenikethanI Před 4 lety

      hehe yeah even I noticed that, when all the circles are extended to the right, it essentially cuts the wave!!!

  • @calebsherman886
    @calebsherman886 Před 5 lety

    SmarterEveryDay!

  • @carlosagorreta5276
    @carlosagorreta5276 Před 5 lety

    that was impressive

  • @adilkhatri7475
    @adilkhatri7475 Před 5 lety

    Epiccccccc!!!!

  • @alonh.4968
    @alonh.4968 Před 4 lety

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

  • @tooljockey2777
    @tooljockey2777 Před 2 lety

    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