Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:59 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : FFT and similar

Author Message
KD5ZXG
Regular Member

Joined: 21/01/2022
Location: United States
Posts: 53
Posted: 08:16pm 03 Mar 2022
Copy link to clipboard 
Print this post

I wanted to continue this side topic without hijacking the original thread. Originally tried sending this to Volhout as PM, but that function appears broken.    

 KD5ZXG said (slightly edited for clarity)  

A sinewave times itself makes for rectified McDonalds arches, but squared in height. Rectification because negative times negative is positive. Times a squarewave of same phase and frequency makes similarly rectified mmmmmm's, but the gain is not squared.

Both above outcomes have a positive DC component. If phases oppose, the DC will be negative. If phases offset, results flutter between signs. Lowpass filter to measure phase shift. A sinewave times any other frequency (sine or square) makes a mess that lacks constant phase shift and low passes to zilch. Over time, all unmatched frequencies but maybe harmonics will remove themselves from the result. How much you lowpass determines how much mess leaks through.

I have almost described a homodyne or lock-in detector. 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 of a +1/-1 squarewave and integrate. Much easier, we only need add or subtract to each integrator. Now multiply our sine times a bunch of "sign"waves that differ only in period. Just need an array of period countdowns and integrators.

The sine*sine method is kinda like RMS, except we havn't yet taken the root of the mean squares. Sine*sign is plain unsquared average. These relate as they would in a multimeter. Magnitude needs adjustment (Pythagoras) to account for the unsquared sides. 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 same things, I would not know.

KD5ZXG

 Vohout said

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.

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

 KD5ZXG now adds

OK then, definitely not same as FFT, so maybe not wasting my time. For starters, I get both magnitude and phase as an unsquared 90 degree pair. FFT has never shown me phase, but maybe I just needed two of them...

I have a concern for frequencies between those being integrated don't fall through cracks, nor count twice. Thinking the low pass response (resolution bandwidth?) has to taper just right to blend with the next. Integrators (comparable to FFT bins?) also have to be properly spaced and maybe decay toward zero by some rule. Maybe the attack of most recent samples should also be gradual like a mirror of how they decay?  Not "Windowing" as you describe for an FFT, or maybe it is...

I use coherent rectangular & incoherent Blackman at work, and have a feel for how they look different. But don't know the math behind them.
Edited 2022-03-04 07:05 by KD5ZXG
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 10:06pm 03 Mar 2022
Copy link to clipboard 
Print this post

A few years ago I had need for a tool to help with voice exercises.
I couldn't find anything that was exactly what I wanted so I programmed my own "voice Trainer"



And the output:


My speech pathologist was impressed.
I still use most days.

I haven't tried to convert it to the CMM2 and probably never will.

When I was looking for inspiration I found this explanation of FFT:
http://blogs.zynaptiq.com/bernsee/dft-a-pied/
It is well worth a read.

Jim
VK7JH
MMedit
 
KD5ZXG
Regular Member

Joined: 21/01/2022
Location: United States
Posts: 53
Posted: 02:57am 04 Mar 2022
Copy link to clipboard 
Print this post

principles-of-lock-in-detection

More or less what I've been on about. Until "Signal mixing in the time domain" where math for glory of math obfuscates a simple process. Only gets worse from there...

As I see it, lock-in and FFT might be same things. One feeds and unfeeds products to a FIFO and keeps running totals of whats hiding in the middle, the other tries to do all multiplications and averages over an array of still data.

Lock-in has less work to do in the middle. If tapered ends are small compared to an untapered FIFO inbetween, it might also be very fast. The FFT can multiply against reference sines pre-tapered to a desired window, thus more flexible. When taper is necessary over the full pool of data, lock-in loses any on-the-fly advantage.

Both cancel unwanted frequencies by multiplication vs a reference averaged over time. I don't forsee a problem with that reference being dumbed down to a +/-1 "sign"wave as all harmonics are well above rectified DC and easily filtered, but there's no taper in that plan and wild ends could be a problem.

And this...
About Lock-In Amplifiers
Edited 2022-03-04 14:46 by KD5ZXG
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 07:35am 04 Mar 2022
Copy link to clipboard 
Print this post

  KD5ZXG said  principles-of-lock-in-detection

More or less what I've been on about. Until "Signal mixing in the time domain" where math for glory of math obfuscates a simple process.

It's only because of math(s) that much of this stuff exists at all.

People saw how math(s) could be used to achieve things which were otherwise impossible.

Sometimes that math(s) can then be used to make "a simple process".

It's not vital to understand the math(s) at that point, but someone had to in order for the process to exist at all.

John
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5089
Posted: 08:32am 04 Mar 2022
Copy link to clipboard 
Print this post

Lock-in(in the digital domain) and FFT are not really related. The only thing they share is that they perform math on a dataset to generate an output.

FFT and it's related inverse FFT may be capable of performing a similar function as the lock-in but I think that may be a huge overkill.

Basically a lock-in amplifier is an instrument that allows you to measure withing a very narrow bandwidth (not achievable by passive hardware filters) to reduce the noise contribution.

By running an FFT you translate the "noisy" input signal to a spectrum representation. By deleting all FFT output samples that are outside the bandwidth of the low pass filter, and performing an inverse FFT you have basically performed what the lock-in amplifier does. Measuring in a very narrow bandwidth. But....
FFT (and inverse FFT) get progressively more calculation intense when the sample array get's bigger (in factors of 2). To get anywhere near the performance of the documented systems (0.01Hz at 10kHz) you need to work with 2^21 FFT's. You can't get that anywhere real-time...

The lock-in principle is based on simple multiplication and addition/subtraction. In an FPGA you could run this at GHz speed, but your standard laptop with an external signal generator/ADC could do quite nice. It all boils down to where you make the analog/digital split.

When you look at the "100% digital" lock-in I really wonder if applying digital filters after the ADC could achieve similar. Digital filters can outperform hardware filters.

Volhout
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5089
Posted: 08:48am 04 Mar 2022
Copy link to clipboard 
Print this post

  TassyJim said  A few years ago I had need for a tool to help with voice exercises.
I couldn't find anything that was exactly what I wanted so I programmed my own "voice Trainer"



And the output:


My speech pathologist was impressed.
I still use most days.

I haven't tried to convert it to the CMM2 and probably never will.

When I was looking for inspiration I found this explanation of FFT:
http://blogs.zynaptiq.com/bernsee/dft-a-pied/
It is well worth a read.

Jim



Nice Jim !!! Running on a laptop ?
What Choir are you member of ?
I recently joined a choir (50 members) for mixed popular and religious songs.
Edited 2022-03-04 18:50 by Volhout
PicomiteVGA PETSCII ROBOTS
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 10:41am 04 Mar 2022
Copy link to clipboard 
Print this post

  Volhout said  

Nice Jim !!! Running on a laptop ?
What Choir are you member of ?


Laptop or my main PC.
I had the choice of getting successful voice training or learning sign-language.
Fortunately, the voice training was (partially) successful.
One vocal chord still paralyzed. The other one is working partially again.

Jim
VK7JH
MMedit
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025