Creating a square wave from a sum of sinusoids
This example shows how to compose a rectangular signal from a sum of sinusoids, adding them one by one, with parameters that can be obtained using the Fourier decomposition (its odd part).
Let's summarize the sinusoids
Create a vector varying from 0 to 10 in increments of 0.1, and take the sine of each of the values in this vector. Let's plot the main harmonic component of our signal.
t = 0:.1:10;
y = sin.(t);
plot( t, y )
Add the third harmonic to the main harmonic and plot the graph.
y = sin.(t) + sin.( 3t )./3;
plot(t,y)
Now let's have all the odd harmonics up to the ninth on the graph.
y = @. sin(t) + sin(3t)/3 + sin(5t)/5 + sin(7t)/7 + sin(9t)/9;
plot(t,y)
We used the operator @. to avoid adding a vectorization indicator . to each function individually, but instead make the entire expression vector.
At the end of the demonstration, we will build several graphs in which the sum of the odd harmonics will gradually accumulate, and thus we will reach the 19th component.
t = 0:0.02:3.14;
y = zeros(10,length(t));
x = zeros(size(t));
for k = 1:2:19
x = x .+ sin.(k*t)./k;
y[Int32((k+1)/2),:] = x;
end
plot( y[1:2:9,:]', leg=false,
title="Накопление синусоид и приближение к прямоугольной функции")
The behavior of the sum of a harmonic series in the vicinity of a discontinuity point is sometimes called the * Gibbs effect*. According to the observed effect, adding a large number of sinusoids will lead to the fact that the excess of the signal level we need at the break point tends to 9%, although the error integral will tend to zero.
Conclusion
We have studied a small example that allows us to understand how the Fourier transform works and where some types of interference in the transmission of pulse signals come from.