Sum of harmonics with different phases - how to get the max peak?

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

@all yes I'm varying phases, number of sine and their amounts in real time. Thus, I'd like to keep the generated signal peaking the same db (i.e. normalizing). And yes: I'm working only with harmonics right now, no overtones (so foundamental and a random set of sine at 2x, 3x, 4x... 128x).

@aciddose: if I sum 3 random harmonics at different phases the results is rarely 3.0.
Last edited by Derozer on Wed Jul 15, 2020 11:34 am, edited 1 time in total.

Post

Another way to express that is: "There is no such thing as time."

We're only observing the emergent property of mixed frequency ratios while fundamentally they're all cyclic. We call this emergent property "time" but it really doesn't exist outside an abstraction we've invented based upon our perception. What does exist is the product of ratios.

If you have a simple problem with three ratios it does not make any sense to put "time" in there, as it has no place and no basis in reality. You only have three ratios of cyclic polar oscillation / orbits. Not even the polarity matters as it is simply a mirror of itself.

"Why does phase advance?" is a long standing unanswered question - albeit we can't really say whether it moves positively or negatively, those are both equal. We only know that our "time" has a particular polarity and we call the opposite "negative".
kryptonaut wrote: Wed Jul 15, 2020 11:18 am it's clear that (a) the max does not correspond with the max of either sine function, and (b) the max and min are very different magnitudes
You need to look at the fundamental and product of ratios and examine the problem according to Fourier theory. Those two frequencies are not whole ratios which is why you end up in that situation. The minima and maxima are equal magnitude if you take into account the zero frequency "DC offset".

You're right though, the point at which the peak occurs needs to take into account the product of phases in radians as well as frequencies. I'm not familiar enough with the Fourier transform to work out exactly how to deal with arbitrary phases.

I believe though we're looking at 1/pi, not just "1". So that would make the solution impossible as it includes an irrational number.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.

Post

Derozer wrote: Wed Jul 15, 2020 11:20 am @all yes I'm varying phases, number of sine and their amounts in real time. Thus, I'd like to keep the generated signal peaking the same db (i.e. normalizing). And yes: I'm working only with harmonics right now, no overtones (so foundamental and a random set of sine at 2x, 3x, 4x... 128x).
If harmonic amplitudes and phases are varying in realtime, then even if you could predict in advance what the max value would be so that you could scale the result, that scale factor would also be changing in realtime.

I think you'd get essentially the same effect by just using some kind of AGC (automatic gain control), which constantly monitors the peak value and adjusts the gain in realtime to keep the peak at or near a given value.

But musically speaking I think BertKoor's comment is worth considering.

Post

It should be possible to find the min/max for something like this with a fixed grid sampling:
sin(x*pi)/2 + sin(x*2*pi + pi/2)/2
https://www.wolframalpha.com/input/?i=s ... 2F2%29%2F2
Wolfram gives:
Image
... which is ultra nasty in terms of expense and depends upon the function anyway. If we switched from pi/2 to some other phase offset I'm not sure the maximum changes in an entirely predictable way. It's all about the common factors and such where 1/2 (pi/2) is trivial but an arbitrary value is then indeterminate and practically uncomputable.

There must be more efficient means though.
Last edited by aciddose on Wed Jul 15, 2020 12:14 pm, edited 1 time in total.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.

Post

Derozer wrote: Wed Jul 15, 2020 11:20 am @aciddose: if I sum 3 random harmonics at different phases the results is rarely 3.0.
The maximum you'll ever find is always 3. So if you have varying phases and magnitudes you can safely assume a maximum peak of three which would be useful to set up dynamic gain control or similar.

The "average" level is probably far less. For example in situations where the absolute peak is 16 I've found ~3 is the mean. Being able to figure out exactly why that is would be nice, but there is NO WAY it's computationally efficient.

Doing things "correctly" is almost NEVER the goal in audio software. It's always about how to get the best possible result with the least possible effort. What may be "mathematically perfect" almost never "sounds good" anyway. (While in almost all cases mathematical perfection doesn't even exist. It's turtles/approximations all the way down.)
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.

Post

kryptonaut wrote: Wed Jul 15, 2020 11:55 am
Derozer wrote: Wed Jul 15, 2020 11:20 am @all yes I'm varying phases, number of sine and their amounts in real time. Thus, I'd like to keep the generated signal peaking the same db (i.e. normalizing). And yes: I'm working only with harmonics right now, no overtones (so foundamental and a random set of sine at 2x, 3x, 4x... 128x).
If harmonic amplitudes and phases are varying in realtime, then even if you could predict in advance what the max value would be so that you could scale the result, that scale factor would also be changing in realtime.

I think you'd get essentially the same effect by just using some kind of AGC (automatic gain control), which constantly monitors the peak value and adjusts the gain in realtime to keep the peak at or near a given value.

But musically speaking I think BertKoor's comment is worth considering.
I could use a smart AGC, but the problem will persist with very low freq: It could take about seconds before to adust it ;) consider that I would manly use it as modulator (i.e. sort of adjustable lfo).

Any valid AGC that you know and I can experiment? I Always see them sold as "compressor".

Post

So you're designing an LFO which is made from various combinations of mainly low-frequency sines with varying phase and amplitudes, and as you adjust each component you want to simultaneously adjust the overall amplitude so the result always reaches +1 or -1 exactly? Or something like that?
Are the phase/amplitude values being changed by a UI and then remaining static, or are they themselves modulated and constantly changing?

Post

kryptonaut wrote: Wed Jul 15, 2020 2:07 pm So you're designing an LFO which is made from various combinations of mainly low-frequency sines with varying phase and amplitudes, and as you adjust each component you want to simultaneously adjust the overall amplitude so the result always reaches +1 or -1 exactly? Or something like that?
Are the phase/amplitude values being changed by a UI and then remaining static, or are they themselves modulated and constantly changing?
Exactly.

Right now by UI, but in the future a "control-rate" modulation is in program.

Post

If I really had to do this, I would periodically step through a single cycle in, say, 256 steps to find the approximate max value and just use that.

Post

kryptonaut wrote: Thu Jul 16, 2020 8:41 am If I really had to do this, I would periodically step through a single cycle in, say, 256 steps to find the approximate max value and just use that.
What I do right now more or less. The problem is when the cycle is long (0,25 hz for example, as said). It would introduce fade out/in for the first 4 seconds, since it will take long time to catch the approx max peak.

But probably its really a complex task that can be solved in this way. Just hoping in some magic math :P

Post

kryptonaut wrote: Thu Jul 16, 2020 8:41 am If I really had to do this, I would periodically step through a single cycle in, say, 256 steps to find the approximate max value and just use that.
Or maybe I've misunderstand? Are you suggesting to find max cycling the actual waveform every 256 samples? So at 0,25 hz, somethings like 690 values to be examined.

Mmm, maybe would be also good to do some kind of local search to catch the reason where the peak is max, than iterate around that range.

Any good algorithm that do this? What would you suggest?

Post

Derozer wrote: Thu Jul 16, 2020 2:38 pm Or maybe I've misunderstand? Are you suggesting to find max cycling the actual waveform every 256 samples? So at 0,25 hz, somethings like 690 values to be examined.
Not quite - what I was picturing was to take the fundamental frequency, say it's 0.25Hz --> 4s, then sample the composite waveform at (say) 256 intervals of 4/256 s (I chose 256 because you said up to 128 harmonics). So you always test the same number of values, whatever the frequency of the fundamental. It would only be an estimate of the peak, but maybe that's good enough for your application?

Post

Yes, 4*44100/256 = 690 more or less.
Not sure if I really got it than hehe.

Can you give to me an example with 3 harmonics, at 0,25hz (foundamental), 10hz (x40) and 12,25hz (x49)? You will sum each other (which will be 176400 samples lenght) and search for ABS(samples[x] every 256 samples, correct?

Post

No, I'm assuming you have a formula to generate your waveform as a sum of harmonics, so in your example sin(x)+sin(40x)+sin(49x). To estimate the max, you could evaluate one full cycle of this at 256 intervals.

MAX(ABS(sin(t)+sin(40t)+sin(49t))) where t goes from 0 to 2pi in steps of 2pi/256

So, not working with samples, but with the generating formula itself.

Post

I've read through this entire thread and I don't understand why the correct answer has been rejected. If you sum sinusoids of different frequencies together, the max peak is the sum of the amplitudes of the sinusoids. Why isn't that answer good enough?

Post Reply

Return to “DSP and Plugin Development”