Rectangle signal

The rectangle signal is the classic signal type to carry out the Fourier transformation :-)

To keep the calculations easy I start with a rectangle impulse periodic to 2π:


Rect


For the ak components:



Rect


Rect

and the bk components:


Rect


There are 2 cases:

If k is odd


Rect


If k is even


Rect


K = 0


Rect



For a symmetric rectangle signal we can use the same formulation:


Rect



Only a0 becomes 0 now. The rest is identical


Rect



Implemented in a function that would look like:



private void Rectangle(double peak)
{
int j;
c[0].real = 0;
c[0].imag = 0;
for (j = 1; j < 500; j++)
{
c[j].real = 0;
if (j % 2 == 0)
c[j].imag = 0;
else
c[j].imag = peak * 4 / Math.PI / j;
}
}

With ak as real parts and bk as imaginary parts:



And that calculates this spectrum for the first 30 harmonics:

Rect



And if all the harmonics are put together, we get the signal shape.

The brightest line is the base frequency. The next darker is the base frequency plus the first harmonic, then comes the same plus the next harmonic … and so on. The more harmonics are included, the closer the shape approximates the origin shape.

Rect



C# Demo Project Fourier signals
  • FourierSignals.zip


  • Java Demo Project Fourier signals
  • FourierSignals.zip