95. Fourier Transform? Square Wave? Frequency? Period? Do I need to know these when studying Embedded Software?

Toby
4 min readDec 23, 2023

Today, I’m going to write a very interesting piece.

First, let me plot the function sin(2*pi*t) over time.

The graph looks like the following:

Starting from 0, returning to 0 is considered one period.

In this case, you can see that the period is 1 second.

The frequency is calculated as 1/period, which is 1Hz.

Now, I’m going to create a waveform with a frequency of 2Hz.

The graph looks like this:

The period is 0.5 seconds,

and the frequency is calculated as 1/0.5, which equals 2Hz.

Now, let’s conduct an interesting experiment.

What kind of graph do you think we’ll get with ssin(2*pi*t)+sin(2*pi*2*t)?

You can see that a peculiar waveform emerges, as shown below:

If we perform frequency analysis on the above function,

we will identify frequencies of 1Hz and 2Hz.

Now, let’s assume we’ve obtained the waveform and try a frequency analysis.

Can you see it? Assuming we have the function x, obtained using a frequency analysis function supported by MATLAB, and passing it through the fft function for frequency spectrum analysis,

we can confirm that it has frequencies of 1Hz and 2Hz.

What I wanted to convey is that I laid the groundwork to explain Fourier Transform.

The essence of Fourier Transform is that any signal can be expressed as a combination of sine and cosine functions.

Signal = a1*sin(2*pi*b1*t) + c1*cos(2*pi*d1*t) +

a2*sin(2*pi*b2*t) + c2*cos(2*pi*d2*t) +

a3*sin(2*pi*b3*t) + c3*cos(2*pi*d3*t) …..

This means that any signal can be represented in this form.

Now, let’s take a look at the most commonly used signals in the world of embedded software.

One of them is the square wave (or rectangular wave).

PWM signals are generated using this waveform, and Digital Input/Output signals often exhibit this waveform as well.

The principle is similar for Input Capture as well.

So, through Fourier Transform, we should be able to express square waves (rectangular waves) as a combination of sine and cosine functions.

The formula is as follows:

A sinusoidal wave (square wave) with a period of f and amplitude A can be represented as the sum of sine functions, as shown above.

Let’s assume a period of 1 and an amplitude of 1.

The formula would be:

y = (4/pi) * ((sin2*pi*t) + (sin2*pi*3*t)/3 + (sin2*pi*5*t)/5 + (sin2*pi*7*t)/7 ….)

Now, let’s simulate and observe how the waveform looks by gradually increasing the value of K:

y1 = 4/pi*(sin(2*pi*t));
y2 = 4/pi*(sin(2*pi*t)+ sin(2*pi*3*t)/3);
y3 = 4/pi*(sin(2*pi*t)+ sin(2*pi*3*t)/3 + sin(2*pi*5*t)/5);
y4 = 4/pi*(sin(2*pi*t)+ sin(2*pi*3*t)/3 + sin(2*pi*5*t)/5 + sin(2*pi*7*t)/7);
y5 = 4/pi*(sin(2*pi*t)+ sin(2*pi*3*t)/3 + sin(2*pi*5*t)/5 + sin(2*pi*7*t)/7 + sin(2*pi*9*t)/9);
y6 = 4/pi*(sin(2*pi*t)+ sin(2*pi*3*t)/3 + sin(2*pi*5*t)/5 + sin(2*pi*7*t)/7 + sin(2*pi*9*t)/9 + sin(2*pi*11*t)/11);

It’s evident that as the value of K increases gradually and more terms are added, the waveform increasingly resembles a square wave, as shown below:

It’s indeed a fascinating discovery.

Now, let’s perform frequency analysis on this waveform.

Can you see it?

1Hz, 3Hz, 5Hz, 7Hz…

are visible.

And the sizes of the peaks on the y-axis represent the influence based on amplitude.

That’s correct.

This is the frequency spectrum of the square wave.

So, what would be the frequency spectrum of a DC voltage or current?

It would be 0 since there is no periodicity.

Sure, in the next section, let’s explore analog and digital signals. Stay tuned!

--

--