It is far from perfect. At first - the signal from the DAC is not filtered. Second - the output buffer amplifier goes to a limiting on the signal levels close to GND and Vss, it is noticeable even visually, and produce harmonic components.
I donāt understand the behaviour of Pedroās FFT.
I use a 10kHz āsineā from the internal DAC, channel A with 0.5V/div, 100uS/div as an example.
[list]
[*]when I vary the amplitude of the sine, the spectrum changes completely. For example, at amplitudes of about 1.7V, the highest peak is at 20kHz, not 10kHz (and it is more then 2 div higher than the 10kHz)
[*]with an amplitude of 2.1V, the picture changes: now the highest peak is at 10kHz and 2 div higher than the 20kHz
[/list]
Maybe this has to do with the fact that only 256 samples are used, i.e. only about 10 periods and this is not enough - does the FFT only give good results when there is an integer number of periods in the 256 samples? Could this explain why the sines have so many harmonics?
I had another problem, which looks like a bug: when moving the ānavigator Bā, changing between the ātriggerā and the āauto/normā¦ā menus - but not changing anything at the settings - sometimes the FFT result change completely!!!
Two more questions: [list]
[*]if the number of samples is the problem, why not make an FFT with 4096 sample? Why is it more complicated than with 256?
The number of samples influences the resolution (frequency / x scale) of the FFT.
Canāt increase the number of samples at the moment because of the increase in program size/storage needs:
TTF coef_table - about 4KB more
the input and output arrays - about 6KB more
Iāve replaced the Hanning window lookup table with a function to generate the relevant indexed values at request, but that still isnāt enough.
Program size is already somewhat large because GCC does not optimize the code as well as IAR - by far.
Anyway, the functions are in place for using either 256 or 1024 samples, and I can get the 1024 samples FFT running under some circunstances, but donāt think itās relevant enough to spend more of my time with it.
Anybody can compile it with 1024 samples FFT support by changing 2 lines of code and uncommenting the needed coef_table values. The code is all there.
If someone wants a better FFT program, a dedicated FFT build can easily be made without issues, that can use 4096 samples.
Complete FFT re-implementation: (still has bugs)
- FFT assembly routines replaced with āno nonsenseā integer C code
- All calculations made in-place (half the memory used)
- Now using 512 samples (256 buckets)
- FFT range boundary painted in blue