Signals and Systems Part 2: Fourier Series

Lesson 7: The Cosine Fourier Series


Can we represent any signal this way?

So in the last lesson on Fourier Series we saw we could represent a square wave as an infinite sum of sinewaves, but is that always the case? For example, what if we shifted the square wave? So instead of being positive from \(0\) to \(\pi\), and negative from \(\pi\) to \(2\pi\), it looks like this (plotted over two periods):

In other words, the square wave is now even. Does this change our Fourier Coefficients? Well, let's compute them again and see if they change. We need to multiply our new square wave by a sinewave and integrate that over a period. Here I chose \(-\pi\) to \(\pi\), to do the integration, instead of \(0\) to \(2\pi\), which is totally fine, and it will help to make a point. Let's call this new signal \(sq_e\) instead of just \(sq\), to distinguish it from the odd square wave:

\begin{equation} b_n = \frac{2}{P}\langle sq_{e}(x), sin(x) \rangle = \frac{2}{2\pi} \int_{-\pi}^{\pi}sq_{e}(x)sin(x)dx \end{equation}

You can do the integral, or you can just plot what the two look like when multiplied together:

Notice anything? This is an odd function, which we should have expected, because we are multiplying an even signal (our shifted square wave) by an odd one (a sinewave). If we integrate this, everything cancels, with the negative regions being matched by positive regions. Well, this was just the first coefficient. What about \(b_2\), where we multiply by \(sin(2x)\)? What does that look like?

It's the same thing again. The positive regions look like they get canceled by the negative ones. You could keep doing this for higher and higher frequencies, and you would keep seeing the same thing over and over again.

Orthogonal Signals

What do all of the Fourier Coefficients being zero mean? It means that we cannot create an even signal out of a bunch of odd ones. We might have expected this since even and odd signals are orthogonal - each contains none of the other. In order to make an even signal, then, we need a bunch of even signals. We need to use cosines.

The Cosine Fourier Series

Let's try instead to use cosines, rather than sinewaves, to construct the square wave. We need to ask the question how much of a cosine is in our square wave? Now, after alreading going through this once before, we know how to answer this question - we just need to use the inner product. As with the sinewaves, though, there is a \(\frac{2}{P}\) out front - we want to make sure that if our signal is purely a cosine, then the 'amount of cosine' in it is 1. Let's try to compute how much of \(cos(x)\) is in our square wave. First, let's plot the two to see what they look like together:

It does look like they have a great deal of overlap - so we might suspect there is some cosine to be found in our square wave, but how much? Want to take a guess? Let's actually do the integral:

\begin{equation} \frac{2}{P}\langle sq_{e}(x), cos(x) \rangle = \frac{2}{2\pi} \int_{-\pi}^{\pi}sq_{e}(x)cos(x)dx \end{equation}

How much cosine is there in our shifted square wave?





Solution

We can do the integral either in three pieces, or we can instead do it in two pieces over a slightly different region, say from \(-pi/2\) to \(3\pi/2\). All that matters is that we cover a single period. From the region \(-\pi/2\) to \(\pi/2\), we just need to integrate 1*cos(x), since the square wave is equal to \(+1\) in this region. This integrates out to \(2/\pi\). The second region, from \(\pi/2\) to \(3\pi/2\), looks exactly the same as the first (cosine is negative in that region, and so is the square wave, so multiplied together they become positive), and this also integrates out to \(2/\pi\).

Interesting... it's the same exact value we got for the sinewave inside the odd square wave (the non-shifted one). In fact, if you calculate how much \(cos(nx)\) is in our shifted square wave, you get the following: \begin{equation} a_n=\frac{4}{n\pi} sin\left(\frac{n\pi}{2}\right) \end{equation}

These are also Fourier Coefficients, but for cosines rather than sines, and the nth cosine Fourier Coefficient is denoted \(a_n\). (remember I told you we would meet the letter a? :))

What are the second and third cosine Fourier coefficients in the example above?





Notice that they are excatly the same as the Fourier Coefficients in the sin() case, but now some of them are negative. This has to do with the maxima of the \(cos(nx)\) function being stuck at 0 - so we can't just keep adding more and more cosines together with the same sign, or this region would blow up (when we want it to converge to 1). This wasn't a problem with the sin() case.

But what does it even mean for there to be negative cosines in our square wave? Well, it just means that if you want to make a square wave out of cosines, you better multiply some by positive coefficients, and some by negative coefficients. If we plot just the first cosine multiplied by \(a_1\), the first Fourier Coefficient, we get something that looks like this:

If we add \(a_3*cos(3x)\) to that (and remember, \(a_3\) is negative, we get:

We can keep adding and adding appropriately-multiplied cosines, here's up to \(a_{25}*cos(25x)\):

And eventually, as in the case with sinewaves, if we add enough terms the square wave starts to look indistinguishable from the sum of cosines (adding up to \(a_{200}*cos(200x)\):

Representing any periodic signal

We've now seen that when our square wave was odd (as in the last lesson), we could build it out of a bunch of other odd signals - sinewaves. But when our square wave was even (in this lesson), we needed a bunch of even signals (cosines) to create it. But what if our signal was neither even nor odd? Well, remember that we can always 'decompose' a signal into its even parts and its odd parts. So if we had a signal that was neither even nor odd, we could create it using one signal that is even, and one signal that is odd. The odd signal is made up only of sine waves (and we can figure out their coefficients, \(b_n\)), and the even signal only of cosines (whose coefficients are \(a_n\). But there's one more subtlety we have to cover before we can represent any periodic signal, and that's dealing with offsets.




If you found this content helpful, it would mean a lot to me if you would support me on Patreon. Help keep this content ad-free, get access to my Discord server, exclusive content, and receive my personal thanks for as little as $2. :)

Become a Patron!