```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
#define N 200000
#define T 4.0
#define A 2.0
#define M 121
#define TAU 1.0
#define DEC 50
int main(int argc, char* argv[])
{
double* t = NULL; /* Time vector (sec) */
double* s = NULL; /* Input signal vector */
complex_t* sc = NULL; /* Complex modulated signal */
complex_t S[M]; /* Complex spectrum */
double Smag[M]; /* Amplitude spectrum */
double Sphi[M]; /* Phase spectrum */
double w[M]; /* Angular frequency (rad/s) */
void* hdspl; /* DSPL handle */
void* hplot; /* GNUPLOT handle */
int k, i;
/* Load libdspl.dll */
hdspl = dspl_load();
if(!hdspl)
{
printf("Сannot to load libdspl!\n");
return 0;
}
/* Memory allocation */
t = (double*)malloc(N*sizeof(double));
s = (double*)malloc(N*sizeof(double));
sc = (complex_t*)malloc(N*sizeof(complex_t));
/* Time vector contains 4 periods of signal */
linspace(-T*2.0, T*2.0, N, DSPL_PERIODIC, t);
/* 4 periods of the rectangle pulses */
signal_pimp(t, N, A, TAU, 0.0, T, s);
/* Spectrum calculation by Fourier serie decomposition */
fourier_series_dec(t, s, N, T, M, w, S);
/* Amplitude and Phase spectrum */
for(k = 0; k < M; k++)
{
Smag[k] = ABS(S[k])/4.0;
Sphi[k] = atan2(IM(S[k]), RE(S[k]));
}
/* Save spectrums to the files */
writetxt(w, Smag, M, "dat/fourier_series_prop_spectrum_amp_a.txt");
writetxt(w, Sphi, M, "dat/fourier_series_prop_spectrum_phi_a.txt");
/* Modulation by complex exponent*/
double w0 = 10.0*M_PI;
for(k = 0; k < N; k++)
{
RE(sc[k]) = s[k] * cos(w0*t[k]);
IM(sc[k]) = s[k] * sin(w0*t[k]);
}
/* Spectrum calculation by Fourier series decomposition */
fourier_series_dec_cmplx(t, sc, N, T, M, w, S);
/* Amplitude and Phase spectrum */
for(k = 0; k < M; k++)
{
Smag[k] = ABS(S[k])/4.0;
Sphi[k] = atan2(IM(S[k]), RE(S[k]));
}
/* Save spectrums to the files */
writetxt(w, Smag, M, "dat/fourier_series_prop_spectrum_amp_se.txt");
writetxt(w, Sphi, M, "dat/fourier_series_prop_spectrum_phi_se.txt");
/* DEC times decimation of the input time signal*/
decimate(t, N, DEC, t, &i);
decimate(s, N, DEC, s, &i);
/* save to dat/fourier_series_prop_time_a.txt */
writetxt(t, s, i, "dat/fourier_series_prop_time_a.txt");
/* DEC times decimation of the modulated complex signal*/
decimate_cmplx(sc, N, DEC, sc, &i);
/* Save real and imaginary parts of modulated signal to the files */
writetxt_cmplx_re(t, sc, i, "dat/fourier_series_prop_time_se_re.txt");
writetxt_cmplx_im(t, sc, i, "dat/fourier_series_prop_time_se_im.txt");
/* Time vector contains 4 periods of signal */
linspace(-T*2.0, T*2.0, N, DSPL_PERIODIC, t);
/* 4 periods of the rectangle pulses */
signal_pimp(t, N, A, TAU, 0.0, T, s);
/* Modulation by cosine oscillation */
for(k = 0; k < N; k++)
{
s[k] *= cos(w0*t[k]);
}
/* Spectrum calculation by Fourier series decomposition */
fourier_series_dec(t, s, N, T, M, w, S);
/* Amplitude and Phase spectrum */
for(k = 0; k < M; k++)
{
Smag[k] = ABS(S[k])/4.0;
Sphi[k] = atan2(IM(S[k]), RE(S[k]));
}
/* Save spectrums to the files */
writetxt(w, Smag, M, "dat/fourier_series_prop_spectrum_amp_sc.txt");
writetxt(w, Sphi, M, "dat/fourier_series_prop_spectrum_phi_sc.txt");
/* DEC times decimation of the modulated complex signal */
decimate(t, N, DEC, t, &i);
decimate(s, N, DEC, s, &i);
writetxt(t, s, i, "dat/fourier_series_prop_time_sc.txt");
/* Plotting by GnuPlot */
gnuplot_create(argc, argv, 1200, 640, "img/plot.png", &hplot);
gnuplot_cmd(hplot, "unset key");
gnuplot_cmd(hplot, "set multiplot layout 3, 3 rowsfirst");
gnuplot_cmd(hplot, "plot 'dat/fourier_series_prop_time_a.txt' with lines");
gnuplot_cmd(hplot, "plot 'dat/fourier_series_prop_time_se_re.txt' with lines,\\");
gnuplot_cmd(hplot, " 'dat/fourier_series_prop_time_se_im.txt' with lines");
gnuplot_cmd(hplot, "plot 'dat/fourier_series_prop_time_sc.txt' with lines");
gnuplot_cmd(hplot, "plot 'dat/fourier_series_prop_spectrum_amp_a.txt' with impulses lt 1 ,\\");
gnuplot_cmd(hplot, " 'dat/fourier_series_prop_spectrum_amp_a.txt' with points pt 7 ps 0.5 lt 1");
gnuplot_cmd(hplot, "plot 'dat/fourier_series_prop_spectrum_amp_se.txt' with impulses lt 1 ,\\");
gnuplot_cmd(hplot, " 'dat/fourier_series_prop_spectrum_amp_se.txt' with points pt 7 ps 0.5 lt 1");
gnuplot_cmd(hplot, "plot 'dat/fourier_series_prop_spectrum_amp_sc.txt' with impulses lt 1 ,\\");
gnuplot_cmd(hplot, " 'dat/fourier_series_prop_spectrum_amp_sc.txt' with points pt 7 ps 0.5 lt 1");
gnuplot_cmd(hplot, "plot 'dat/fourier_series_prop_spectrum_phi_a.txt' with impulses lt 1 ,\\");
gnuplot_cmd(hplot, " 'dat/fourier_series_prop_spectrum_phi_a.txt' with points pt 7 ps 0.5 lt 1");
gnuplot_cmd(hplot, "plot 'dat/fourier_series_prop_spectrum_phi_se.txt' with impulses lt 1 ,\\");
gnuplot_cmd(hplot, " 'dat/fourier_series_prop_spectrum_phi_se.txt' with points pt 7 ps 0.5 lt 1");
gnuplot_cmd(hplot, "plot 'dat/fourier_series_prop_spectrum_phi_sc.txt' with impulses lt 1 ,\\");
gnuplot_cmd(hplot, " 'dat/fourier_series_prop_spectrum_phi_sc.txt' with points pt 7 ps 0.5 lt 1");
gnuplot_close(hplot);
/* free libdspl.dll */
dspl_free(hdspl);
/* free memory */
free(s);
free(t);
free(sc);
return 0;
}
```

# Fourier series properties

In the previous section, Fourier series decomposition of periodic signals was considered. Expressions were given for the Fourier series in trigonometric and complex forms and the spectrum of a periodic signal was introduced.

It is shown that the spectrum of the periodic signal is a discrete function , defined on an equidistant frequency grid ,

In this section, we will consider some properties of the periodic signals spectrum. As we will see later, the Fourier transform of non-periodic signals, as well as the discrete Fourier transform, have similar properties.

Let there are two periodic signals and with equal periods , and both signals satisfy the Dirichlet conditions. The signals and can be represented by a Fourier series with coefficients and , where ,

Throughout the rest of this section, we assume that the signals and are periodic with equal periods , and both signals satisfy the Dirichlet conditions. Then the signal is also a periodic signal with the period , and can be represented by a Fourier series with the coefficients:

Thus, the spectrum of the sum of periodic signals is equal to the sum of their spectra. A consequence of the linearity property is the property of multiplication by a constant. The signal spectrum , , is equal to:

Consider the signal as a result of the cyclic time shift of the input signal , as shown in the figure 1 for positive and negative values of .

The spectrum of the signal with a cyclic time shift is:

Thus, the cyclic time shift of the periodic signal corresponds to the spectrum multiplication by the phase factor . In this case, the amplitude spectrum does not change, and the phase spectrum has an additional linear term.

Let the signal is a cyclic convolution [1, p. 362] of signals and :

Let's change the order of integration and use the cyclic time shift property (4):

The spectrum of the periodic signal (5) is proportional to the product of the spectra and .

This is one of the most important properties of spectral analysis, which allows you to analyze signal processing systems in the frequency domain, replacing the time convolution of signals by the product of their spectra.

Let's signal is product of and signals. The signal is -periodic, and it spectrum equals:

We can substitute in (8) instead signal its Fourier series decomposition:

Change the order of integration and sum in (9) and we will have:

Let's is real periodic signal. It spectrum equals:

Amplitude and phase spectrum of the real signal are:

Symmetry properties is not satisfied if is complex signal.

Let the signal is product of signal and complex exponent with frequency , where is an arbitrary integer. The choice of the frequency ensures the periodicity of the signal , because an integer number of the complex exponent oscillations fits in one period .

Thus, the signal satisfies the Dirichlet conditions, and its spectrum is:

The multiplication of the signal by the complex exponent shift the signal spectrum to the frequency . In this case, the signal becomes complex, and its spectrum is asymmetric with respect to the zero frequency.

Figure 2 shows an example of the frequency shift of the signal when is multiplied by the complex exponent with the frequency rad/s.

It is important to note that the signal itself has become complex (the graph shows separately the real and the imaginary part of the signal), in this case, its amplitude spectrum ceased to be symmetric, and its phase spectrum ceased to be antisymmetric with respect to the zero frequency.

Consider now the multiplication of the signal not by the complex exponent, but by the harmonic oscillation , where , – arbitrary integer, — arbitrary initial phase.

We also keep the signal periodicity in this case, and its spectrum is:

Thus, the multiplication of the signal by the harmonic oscillation leads to a shift of the spectrum by frequencies in both the positive and negative frequency regions, a decrease in the amplitude in the positive and negative regions by a factor of two, and the addition of the phase factor .

The figure 3 shows an example of the frequency shift of the signal when multiplying by with frequency rad/s (5 Hz), and rad.

From the figure 3 one can see that the spectrum of the frequency-shifted signal is the sum of the half-amplitude spectra shifted by the frequencies . Note that the real signal remains real with a symmetric amplitude and antisymmetric phase spectrum.

index {average power} allocated at a resistance of 1 Ohm by the signal :

Substitute in (19) instead of the expression of the Fourier series in complex form:

Equating (19) and (21), we get Parseval's equality, which relates the average power of a periodic signal in the time and frequency domains:

From (22) it follows that the average power released at the 1 Ohm resistance for one signal repetition period is equal to the sum of the spectral components amplitudes squares. In this case, the summation is for from minus infinity to infinity. This means that the components with negative frequencies corresponding to negative also contribute to the signal power.

If we take into account that the amplitude spectrum of a real periodic signal is symmetric with respect to the zero frequency, then we can conclude that the spectral components in the negative frequency range carry the same power as the spectral components with positive frequencies . Therefore, the negative frequencies that appeared during the transition to the Fourier series in complex form are not just a mathematical abstraction, but a physical entity that carries almost half the power of a real signal.

Let the signal be a continuous periodic signal differentiable on the time axis (does not have discontinuities of the first kind), whose spectrum is equal to . Then the signal is also a periodic signal that satisfies the Dirichlet conditions and its spectrum is:

We use the rule of integration by parts:

Thus, the spectrum of the periodic signal derivative is equal to the spectrum of this signal multiplied by .

The presence of the factor leads to the fact that the spectrum of with increasing frequency decays weaker than the original signal spectrum . Therefore, initially we imposed a restriction on the original signal: it must be continuous and differentiable, then its spectrum will decay faster than , and multiplication by will not increase with increasing frequency.

Now let be a signal with a zero mean value. The spectrum of the signal is zero at zero frequency: .

Then

Note that if there is in the signal , the integrator from minus infinity will accumulate an infinite component of the signal . Figure 4 shows an example of a periodic signal with a zero mean value and the result of its integration.

Consider the spectrum of the signal . To do this, note that the signal is nothing but the derivative of the signal . Then using the spectrum property of the signal derivative (26), we can write:

With , the spectrum of is calculated without much difficulty. However, at the frequency , obtain an limits of indeterminate form :

Evaluate limits of indeterminate forms by L'Hospital's rule:

By the definition of the spectrum

Finally, the spectrum of the signal at zero frequency is:

Analyzing the expression , we can conclude that the integration of the signal leads to a faster decay of the amplitudes of the signal spectrum due to the presence of an additional factor . Thus, integrating removes the jumps in the original signal, as shown in the figure 4.

In this section, we examined some properties of the spectra of periodic signals: linearity, properties of time and frequency shifts, spectrum of convolution and product of signals.

We also analyzed the property of symmetry of the spectrum of the real signal and found that the amplitude spectrum of the periodic signal is symmetric, and the phase spectrum — antisymmetric with respect to zero frequency.

We also considered Parseval's equality, which establishes the ratio of the average signal power in the time and frequency domains, and the property of differentiation and integration of the signal.

In the next section, we will analyze the decomposition of non-periodic signals and obtain a continuous Fourier transform.

The figures for the figures in this section were calculated using DSPL-2.0 library.

The following source code of the data calculation program for plotting the figureв 2 and 3: