I have just started with Kicad 8 and tried FFT on an RC circuit. The result look strange and I do not understand what is wrong. Below see circuit and results:
Spice Netlist:
.title KiCad schematic
.save all
.probe alli
.probe p(V2)
.probe p(C1)
.probe p(R1)
linearize V(in) V(out)
fft V(in) V(out)
V2 in 0 DC 0 SIN( 0 1 1k 0 0 0 ) AC 1
C1 out 0 10u
R1 in out 1k
.end
your help will be much appreciated
The fundamental issue is you have not windowed the data and thus you have what is known as spectral leakage. This isn’t a Kicad/ngspice limitaton, this is fundamental to fft’s… How to mitigate it though is downto the tool
FFT only really works for complete cycles, and that is complete cycles of all frequencies of interest.
For a simple simulation like this you can set the simulation time to the EXACT multiple of the period.
Since it is a simple circuit (one that does not have harmonics) you could perform it over one cycle.
HOWEVER… The maximum frequency is half the sampling frequency and the minimum frequency is the simulation time.
Now for simulations with harmonics where ensuring you have completed cycles is “impossible” you perform what is windowing ( my favourite is blackman-harris but will manually perform a rectangle if I was EXACT results).
Whether ngspice supports a basic Hamming/Hanning/* window… I do not know and thus the alternative is to
Export as CSV and process with python
Run for a longer period and thus more cycles to mitigate aspects of the spectral leakage at the frequency of interest (at the expense of leakage at higher frequency )
Red is the sine input, green a resistor voltage divide by 2, violett a high-pass RC, orange the low-pass RC.
The fft here is provided by the fftw3 library (KiCad8.99). fft-rc.7z (6.0 KB)
With existing KiCad 8.99 (no fftw3) the result is much noisier.
thank you all for your response,
I realize that I was on the wrong path (I did FFT many years ago in school).
What I really was looking for was the spectrum, that means the frequences that I get after filtering. Is there a way to get that simulated?