MMBasic for Windows - betas

Author Message
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3991
 Posted: 10:23am 03 Mar 2022

KD5ZXG said  I originally tried sending this to Volhout as PM, but that function appears broken. Appears sent, but the TO: name somehow went blank. Forgive if this response is not entirely on-topic.

A sinewave times itself makes for rectified McDonalds arches, but squared in height. Rectification because negative times negative is positive.

Times a squarewave +/-1 of same phase and frequency also makes rectified mmmmmm's, but the gain is unity and not squared in magnitude.

Both the above outcomes have a positive DC component. If the phases oppose, the DC will be negative. If phases offset, the result flips between both signs. DC can be lowpass filtered to measure phase shift.

A sinewave times any other frequency makes a mess that low passes to zilch. Over time, all other frequencies but harmonics will remove themselves from the result. How much you lowpass determines how much mess leaks through, but very narrow lowpass is easy.

I have almost described a homodyne detector or lock-in amplifier. Except they usually work in 90 degree pairs, so to produce a two part vector. Let's do that.

Instead of multiplying sines and integrating over time, lets multiply only by the sign +1/-1 of a squarewave and integrate. Much easier, we only need add or subtract...

Now multiply our sine times a bunch of "sign"waves that differ only in period. Just need an array of countdowns and an array to integrate each result.

The sine*sine method is kinda like RMS, except we havn't yet taken the root of the mean squares. Sine*sign is plain old average. Probably relate just like they would for a multimeter. Vectors might need slight adjustment to account for that cheat.

I am not mathematical and don't know how FFT works. I'm not sure this alternate makes sense or less work. If I were describing the same thing, I would not know.

KD5ZXG

Fourier transform works on repetitive signals. (google "wiki FFT").
In theory these signals repeat until eternity.
If you take a snapshot of these signals (i.e. 10 sine waves) the beginning and the end of the 10 sine waves represent a distortion of the "eternal signal", they are distortions.

To minimize the disruption effect of the beginning and end of the snapshot, each sample in the snapshot is "weighted". It's contribution to the Fourier Transform is made more -or less- important. The "weighting" is called "windowing".

There are many types of windows. There is a rectangular window (meaning all samples have the same weight), there is triangular weighting (the first and last samples have zero weight, the centre samples have maximum weight. Samples in between have a weight that is a linear interpolation between first and centre sample.
If you execute the program in my post, and press "w" a few times, you see a number of windowing techniques, and the effect on waveform and FFT.

One of the weighting standards is the "Hann Window". This is similar to the triangular windowing, but samples between first and centre are weighted with a sine^2 function.

Play with the program, and experience.

Vohout

note: the FFT window shows linear magnitude FFT for demonstration purpose (the lin2log function is commented out).
Edited 2022-03-03 20:24 by Volhout