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.

# Finding Fourier coefficients for square wave

Finding Fourier coefficients for a square wave. Created by Sal Khan.

## Want to join the conversation?

• At , Sal said there will be no b sub 4 term. Why is that? • Wouldn't a square wave not be a function since every T/2 (where T is the period) it is perfectly vertical which violates the VLT or in other words you have all y's from the top to the bottom of the wave for those x values? • This is a really good question. It is a good example of our quest for beautiful tidy mathematical rigor bumping up against something that is super useful in real life, in this case, the highly non-linear square wave. We need to exercise some flexibility in order to resolve the conflict.

Wolfram lists three ways to analytically represent a square wave using functions. (http://mathworld.wolfram.com/SquareWave.html). Another way to compose a square wave is as an infinite sum of sine waves (as in this Fourier Series video sequence). Each individual sine wave component is a proper function that passes the Vertical Line Test. Until the limit gets all the way to infinity, there is always a slope to the function as it passes through its transition.

Another similar place this puzzle arrises in signal processing where we have the concept of the Dirac Delta Function (https://en.wikipedia.org/wiki/Dirac_delta_function). Again, there are very sudden changes in value that you have to hold in your head. The way I accept these ideas is to understand them as (and believe them to be) the limits of more reasonable functions.

Also check out the value of the sinc function, sin (x) / x, when x = 0. Another mind bender.
• hold on, in the middle of the video, Khan replaces f(t) in the integral with 3. Isn't that not possible to do in calculus? I think you have to do integration by parts • When he introduces the n/n trick to make the integration of cos(nt) and sin(nt) easier, it threw me off. Is there a lesson on here where he explains that some more?
(1 vote) • Just before Sal is getting ready to evaluate an integral of sin(nt). The "n" inside the sine makes this a little tricky. Sal often thinks about an integral as an anti-derivative. If he knows how to take a derivative of something, then its easy to run the process in the opposite direction to get the integral. He's better at remembering his derivatives. In this example he considers the derivative of a cosine function because he knows it always ends up as some sort of sine function. The derivative of cosine is -sine. Then he slips an "n" into the cosine...

At Sal thinks aloud, "We know the derivative of cos(nt) = -n sin(nt)

This gives him an expression that includes sin(nt), the term inside his integral. But his antiderivative equation said aloud at also has an "n" term that's not currently part of the integral he wants to solve. He can run this equation in the opposite direction (take the integral of sin(nt) IF he can fiddle around and somehow include the leading "n" term as well.

So he just sticks in an "-n" term into the integral because he feels like it, and then includes a -1/n on the outside of the integral to repair the "damage".

Once he has -n sin(nt) inside the integral he runs the antiderivative equation backwards at to solve the integral, resulting in cos(nt).

I don't think this is a standard calculus method for doing integrals, but it clearly in Sal's bag of tricks. It's an interesting perspective on how to attack integrals.
• does the curly S he draws at mean interval? • if my f(x) = pi+x , and its between (-pi,pi) how does that change things? • At , Sal said our function is equal to three. Why is that?
(1 vote) • Why there isn't a b sub zero term?
(1 vote) • If I'm applying Fourier analysis and Fourier transform to comparing the sound waves of a piano and a cello, how would i go about this?
(1 vote) • Step 1: Make a recording of each instrument in digital form. For example, record a single note (A440 or middle-C for example) for 1 second with a sample rate of 20,000 samples/second.

Step 2: Perform Fourier transforms on each tone file on a computer to extract the frequency content of each tone. The computer algorithm for Fourier transforms is called an FFT (Fast Fourier Transform). Programs like Matlab or Octave (free) have an FFT module.

Step 3: Overlay the two results in different color. The highest peak in both will be at the primary tone, A440 or middle-C. You will see smaller peaks (overtones) at octaves above the fundamental tone. And you will also see even smaller peaks at other frequencies due to non-linearities in the two instruments.

The overtones and non-linear sounds are how your ear can tell the same note on a piano apart from a cello.
• I'm applying the Fourier Transform to a wire mesh with a separation between wires at a different interval than the actual width of the wire. How would I be able to write this in terms of the Fourier series with the maximum and minimums at different intervals from each other? Or can we make the assumption that they are the same.

The exact difference is the wires have difference of ~92 microns, the separation between wires is ~120 microns.

I also have another question about the video specifically, around the time, you pulled 'n' out from the integral and put in the denominator. Why?
(1 vote) • If your wire mesh was a time-based signal, it would look like a pulse train where the pulse height was less than half the period. Look for guidance on the web: the Fourier transform of a pulse train where the "duty cycle" is not 50%.

Just before Sal pulls a trick where he introduces a factor of n/n, the top n is inside the integral and the 1/n is in front of the integral. The reason for this is is to get an easier evaluation of the antiderivative of the term n cos(nt) compared to evaluating the antiderivative of cos(nt).