I need to compute the amplitude of a certain frequency band as the input to a PID algorithm. My system looks like this:

[Sine Generator] -> [Actuator] -> [Physical complex coupling] -> [Sensor]
  ^                                                                 |
  |                                                                 |
  +--[PID Control Algorithm] <---- [FFT Amplitude computation] <----+

The PID controller adjusts the amplitude of the sine wave until the sensor and FFT register the correct amplitude in the output signal. In order to have a performant system, I need to compute the amplitude as quickly as possible so that the PID controller can make adjustments based on the most recent events.

In normal analysis, I would use data from the future to calculate the amplitude at a given point in time, but that information is not available when I need it. As a result, the input data is all from the past. (Also, during the initial start-up of the system, I have no data at all!) The number of missed cycles is dependent on my window size - for accuracy, I would like it to be as large as possible, but for latency, I would like it to be as small as possible (I have abundant processing power, that's not a significant constraint yet).

Due to windowing, the dominant samples used as input to the FFT are several cycles before the present time and the most recent, most important samples are only very slightly weighted. The obvious solution would be to adjust the windowing function such that the most recent cycles are heavily weighted - essentially, using just one side of a windowing function. However, this does not seem to preserve the desired effects of the windowing function, as explained (somewhat circuitously) in this question: FFT with asymmetric windowing?.

I've also tried inverting and mirroring the data, which works when the input signal is a pure sine wave (of varying amplitude) at a zero-crossing, but introduces artifacts at other times. I've begun looking into the Goertzel algorithm and sliding DFTs, but those seem to only improve the difficulty of the computation and not the latency of the result.

How can I reduce the lag associated with sampling a real-time signal?

  • $\begingroup$ You're telling much, but not what (and how) exactly you compute with your fft. From what you wrote, a Fourier method is likely not ideal and there are probably much more suitable methods for your specific problem. So maybe you can add the relevant technical details. $\endgroup$
    – Jazzmaniac
    Nov 24, 2014 at 20:12
  • $\begingroup$ Hi @Jazzmaniac, I'll try to extract the exact methods used and update this post later - the actual implementation went through a lot of revisions, and I want to make sure that I post something which works, but I'm really interested in understanding how analysis on real-time signals works in general. Are all Fourier-based analyses on real-time signals delayed by half of the window size? $\endgroup$
    – kvermeer
    Nov 25, 2014 at 13:07
  • $\begingroup$ Also, is C# code OK? I see a lot of Matlab code here, but not a lot of other languages. And should I extract the relevant functions from the Math.NET Numerics package, or is that library well-understood? $\endgroup$
    – kvermeer
    Nov 25, 2014 at 13:09
  • $\begingroup$ I was more thinking of mathematical detail, but code is ok too. Any language that one can decipher would do. It should not contain a lot of obscure function calls and rely on unknown context. So high level pseudo code would be ideal $\endgroup$
    – Jazzmaniac
    Nov 25, 2014 at 15:25


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.