Not only is there a glcdScope sketch which is useful for displaying voltage across the 0.1 Ω shunt in my 220V experiments, there’s also a little Spectrum Analyzer sketch to try out. *Yummie!*

Spectrum analysis tells you what frequencies are present in a given sample of a periodic signal. Lots of math there – just Google around for “Fast Fourier Transform” (FFT) and you’ll get it all on your plate if you’re curious.

But this stuff is a bit harder than a plain signal. Here’s what I’m seeing, with just a short wire connected, picking up some 50 Hz presumably (as with the scope test) – again with the “digital phosphor” persistence:

In *principle*, this graph is ok: lots of signal at lower frequencies and progressively less at higher frequencies. After all, with a perfect 50 Hz sine wave and no noise, we’d expect a single peak at the start of the scale.

The repeated peaks every few pixels also look promising. With a bit of luck they are in fact the harmonics, i.e. the 100 Hz, 150 Hz, … multiples – which is what you get when a signal is repetitive but not exactly a sine wave. Harmonics are what makes music special – the way to distinguish a note played on the violin and on the piano.

But I was hoping for something else: a bit more peaks at the right hand side of the graph. This would indicate that there are high frequencies in the signal, the computer’s switching power supply close to this setup, for example.

And worse: I’m seeing a completely flat line when hooking this up to the 220V current shunt. Looks like this signal is too weak to play FFT games with (should the data be auto-scaled?).

Anyway, here’s the glcdSpectrum50 sketch:

It relies on the fix_fft.cpp file by Tom Roberts which does the FFT heavy-lifting (original is here).

Also, note that I’m using a slightly different algorithm this time to determine the average signal value: the average of the *last* 256 samples is used to compute the center value subtracted from the *next* 256 samples. The outcome should be similar, as long as the signal is indeed symmetric around this value.

*All in all a nice try, but it didn’t really provide much new insight (yet?).*

Impressive, what can be done with this simple hardware in very short time! (I remember writing my own FFT completely in assembler on an Atari ST, that was hard work, at least for me :-) ) I would not expect to see sharp lines in the FFT output though (and this fits to what you get), as you will not sample complete periods of the signal (do you?) and you do not use a window filter function to attenuate this ‘windowing’ effect (Hamming, Hanning, …). And it is also unrealistic to see harmonics with a significant energy, where should they come from?

Nevertheless, very nice work, as always, Jörg.

PS: ’rounding’ the average (avg = (sum+128)>>8) could perhaps reduce ‘noise’ by half a bit

29 September 2011at9amIs your sampling frequency high enough to pick up the high frequency noise you’re looking for? Logging the values should boost any low amplitude signals.

29 September 2011at1pm