MATLAB sine wave superposition is converted into square wave odd harmonic composition

Mondo Workplace Updated on 2024-01-29

Sine wave is familiar to everyone, so to convert into a square wave, here is a first introduction to what is harmonics, harmonics are the Fourier series decomposition of the periodic ** flow, and the frequency is a component with a frequency greater than 1 integer multiple of the fundamental wave (the same component with the frequency as the power frequency (50Hz)).

When the harmonic frequency is 3 times the fundamental frequency, the wave is called the third harmonic, the wave with the fundamental frequency 5 times is called the fifth harmonic, and so on, such an odd multiple of the wave is the odd harmonic. Generally, due to the pressure of the sinusoidal voltage on the nonlinear load, the fundamental current is distorted to produce harmonics.

The main nonlinear loads are UPS, switching power supply, rectifier, inverter, inverter, etc.

Here we will take a look at how to convert into a square wave through the superposition of sine waves, of course, there is a Gibbs effect here, so it will never actually be converted into a square wave, it is an approximation, and this Gibbs phenomenon will be explained again later. #matlab#

MATLAB sine waves are superimposed into square waves.

% Let's start with a fundamental frequency diagram.

t = 0:.1:2*pi;

y = sin(t);

plot(t,y);

% to add a third harmonic.

y = sin(t) +sin(3*t)/3;

plot(t,y);

% Add some more odd harmonics.

y = sin(t) +sin(3*t)/3 + sin(5*t)/5 + sin(7*t)/7 + sin(9*t)/9;

plot(t,y);

We can see that the more odd harmonics are added, the closer this sine wave is to a square wave.

% loops to add more odd harmonics.

t = 0:.02:2*pi;

y = zeros(10,length(t));

x = zeros(size(t));

for k = 1:2:29

x = x + sin(k*t)/k;

y((k+1)/2,:)= x;

endplot(y(:,')

plot(t,y)

title('Constructing Square Waves: The Gibbs Effect')

From here, it can be seen that although there are many superimposed sine waves, there will always be violent oscillations at the edge of the waveform, which is the Gibbs effect mentioned above, in other words, no matter how many sine waves are superimposed, the peak of this fluctuation remains the same.

The Gibbs effect phenomenon also shows that Fourier series cannot represent discontinuous, discontinuous signals, so the "arbitrary" function of the Fourier transform should refer to a continuous function. Judging from this phenomenon, when Fourier's ** was reviewed by Lagrange, Lagrange was right when he said that "sinusoidal curves cannot be combined into angular signals", and it can only be said that it is approximated.

% Three-dimensional surface diagram, the gradual process of a sine wave to a square wave.

surf(y);

shading interp

axis off ij

If the cosine wave wants to be converted into a square wave, you need to pay attention to the plus and minus signs here, because this cosine is an even function.

y = cos(t) -cos(3*t)/3 + cos(5*t)/5 - cos(7*t)/7 + cos(9*t)/9;

plot(t,y);

Related Pages