Representation of periodic signals by the Fourier series

Content

DSPL-2.0 is free digital signal processing algorithms library

Distributed under v3 LGPL v3 license

GitHub project page.

Found a mistake? Select it with the mouse and press ctrl+enter
Introductory remarks

In this section, we will consider the representation of periodic signals using the Fourier series. Fourier series are the basis of the theory of spectral analysis, because as we will see later, the Fourier series transformation of a non-periodic signal can be obtained as the limit transition of the Fourier series with an infinite repetition period. As a result, the properties of the Fourier series are also valid for the Fourier transform of non-periodic signals.

We consider the expressions of the Fourier series in trigonometric and complex form, and also pay attention to the Dirichlet conditions for the convergence of the Fourier series. In addition, we will dwell in detail on the explanation of such a concept as the negative frequency of the signal spectrum, which often causes difficulty in getting acquainted with the theory of spectral analysis.

Periodic signal. Trigonometric Fourier Series

Let there be a periodic signal  of continuous time , which repeats with a period  s, that is, , where  — is an arbitrary integer.

As an example, the figure 1 shows a sequence of rectangular pulses of duration  s, repeating with a period of  s.

Periodic sequence of  rectangular pulses
Figure 1. Periodic sequence of rectangular pulses

From the course of mathematical analysis we know that the system of trigonometric functions

(1)
with multiple frequencies , where  rad/s,  — is an integer, forms an orthonormal basis for the expansion of periodic signals with a period of , satisfying the Dirichlet conditions .

Dirichlet conditions for the convergence of the Fourier series require that the periodic signal  was set on a segment , while satisfying the following conditions:

For example, the periodic function  does not satisfy the Dirichlet conditions, because the function  has discontinuities of the second kind and takes infinite values at , where  — an arbitrary integer. Thus, the function  cannot be represented by a Fourier series. We can also give an example of the function , which is limited, but also does not satisfy the Dirichlet conditions, since it has an infinite number of extremum points as it approaches zero. The function graph  shown in the figure 2.

The function graph :   а — two repetition periods; b — in the neighborhood 
Figure 2. The function graph :
а — two repetition periods; b — in the neighborhood 

The figure 2а shows two repetition periods of the function , and the figure 2b — is an area in the neighborhood . You can see that when   approaches zero, the oscillation frequency increases infinitely, and such a function cannot be represented by the Fourier series, because it is not piecewise monotonous.

It should be noted that in practice there are no signals with infinite values of current or voltage. Functions with an infinite number of extrema of type  are neither found in applied tasks. All real periodic signals satisfy the Dirichlet conditions and can be represented by an infinite trigonometric Fourier series of the form:

(2)

In the expression (2), the coefficient  sets the constant component of the periodic signal .

At all points where the signal is continuous, the Fourier series (2) converges to the values of the given signal, and at the break points of the first kind — to average , where  and  — are limits to the left and right of the break point, respectively.

It is also known from the course of mathematical analysis that the use of a truncated Fourier series containing only  of the first terms instead of an infinite sum leads to an approximate representation of the signal :

(3)
at which a minimum of the mean square error is ensured. The figure 3 illustrates the approximation of a periodic sequence of rectangular pulses and a periodic sawtooth signal using a different number of members of the Fourier series .

 Signal approximation by truncated Fourier series:   а — rectangular impulses; b — sawtooth signal
Figure 3. Signal approximation by truncated Fourier series:
а — rectangular impulses; b — sawtooth signal

Fourier series in complex form

In the previous section, we considered the trigonometric Fourier series for the expansion of an arbitrary periodic signal  that satisfies the Dirichlet conditions. Applying the Euler formula, we can show:

(4)
Then the trigonometric Fourier series (2), taking into account(4):
(5)

Thus, the periodic signal  can be represented by the sum of the constant component  and complex exponentials rotating with frequencies  with coefficients  for positive frequencies , and  for complex exponentials rotating with negative frequencies .

Consider the coefficients for complex exponentials rotating with positive frequencies :

(6)

Similarly, the coefficients for complex exponentials rotating with negative frequencies :

(7)

The expressions (6) and (7) coincide; in addition, the constant component  can also be written through the complex exponent at zero frequency:

(8)

Thus, (5) considering (6)–(8) can be represented as a single sum for indexing  from minus infinity to infinity:

(9)
Leonhard Euler
1707–1783
The expression (9) is the Fourier series in complex form. The coefficients of the Fourier series in the complex form  are related to the coefficients  and  of the series in the trigonometric form, and are determined for both positive and negative frequencies . The index  in the designation of frequency  indicates the number of discrete harmonics, with negative indices corresponding to negative frequencies .

From the expression (2) it follows that for the real signal , the coefficients  and  of the series (2) also are real. However, (9) associates a real signal , with a set of complex conjugate coefficients , related to both positive and negative frequencies .

Some explanations for the Fourier series in complex form

In the previous section, we made the transition from the trigonometric Fourier series (2) to the Fourier series in complex form (9). As a result, instead of decomposing periodic signals in the basis of real trigonometric functions, we obtained decomposition in the basis of complex exponentials with complex coefficients  and negative frequencies in the decomposition! Since this issue is often confused, some clarification is needed.

First, working with complex exponents is in most cases easier than with trigonometric functions. For example, when multiplying and dividing complex exponentials, it’s enough to just add (subtract) the indicators, while the formulas for multiplying and dividing trigonometric functions are more cumbersome.

Differentiating and integrating exponentials, even complex ones, is also easier than trigonometric functions that constantly change during differentiation and integration (the sine turns into cosine and vice versa).

If the signal is periodic and real, then the trigonometric Fourier series (2) seems more obvious, because all the expansion coefficients , and  remain real. However, one often has to deal with complex periodic signals (for example, when modulating and demodulating, a quadrature representation of the complex envelope is used). In this case, when using the trigonometric Fourier series, all coefficients , and  of the expansion (2) will become complex, while when using the Fourier series in the complex form (9), the same decomposition coefficients  will be used, for both real and complex input signals.

And finally, it is necessary to dwell on the explanation of the negative frequencies that appeared in (9). This question often causes misunderstanding. In everyday life, we do not encounter negative frequencies. For example, we never tune our radio to a negative frequency. Let's consider the following analogy from mechanics. Let there be a mechanical spring pendulum that makes free oscillations with a certain frequency . Can a pendulum oscillate with a negative frequency of ? Of course, it cannot. Just as there are no radio stations broadcasting at negative frequencies, the pendulum oscillation frequency cannot be negative. But the spring pendulum — is a one-dimensional object (the pendulum oscillates along one straight line).

We can also give another analogy from mechanics: a wheel rotating with a frequency . The wheel, unlike the pendulum, rotates, i.e. a point on the surface of the wheel moves in the plane, and not just vibrates along one straight line. Therefore, to uniquely specify the rotation of the wheel, setting the speed is not enough, because you must also set the direction of rotation. For this we can use the sign of frequency.

So if the wheel rotates at an angular frequency  rad/s counterclockwise, then we believe that the wheel rotates with a positive frequency, and if in the clockwise direction, then the speed will be negative. Thus, to specify rotation, the negative frequency ceases to be nonsense and indicates the direction of rotation.

And now the most important thing that we must understand. The oscillation of a one-dimensional object (for example, a spring pendulum) can be represented as the sum of the rotations of two vectors shown in the figure 4.

Oscillation of a spring pendulum  as the sum of the rotations   of two vectors  on the complex plane
Figure 4. Oscillation of a spring pendulum as the sum of the rotations
of two vectors on the complex plane

The pendulum oscillates along the material axis of the complex plane with a frequency  according to harmonic law . The movement of the pendulum is shown by a horizontal vector. The upper vector rotates on the complex plane with a positive frequency  (counterclock-wise), and the bottom vector rotates with a negative frequency  (clockwise). The figure 4 clearly illustrates the well-known from the course of trigonometry ratio:

(10)

Thus, the Fourier series in complex form (9) represents periodic one-dimensional signals  as the sum of vectors on the complex plane rotating with positive and negative frequencies. We note that in the case of a real signal, according to (9), the decomposition coefficients  for negative frequencies  are complex conjugate to the corresponding coefficients for positive frequencies . In the case of a complex signal, this property of the coefficients is not satisfied because  and  are also complex.

The spectrum of periodic signals

The Fourier series in complex form is the decomposition of a periodic signal  to the sum of complex exponentials rotating with positive and negative frequencies multiple  rad/s with corresponding complex coefficients , which determine the spectrum of the signal . The complex coefficients  can be represented by the Euler formula as , where  — amplitude spectrum, and  — phase spectrum.

Since periodic signals are laid out in a row only on a fixed frequency grid , then the spectrum  periodic signals is a linear spectrum(discrete).

Spectrum of a periodic sequence of  rectangular pulses: 
		а — amplitude spectrum; b — phase spectrum
Figure 5. Spectrum of a periodic sequence of rectangular pulses:
а — amplitude spectrum; b — phase spectrum

The figure 5 shows an example of amplitude  and phase  spectrum of a periodic sequence of rectangular pulses (see Fig. 1) at  s, pulse duration  s and pulse amplitude  V.

The amplitude spectrum of the original material signal is symmetric with respect to the zero frequency, and the phase spectrum — is antisymmetric. We note that the values of the phase spectrum  and  correspond to the same point in the complex plane .

We can conclude that all the decomposition coefficients of the reduced signal are purely real, and the phase spectrum  corresponds to negative coefficients .

Note that the dimension of the amplitude spectrum  coincides with the dimension of the signal . If  describes the change in voltage over time, measured in volts, then the harmonic amplitudes of the spectrum  will also have a dimension of volts.

Conclusion

This section discusses the representation of periodic signals using the Fourier series. The expressions for the Fourier series in trigonometric and complex forms are given. We paid special attention to the Dirichlet conditions for the convergence of the Fourier series and gave examples of functions for which the Fourier series diverges.

We elaborated on the expression of the Fourier series in complex form and showed that periodic signals, both real and complex, are represented with a series of complex exponentials with positive and negative frequencies. Moreover, the expansion coefficients are also complex and characterize amplitude and phase spectrum of a periodic signal.

In the next section, we will examine in more detail the properties of the spectra of periodic signals.

Software implementation in the DSPL library

The data for constructing the drawings in this section were calculated using of the DSPL-2.0 library

Below is the source code of the data calculation program for drawing 2:


/*******************************************************************************
 * This program calculates data for function
 * 
 *                          s(t) = sin(1/sin(t))
 * 
 * 
 * Saved files:
 * 
 * dat/fourier_series_signal0.txt 
 * dat/fourier_series_signal1.txt
 *  
 ******************************************************************************/ 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "dspl.h"


/* size of arrays */
#define N  10000

int main(int argc, char* argv[])
{
  double t[N]; /* argument array */
  double s[N]; /* fucntion s(t) = sin(1/sin(t)) array */
  void* hdspl; /* DSPL handle        */
  void* hplot; /* GNUPLOT handle     */
  int k;
  
  /* load libdspl.dll */
  hdspl = dspl_load();
  if(!hdspl)
  {
    printf("Cannot to load libdspl!\n");
    return 0;
  }

  /* fill t array from -2*pi to 2*pi */
  linspace(-M_2PI, M_2PI, N, DSPL_PERIODIC, t);
  
  /* calculte s(t) = sin(1/sin(t)) for every t[k]      */
  for(k = 0; k < N; k++)
    s[k] = sin(1.0/sin(t[k]));
    
  /* save s(t) to the file dat/fourier_series_signal0.txt */  
  writetxt(t, s, N, "dat/fourier_series_signal0.txt");


  /* fill t array from -0.2 to 0.2 */
  linspace(-0.2, 0.2, N, DSPL_PERIODIC, t);
  
  /* calculate s(t) = sin(1/sin(t)) for every t[k]      */
  for(k = 0; k < N; k++)
    s[k] = sin(1.0/sin(t[k]));

  /* save data to the file dat/fourier_series_signal1.txt */  
  writetxt(t, s, N, "dat/fourier_series_signal1.txt");
  
  /* plotting by GNUPLOT */
  gnuplot_create(argc, argv, 560, 380, "img/dirichlet_ex.png", &hplot);
  gnuplot_cmd(hplot, "set grid");
  gnuplot_cmd(hplot, "unset key");
  gnuplot_cmd(hplot, "set xlabel 'x'");
  gnuplot_cmd(hplot, "set ylabel 'sin(1/sin(x))'");
  gnuplot_cmd(hplot, "plot 'dat/fourier_series_signal1.txt' with lines");
  gnuplot_close(hplot);
  
  /* free libdspl.dll */
  dspl_free(hdspl);
  

  return 0;
}

The source code of the program for calculating data for building graphs of approximation of the rectangular pulses periodic sequence and a sawtooth signal of the truncated Fourier series(Fig. 3):


/*******************************************************************************
 * This function calculates approximation of periodic rectangular impulses
 * and sawtooth signal by truncated Fourier series 
 ******************************************************************************/ 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "dspl.h"

/* Size of arrays */
#define N  1000

/* time period (s) */
#define T  2

/* pulse duration (s) */
#define TAU 1

/* Max number of Fourier serie coefficients */
#define MAX_M 61

/*  Number of periods */
#define P 3.0

int main(int argc, char* argv[])
{
  double t[N];         /* time                       */
  double s[N];         /* input signal               */
  double x[N];         /* approximation              */
  double w[MAX_M];     /* frequency                  */
  complex_t S[MAX_M];  /* complex spectrum           */
  
  complex_t xc[N];     /* complex signal             */

   
  /*
   * Numbers of truncated Fourier serie coefficients
   * Note: 5 spectrum samples contains two pairs of conjugate spectrum 
   * samples and one mean value on the zero frequency.
   * So 5 truncated Fourier serie coefficients in complex form corresponds 
   * to two values a_n and b_n in trigonometric form.
   */ 
  int M[4] = {5, 9, 21, MAX_M};

  void* hdspl; /* DSPL handle        */
  void* hplot; /* GNUPLOT handle     */
  
  
  int k, n;
  char fname[64];  /* saved data filename */


  /* load libdspl.dll */
  hdspl = dspl_load();
  if(!hdspl)
  {
    printf("Cannot to load libdspl!\n");
    return 0;
  }
  
  /* fill time array for P periods  */
  linspace(-T*0.5*P, T*0.5*P, N, DSPL_PERIODIC, t);
  
  /*--------------------------------------------------------------------------*/
  /*  rectangular impulses */
  signal_pimp(t, N, 1.0, TAU, 0.0, T, s);
  
  /* save to dat/fourier_series_pimp0.txt */
  writetxt(t, s, N, "dat/fourier_series_pimp0.txt");
  
  /* for different numbers of truncated Fourier series coefficients */
  for(k = 0; k < 4; k++)
  {
    /* Current complex spectrum */
    fourier_series_dec(t, s, N, T, M[k], w, S);
    
    /* Normalizing because P periods  */
    for(n = 0; n < M[k]; n++)
    {
      RE(S[n]) /= P;
      IM(S[n]) /= P;
    }
  
    /* signal reconstruction from truncated Fourier serie */
    fourier_series_rec(w, S, M[k], t, N, xc);
  
    /* reconstructed signal image part is arround 1E-16. Ignore it */
    cmplx2re(xc, N, x, NULL);
  
    /* save to file */
    sprintf(fname, "dat/fourier_series_pimp_rec_%d.txt", M[k]);
    writetxt(t, x, N, fname);
  }
  
  /*--------------------------------------------------------------------------*/
  /* sawtooth signal*/
  signal_saw(t, N, 0.5, 0.0, T, s);
  for(n = 0; n < N; n++)
    s[n] += 0.5;
  
  /* save to dat/fourier_series_saw0.txt */
  writetxt(t, s, N, "dat/fourier_series_saw0.txt");
  
  /* for different numbers of truncated Fourier series coefficients */
  for(k = 0; k < 4; k++)
  {
    /* Current complex spectrum */
    fourier_series_dec(t, s, N, T, M[k], w, S);
    
    /* Normalizing because P periods  */
    for(n = 0; n < M[k]; n++)
    {
      RE(S[n]) /= P;
      IM(S[n]) /= P;
    }
    
     /* signal reconstruction from truncated Fourier serie */
    fourier_series_rec(w, S, M[k], t, N, xc);
  
     /* reconstructed signal image part is arround 1E-16. Ignore it */
    cmplx2re(xc, N, x, NULL);
  
    /* save to file */
    sprintf(fname, "dat/fourier_series_saw_rec_%d.txt", M[k]);
    writetxt(t, x, N, fname);
  }
  
  
  /* GNUPLOT */
  gnuplot_create(argc, argv, 800, 640,  "img/fourier_series_rec.png", &hplot);
  gnuplot_cmd(hplot, "unset key");
  gnuplot_cmd(hplot, "set multiplot layout 4,2 rowsfirst");
  gnuplot_cmd(hplot, "plot 'dat/fourier_series_pimp0.txt' with lines,\\");
  gnuplot_cmd(hplot, "     'dat/fourier_series_pimp_rec_5.txt' with lines");
  gnuplot_cmd(hplot, "plot 'dat/fourier_series_saw0.txt' with lines,\\");
  gnuplot_cmd(hplot, "     'dat/fourier_series_saw_rec_5.txt' with lines");
  gnuplot_cmd(hplot, "plot 'dat/fourier_series_pimp0.txt' with lines,\\");
  gnuplot_cmd(hplot, "     'dat/fourier_series_pimp_rec_9.txt' with lines");
  gnuplot_cmd(hplot, "plot 'dat/fourier_series_saw0.txt' with lines,\\");
  gnuplot_cmd(hplot, "     'dat/fourier_series_saw_rec_9.txt' with lines");
  gnuplot_cmd(hplot, "plot 'dat/fourier_series_pimp0.txt' with lines,\\");
  gnuplot_cmd(hplot, "     'dat/fourier_series_pimp_rec_21.txt' with lines");
  gnuplot_cmd(hplot, "plot 'dat/fourier_series_saw0.txt' with lines,\\");
  gnuplot_cmd(hplot, "     'dat/fourier_series_saw_rec_21.txt' with lines");
  gnuplot_cmd(hplot, "plot 'dat/fourier_series_pimp0.txt' with lines,\\");
  gnuplot_cmd(hplot, "     'dat/fourier_series_pimp_rec_61.txt' with lines");
  gnuplot_cmd(hplot, "plot 'dat/fourier_series_saw0.txt' with lines,\\");
  gnuplot_cmd(hplot, "     'dat/fourier_series_saw_rec_61.txt' with lines");
  gnuplot_cmd(hplot, "unset multiplot");
  gnuplot_close(hplot);


  /* free libdspl.dll */
  dspl_free(hdspl);

  return 0;
}

The source code of the program for calculating the amplitude and phase spectrum (Fig. 5):


/*******************************************************************************
 * This program calculates amplitude amplitude and phase spectrum of
 * periodic sequence of rectangular pulses
 * 
 * Saved files:
 * 
 * dat/fourier_series_pimp_mag.txt - amplitude spectrum
 * dat/fourier_series_pimp_phi.txt - phase spectrum
 *  
 ******************************************************************************/ 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "dspl.h"

/* Number of samples in one time period */
#define N  1000

/* time period length (s) */
#define T  4

/* rectangular pulses duration (s)      */
#define TAU 2

/* Number of spectrum samples           */
#define K 41

int main(int argc, char* argv[])
{
  double t[N];    /* time (s)           */
  double s[N];    /* input signal       */
  double w[K];    /* frequency (rad/s)  */
  complex_t S[K]; /* complex spectrum   */
  double mag[K];  /* amplitude spectrum */
  double phi[K];  /* phase spectrum     */
  void* hdspl;    /* DSPL handle        */
  void* hplot;    /* GNUPLOT handle     */
  int n;


  /* Load libdspl.dll */
  hdspl = dspl_load();
  if(!hdspl)
  {
    printf("cannot to load libdspl!\n");
    return 0;
  }

  /* fill one pertiod time array */
  linspace(-T*0.5, T*0.5, N, DSPL_SYMMETRIC, t);

  /* signal  */
  signal_pimp(t, N, 2.0, TAU, 0.0, T, s);

  /* complex specctrum calculation */
  fourier_series_dec(t, s, N, T, K, w, S);

  /* amplitude and phase spectrum */
  for(n = 0; n < K; n++)
  {
    mag[n] = ABS(S[n]);
    phi[n] = atan2(IM(S[n]), RE(S[n]));
  }

  /* save amplitude spectrum */
  writetxt(w, mag, K, "dat/fourier_series_pimp_mag.txt");

  /* save phase spectrum */
  writetxt(w, phi, K, "dat/fourier_series_pimp_phi.txt");

  /* Plotting */
  gnuplot_create(argc, argv, 560, 380, "img/spectrum.png", &hplot);
  gnuplot_cmd(hplot, "unset key");
  gnuplot_cmd(hplot, "set grid");
  gnuplot_cmd(hplot, "set lmargin 8");
  gnuplot_cmd(hplot, "set multiplot layout 2,1 rowsfirst");
  gnuplot_cmd(hplot, "set xlabel 'Frequency, rad/s'");
  gnuplot_cmd(hplot, "set ylabel 'Amplitude spectrum'");
  gnuplot_cmd(hplot, "plot[-10*pi:10*pi] 'dat/fourier_series_pimp_mag.txt' with  impulses lt 1 ,\\");
  gnuplot_cmd(hplot, "'dat/fourier_series_pimp_mag.txt' with points pt 7 ps 0.5 lt 1");
  gnuplot_cmd(hplot, "set ylabel 'Phase spectrum'");
  gnuplot_cmd(hplot, "plot[-10*pi:10*pi] 'dat/fourier_series_pimp_phi.txt' with  impulses lt 1 ,\\");
  gnuplot_cmd(hplot, "'dat/fourier_series_pimp_phi.txt' with points pt 7 ps 0.5 lt 1");
  gnuplot_cmd(hplot, "unset multiplot");
  gnuplot_close(hplot);
  
  /* free libdspl.dll */
  dspl_free(hdspl);

  return 0;

}


See also

Some properties of the expansion of periodic signals in a Fourier series
The spectrum of the periodic sequence of rectangular pulses
Fourier transform of non-periodic signals

Reference

[1] Bracewell R. The Fourier Transform and Its Applications McGraw-Hills, 1986, 474 c. ISBN 0-07-007-015-6

Page update: 30.08.2020 (13:10:53)