Fourier series problem

Hi,

I am trying to simulate the fourier series coefficients a0, a1, and b1 and then trying to plot the fourier series. But the simulation result in the end does not look like the math results. I am doing something wrong? See below…
How to make a simulation (ideally by using only behavioral sources) to match the fourier series math results as I showed below?

sf_test.qsch (4.8 KB)





The Fourier series coefficients a0, a1, and b1 are calculated by integrating over at least one full period. In real-time applications, the output using these coefficients (a0, a1, and b1) must be delayed by one period (a one-period delay). The integrator must be reset at the start of each period, and the coefficients should only be calculated and used at the end of each period.

Your current setup suggests you have some confusion about how the mathematics should work. The simplest solution might be to write a DLL block with C code for this task. I tested a code that can implement this idea. However, note that output is delayed by one cycle, as a0, a1, and b1 are only available after one full cycle of integration.

example.Fourier.qsch (3.4 KB)
fourier.cpp (5.5 KB)

1 Like

Thanks for explanations.
Can you upload also the qspice simulation?

I am still wonderying If any analog equivalent way - so without involving any code (for example by using behavioral sources or whatever) can be thing off, in order to calculate this fourier coefficients and further the fourier series.

There is somewehere this block delayed by one period (a one period delay)?

I modified my reply to include .cpp code and schematic.

Here is what I refer to delay.

The fourier series coefficients are calculated at the end of each period. You need to hold that results for Fourier Synthesis to rebuild the signal using coefficients in next period. The integrator has to be reset and in next period to calculate its next fourier series coefficients. Such a logic to implement with analog block seems petty complicate to me.

Example LTspice:
signal_harmonic.txt (474 Bytes)
Analyzer_Controls.txt (10.5 KB)

2 Likes

Reviewed @bordodynov LTspice subckt signal_harmonic.txt, a Qspice version is setup to calculate a0, a1, b1 (or magnitude and phase of fundamental for a cosine function), together with synthesis signal. Here is an update include both digital and analog version.

example.Fourier.analog.qsch (5.3 KB)
fourier.cpp (5.5 KB)
Fourier-order1.qsym (1.3 KB)

1 Like

Thanks you much both…!!!