[LAD] Converting single-cycle wave to harmonic spectrum

Fons Adriaensen fons at linuxaudio.org
Mon May 10 13:02:33 CEST 2021


On Mon, May 10, 2021 at 12:20:56PM +0200, Jeanette C. wrote:

> The input waveform is exactly one single cycle
> The waveform has only harmonic overtones.

You may be making a dangerous assumption (if you want an accurate result):
that a single cycle corresponds exactly to an integer number of samples.

If that is the case, all you need is an FFT size equal to the number of
samples, AFAIK, fftw3 can do any size. Then each bin of the FFT output
will correspond exactly to an harmonic.

But in general, a single cycle will not be an integer number of samples,
and in that case there is no simple solution.

Suppose you have N samples, but the actaul period is N + eps, with
0 < eps < 1. If you know eps, you could resample the signal to an integer
number of samples or to some preferred FFT size. But now we have a new
problem: in order to do the resampling you'll need some extra samples
either before or after the ones you started with. If these are available,
and if you know that they are valid (i.e. they represent an identical
cycle), that is probably the way to go. And if not, there is no 'exact'
solution.

Maybe you could tell us what exactly you want to use this for, then a
pragmatic solution could be found.

Ciao,

-- 
FA



More information about the Linux-audio-dev mailing list