If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Visualizing the Fourier expansion of a square wave

Visualize the Fourier expansion of a square wave. A square wave can be approximated by adding odd harmonics of a sine wave. Created by Sal Khan.

Want to join the conversation?

  • male robot donald style avatar for user Gleb Beliaev
    Sal, are you going to make videos about how to solve differential equations with help of Fourier transform?
    (40 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user Shushma Gudla
    can we see the general form for a function that doesn't have 2pi as its period?
    (25 votes)
    Default Khan Academy avatar avatar for user
    • male robot hal style avatar for user Sean
      You could derive it for any interval, but you have to go back to the beginning and compute the definite integral of sin(mt) cos(nt) and their products, etc. just like Sal did in the first few videos, and then use those results.
      (9 votes)
  • starky tree style avatar for user Alasdair Mitchell
    What is the Fourier Series used for?

    Is it used to convert signals into data which can then be edited and transported digitally and then converted back to a signal at the destination?
    (8 votes)
    Default Khan Academy avatar avatar for user
    • purple pi purple style avatar for user APDahlen
      Hello Alasdair,

      The Fourier series is a description of a waveform such as a square or triangle wave. It helps us think about electric circuits.

      The Fourier transform is a mathematical construct (algorithm ) that allows us to convert a signal such as a square or triangle waveform to constituent sinusoids.

      The actual conversion (real circuits) use Analog to Digital Converters (ADC) and Digital to Analog Converters (DAC) to convert real world signal to digital and then back again.

      Regards,

      APD
      (18 votes)
  • aqualine ultimate style avatar for user Rohan Suri
    Do we have Fourier series for only 2π periodic functions?
    (6 votes)
    Default Khan Academy avatar avatar for user
    • leafers ultimate style avatar for user Florence Tsang
      Not really. For any functions of the period T = 2π/ω, you can replace the cos(nt) and sin(nt) with cos(nωt) and sin(nωt). The limits of integration will range between -π/ω and π/ω. Now instead of 1/π in front of the integral at the final step, you will have ω/π. For the examples in the videos, T = 2π gives us ω = 2π/2π = 1, hence why at the final step we have 1/π.
      (7 votes)
  • blobby green style avatar for user CyVX
    How come there are no more videos on solving problems
    (8 votes)
    Default Khan Academy avatar avatar for user
  • marcimus pink style avatar for user Aaiyeesha Mostak
    Sal, can we have some videos on solving partial differentiation equation by fourier transform? That would be very helpful.
    (5 votes)
    Default Khan Academy avatar avatar for user
  • orange juice squid orange style avatar for user Ali Salloum
    So how is this all related to the fourier transform of integral of e^(-i*2*pi*t*v) * s(t), where s is some function?
    (3 votes)
    Default Khan Academy avatar avatar for user
    • male robot donald style avatar for user Maxime
      As you know from Eulers formula e^ix=i*sin(x)+cos(x). So in that exponent-thing you have and a sine wave and a cosine wave, separated by the imaginary unit i. By taking the integral of that, you can simultaneously compute and the amplitudes for the sine, and that for the cosine. As answer you will get a complex number where the real part in for the cosine and the imaginary part for the sine.
      (3 votes)
  • female robot ada style avatar for user CHRISTINA
    At Sal says, "You can type these things into Google..." and then he showed a bunch of graphs getting closer and closer to f(t). I tried typing the function (the first few terms anyway) into Google, and was just directed to a bunch of sites. Can you be more specific? I would love to try it!
    (1 vote)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user aadil.khalil15
    These were really tremendous sessions. Thanks for your valuable approach.. Could you please let us know that Is it the same fourier transform which is being used in the PID controllers for calculating errors and adding it up to the assigned values in order to have the desired process values...
    Thanks!
    Regards,
    Muhammad Adil
    (2 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user JOHANN WEGMANN
    Hallo,thanks for Fourier,I think its as powerfull as Eulers exponent function,integration of difficult integrals with algorithms of numerical analysis,are much,and probably codes of math might solve terarively,Runge Kutta,Newton Raphson or just Simpsons rule,this is so powerfull,let me try to change RC exponential into sines and cosines to trigonometrical function I never did, then I will jump into CRC theoretical reversed CAPS and Rload, to check if resonance is possible under controlled polarituy of bat or of CAPs 1 and 2.Is just a feeling,beyond the reason is mathematics, without mathematics and Physics no engineers, without FEA nothing at all.Regards JOhann Wegmann.
    (1 vote)
    Default Khan Academy avatar avatar for user

Video transcript

- [Voiceover] So we started with a square wave that had a period of two pi, then we said, hmm, can we represent it as an infinite series of weighted sines and cosines, and then working from that idea, we were actually able to find expressions for the coefficients, for a sub zero and a sub n when n does not equal zero, and the b sub ns. And evaluating it for this particular square wave, we were able to get that a sub n is going to be equal, or a sub zero is going to be 3/2, that a sub n is going to be equal to zero for any n other than zero, and that b sub n is going to be equal to zero if n is even and six over n pi if n is odd. So one way to think about it, you're gonna get your a sub zero, you're not gonna have any of the cosine terms, and you're only going to have the odd sine terms. And if you think about it just visually, if you look at the square wave, it makes sense that you're gonna have the sines and not the cosines because a sine function is gonna look something like this. So a sine function is gonna look something like this, while a cosine function looks something like, let me make it a little bit neater, a cosine function would look something like that. And so a cosine and multiples of cosine of two x, cosine of three x, is gonna be out of phase, while the sine of x, or I should say cosine of ts and the sines of ts, sine two t, sine three t, is gonna be more in phase with the way this function just happened to be. So it made sense that our a sub ns were all zero for n not equaling zero. And so based on what we found for our a sub zero, and our a sub ns, and our b sub ns, we could expand out this actual, we did in the previous video, what is this Fourier series actually look like? So 3/2 plus six over pi sine of t plus six over three pi sine of three t plus six over five pi sine of five t, and so on and so forth. And so a lot of you might be curious what does this actually look like. And so I actually just, you can type these things into Google and it will just graph it for you. And so this right over here is just the first two terms. This is 3/2 plus six over pi sine of t. And notice it's starting to look right because our square wave looks something like, it goes, it looks something like this. So it's gonna go like that and then it's gonna go down to zero and then it's gonna go up, looks something like that. It doesn't have the pis and the two pis marked off between these because it's gonna look something like that. So even just the two terms, it's kind of a decent approximation for even two terms, but then as soon as you get to three terms, if you add the six over three pi sine of three t to the first two terms. So if you look at these first three terms, now it's looking a lot more like a square wave. And then if you add the next term, well, it looks like even more like a square wave, and then if you add to that what we already wrote down here, if you were to add to that six over seven pi times sine of seven t, it looks even more like a square wave. So this is pretty neat. You can visually see that we were actually able to do it. And it all kind of just fell out from the mathematics.