Sum of harmonics with different phases - how to get the max peak?
-
- KVRAF
- 3080 posts since 17 Apr, 2005 from S.E. TN
I don't currently have access to math tools I can remember how to operate, to investigate. Nor curious enough to re-learn just for idle curiosity. Never had matlab, can't recall how to operate Octave.
Ignorant musings-- Allowing only integer harmonic frequencies-- A discrete Dirac impulse-- Kronecker delta function: One lonely sample value of 1.0 in a buffer full of zeros. The Crest factor would depend on buffer size. Lower frequency waveforms, bigger buffer sizes, would have bigger Crest factors of course.
For any given buffer size, if the max peak is always <= 1.0, does a Kronecker delta waveform have the biggest possible Crest factor? For example a 256 sample Kronecker delta I think would have an RMS level of 0.0625 and a Crest factor of 16 or about 24 dB.
OK we take the DFT of the 256 sample buffer and get 128 equal-amplitude harmonics? Inverse DFT gives us back the Kronecker delta. Are the DFT harmonic levels 1.0 / 128? Could you sum up whatever number pops out of the 128 DFT bins and get the 1.0 peak of the original Kronecker delta? Or maybe the DFT harmonic levels are RMS and you would have to multiply them by 1.414 or whatever to match the sum peak of 1.0? Or something else entirely?
I can't remember how to conveniently use a tool to find that out. If I re-learn just to satisfy passing curiosity, will have forgotten again before I need to use the skill again.
So anyway, if the Kronecker DFT levels and phases really are the biggest crest factor we can get out of an n-sized buffer peaking at 1.0-- If we begin scrambling phase of the equal-amplitude DFT bins and doing iDFT, would some phase combinations give a max peak even bigger than 1.0? Or a Crest Factor even bigger than 24 dB?
And what kind of scrambled phase would give the minimum Peak, or the lowest possible Crest factor given the 128 equal-amplitude harmonics?
Just geezer rambling, not important.
Ignorant musings-- Allowing only integer harmonic frequencies-- A discrete Dirac impulse-- Kronecker delta function: One lonely sample value of 1.0 in a buffer full of zeros. The Crest factor would depend on buffer size. Lower frequency waveforms, bigger buffer sizes, would have bigger Crest factors of course.
For any given buffer size, if the max peak is always <= 1.0, does a Kronecker delta waveform have the biggest possible Crest factor? For example a 256 sample Kronecker delta I think would have an RMS level of 0.0625 and a Crest factor of 16 or about 24 dB.
OK we take the DFT of the 256 sample buffer and get 128 equal-amplitude harmonics? Inverse DFT gives us back the Kronecker delta. Are the DFT harmonic levels 1.0 / 128? Could you sum up whatever number pops out of the 128 DFT bins and get the 1.0 peak of the original Kronecker delta? Or maybe the DFT harmonic levels are RMS and you would have to multiply them by 1.414 or whatever to match the sum peak of 1.0? Or something else entirely?
I can't remember how to conveniently use a tool to find that out. If I re-learn just to satisfy passing curiosity, will have forgotten again before I need to use the skill again.
So anyway, if the Kronecker DFT levels and phases really are the biggest crest factor we can get out of an n-sized buffer peaking at 1.0-- If we begin scrambling phase of the equal-amplitude DFT bins and doing iDFT, would some phase combinations give a max peak even bigger than 1.0? Or a Crest Factor even bigger than 24 dB?
And what kind of scrambled phase would give the minimum Peak, or the lowest possible Crest factor given the 128 equal-amplitude harmonics?
Just geezer rambling, not important.
- KVRAF
- 5140 posts since 22 Jul, 2006 from Tasmania, Australia
I think it as aciddose said, for 3 normalized sine osc with different phases, the max peak is always 3 in time
-but you can chop that down and get the max peak for the cycle in realtime and then alter the amplitude of the next cycle possibly
-but you can chop that down and get the max peak for the cycle in realtime and then alter the amplitude of the next cycle possibly
- KVRAF
- 12555 posts since 7 Dec, 2004
If the three sines have any frequency ratio other than a whole ratio... for example 1/3 or 5/1 or similar, there is always certainty that the irrational phases will eventually all line up.
When you have whole / integer frequency ratios this is impossible: harmonic ratios (1/1, 1/2, 1/3, 1/4) never "line up" because their relative phases remain in "sync". There is no drift over time, so any sum of partials at harmonic ratios may have a peak less than N.
This is because even prime numbers are sums of lesser primes. For example 5 = 3 + 2, 7 = 5 + 3 and so on. https://en.wikipedia.org/wiki/Integer_factorization
When you have irrational ratios ... that's a contradiction... I mean where the frequencies can't be expressed as a fraction x/y using whole numbers; eventually the phases will all drift to the point where the line up together because we can't represent an irrational number. So the actual ratio will look like it's irrational, but it's in fact just a very large ratio like 2758284/2479539. When you combine lots of these "detuned" frequencies together they'll all eventually line up.
A good common practice example of this is a chord with an equal temperament fifth. Since the ratio is 2^(7/12) (1.49830707~) rather than 3/2 (1.5) it drifts, but it still eventually phases back into sync over time. The amount of time is just very long rather than 3/2 = 2 cycles (? if I'm doing that correctly.)
It's very likely however for any particular set of ratios+phases that the actual peak will be close to N or close to the mean (average) or mode of the 'probability' distribution even when in "sync" (a "small" fraction), depending upon the distribution.
In an unskewed normal distribution the most common values will always be near the middle, such as IQ = 100. It seems we're dealing with that here, the apparent skew distributions actually look like 1/2 of a Gaussian. It's hard for me to tell though and I'm not familiar enough with statistics to intuit whether that's the case.
When you have whole / integer frequency ratios this is impossible: harmonic ratios (1/1, 1/2, 1/3, 1/4) never "line up" because their relative phases remain in "sync". There is no drift over time, so any sum of partials at harmonic ratios may have a peak less than N.
This is because even prime numbers are sums of lesser primes. For example 5 = 3 + 2, 7 = 5 + 3 and so on. https://en.wikipedia.org/wiki/Integer_factorization
When you have irrational ratios ... that's a contradiction... I mean where the frequencies can't be expressed as a fraction x/y using whole numbers; eventually the phases will all drift to the point where the line up together because we can't represent an irrational number. So the actual ratio will look like it's irrational, but it's in fact just a very large ratio like 2758284/2479539. When you combine lots of these "detuned" frequencies together they'll all eventually line up.
A good common practice example of this is a chord with an equal temperament fifth. Since the ratio is 2^(7/12) (1.49830707~) rather than 3/2 (1.5) it drifts, but it still eventually phases back into sync over time. The amount of time is just very long rather than 3/2 = 2 cycles (? if I'm doing that correctly.)
It's very likely however for any particular set of ratios+phases that the actual peak will be close to N or close to the mean (average) or mode of the 'probability' distribution even when in "sync" (a "small" fraction), depending upon the distribution.
In an unskewed normal distribution the most common values will always be near the middle, such as IQ = 100. It seems we're dealing with that here, the apparent skew distributions actually look like 1/2 of a Gaussian. It's hard for me to tell though and I'm not familiar enough with statistics to intuit whether that's the case.
Last edited by aciddose on Thu Jul 23, 2020 7:08 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.
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.
- KVRist
- Topic Starter
- 180 posts since 18 Nov, 2017
The problem is when the "cycle" is long. Having a foundamental of 1/4 hz and two additional harmonics starting at different phase, the "real time" processing will end up as a sort of gain modulation for about 4 seconds. Which is a side-effect that I'd like to avoid.
Not sure also about the meaning of "max peak is always 3": summing 3 harmonics with different phases is very unlikely to reach 3.0. Whats the point to evalutate a "max" peak when i quite never reach it? Not sure I got this point
Last edited by Derozer on Thu Jul 23, 2020 7:10 pm, edited 1 time in total.
- KVRAF
- 12555 posts since 7 Dec, 2004
You'll most often reach it or approximate it. The average is less than 3 for harmonic partials but if you're changing the ratios and phase dynamically it makes the most sense to fix the gain to 1/3rd as previously stated.
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.
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.
- KVRist
- Topic Starter
- 180 posts since 18 Nov, 2017
I've tried triggering 10 times random phase and watch into a scope the reached peak with sum/3.0. Result is far away below 1.0... it range between 6.0 and 8.0.
I'll post a video later or tomorrow.
- KVRAF
- 12555 posts since 7 Dec, 2004
Yes, the average is less than 3, but the max for a sum of non-harmonic partials is 3 = (N). You need to pick a value that never changes, or you'll be introducing amplitude modulation into the result.
You've had a ton of suggestions and it's very clearly been stated that what you want is impossible. So it's now up to you to implement whatever works for you. You can't come back to reply to the facts we've stated with some subjective opinion on the matter.
(edit to clarify, I think this is the source of misunderstanding. The peak for a sum of harmonic partials is not necessarily = N.)
You've had a ton of suggestions and it's very clearly been stated that what you want is impossible. So it's now up to you to implement whatever works for you. You can't come back to reply to the facts we've stated with some subjective opinion on the matter.
(edit to clarify, I think this is the source of misunderstanding. The peak for a sum of harmonic partials is not necessarily = N.)
Last edited by aciddose on Thu Jul 23, 2020 7:35 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.
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.
- KVRAF
- 12555 posts since 7 Dec, 2004
I'm not 100% certain I follow you completely, but you're aware of the real additive band-limited impulse, right? All phases = 0, all amplitudes = 1, all harmonic partials of length = 1024:
That should be the highest peak you can get with equal phase. The rectangular pulse should transform into a translated sinc pulse in frequency and phase. The "real unit impulse" in time-domain we're seeing here is the opposite version of the rectangular pulse in frequency-domain. So if we used a narrowed pulse it should only change the scale of the translated version.
It doesn't seem intuitively so that the unit sample delta function should have the maximum peak... I suppose the greatest peak may be with varying amplitude and phase, as some partials may have a detrimental impact on the peak and so those would require lower or zero amplitude.
I'm certain this must be a well established function but I don't know the answer either. "What is the band-limited additive (summed harmonic-partial) signal with the maximum time-domain peak?"
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.
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.
-
- KVRist
- 81 posts since 24 Oct, 2000 from Bremen, Germany
While the maths is interesting, if it's for a LFO waveform you could use a soft clipper to enforce a known peak level - or better a sine waveshaper to avoid flattening off the tops and bottoms.
-
- KVRAF
- 3080 posts since 17 Apr, 2005 from S.E. TN
Thanks aciddose. Been years since I programmed with FFT and never knew a lot about it. Recalled that DFT and iDFT are supposed to be completely reversible within rounding error, and recalled that a unit sample delta function yields equal amplitude harmonics but did not remember that the equal amplitude amplitude harmonic level in that case is supposed to be 1.0. Erroneously recalled it some lower value.aciddose wrote: ↑Thu Jul 23, 2020 7:30 pmI'm not 100% certain I follow you completely, but you're aware of the real additive band-limited impulse, right? All phases = 0, all amplitudes = 1, all harmonic partials of length = 1024:
That should be the highest peak you can get with equal phase. The rectangular pulse should transform into a translated sinc pulse in frequency and phase. The "real unit impulse" in time-domain we're seeing here is the opposite version of the rectangular pulse in frequency-domain. So if we used a narrowed pulse it should only change the scale of the translated version.
It doesn't seem intuitively so that the unit sample delta function should have the maximum peak... I suppose the greatest peak may be with varying amplitude and phase, as some partials may have a detrimental impact on the peak and so those would require lower or zero amplitude.
I'm certain this must be a well established function but I don't know the answer either. "What is the band-limited additive (summed harmonic-partial) signal with the maximum time-domain peak?"
Yesterday found a couple of online references.
http://www.dspguide.com/ch11/1.htm
In your posted iDFT plot, are the non-zero values surrounding the unit sample delta because the iDFT is automatically "anti-aliasing" the impulse? I mean, references say that DFT and iDFT are reversible-- And apparently real DTFT on a clean unit impulse yields the "equal-level 1.0 harmonics" so is the iDFT failure to cleanly re-create the unit impulse an "exception to the reversibility rule"?
So anyway I was just trying to think up the biggest possible crest factor waveform within the constraint that Max Peak = 1.0. Can't think of a waveform which would have a bigger crest factor than a single sample = 1.0 and the rest of the samples = 0.
However if all harmonics = 1.0 then scrambling the phase could make peaks bigger than the 1.0 unit delta. With the previous example 256 sample buffer, 128 harmonics of 1.0 amplitude. If we adjust bin phases so that a peak of every harmonic lines up with harmonic 1 peak, then the iDFT peak ought to hit 128? Dunno what the rest of the wave would look like. Maybe the crest factor would get even-more-huger, or maybe the RMS would get real big along with the Peak, and the crest factor wouldn't get outrageous?
Reminds of possibly bad thinking from a couple decades ago-- Had been playing with scrambling phase of geometric waveforms, square, ramp, triangle. Maybe was wrong but at the time it looked like those geometric waveforms were the "most compact" "smallest crest factor" phase alignment for that set of harmonic amplitudes. Scrambling the phase resulted in "less compact" "bigger crest factor" waveform for square, ramp, triangle.
Maybe was wrong at the time and there are even more compact, smaller crest factor phase alignments for those geometric waves. Dunno.
However, it looks like a unit impulse waveform is also a "very compact" "low crest factor" representation of the bin amplitudes, even if the unit impulse waveform might happen to be the "biggest possible crest factor wave" which peaks at 1.0.
Not important. Not trying to prove anything just thinking about it.
- KVRAF
- 12555 posts since 7 Dec, 2004
It's not a transform, that's just a direct summation of time-domain partials. The transform of the time-domain waveform isn't a perfect rectangle and seems to be an integrated sinc if not every partial is = 1.0. I've found it's easier to work with additive sums directly rather than Fourier synthesis as some of the results you get due to periodicity are difficult to understand intuitively. With full band sums however the rectangular window Fourier transform is exactly what you'd expect: the magnitude of each partial is exact. There is always a small amount of error due to the stdlib sin() approximation, so to get really high accuracy results requires an ultra-high precision sin() and cos() implementation and double or higher precision computation.JCJR wrote: ↑Sat Jul 25, 2020 2:48 am In your posted iDFT plot, are the non-zero values surrounding the unit sample delta because the iDFT is automatically "anti-aliasing" the impulse? I mean, references say that DFT and iDFT are reversible-- And apparently real DTFT on a clean unit impulse yields the "equal-level 1.0 harmonics" so is the iDFT failure to cleanly re-create the unit impulse an "exception to the reversibility rule"?
Yeah, as far as crest factor as that's the definition of such of course. N/0 = inf (ratio of peak to remainder of signal), so as there's nothing greater than infinity it must be.
It seems as if it should be 128 intuitively by assuming sin(pi/2) = 1, but the crest factor will always be low as the phase of all the partials align to that peak gradually rather than suddenly. The waveform is continuous rather than discontinuous, so the peak/nonpeak ratio is finite rather than infinite.JCJR wrote: ↑Sat Jul 25, 2020 2:48 am However if all harmonics = 1.0 then scrambling the phase could make peaks bigger than the 1.0 unit delta. With the previous example 256 sample buffer, 128 harmonics of 1.0 amplitude. If we adjust bin phases so that a peak of every harmonic lines up with harmonic 1 peak, then the iDFT peak ought to hit 128? Dunno what the rest of the wave would look like. Maybe the crest factor would get even-more-huger, or maybe the RMS would get real big along with the Peak, and the crest factor wouldn't get outrageous?
I suppose the answer there is that when we look at the unit impulse we're imagining a Kronecker delta, but in actuality it's sinc(). So the crest factor for sinc() is the true value as the unit sample doesn't actually exist. That's probably what we see when the signal is transformed and then inverse transformed: the continuous nature of the true underlying sinc() is exposed.
It's all interesting foundational stuff that is easy to forget about. Some things about phase such as triangle = symmetric parabola (quadratic) are obvious although they're not widely known or mentioned. A mathematics tool with higher precision would probably be the best thing to use to play around with sums of partials + Fourier transforms. I've built my own tools but I've always focused on priorities other than maximizing precision, so things I believe are due to error may or may not be... I can't say whether the inverse transform of a rectangle is actually the same as the time-domain sum of partials or not, or whether the amplitude should be == N.
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.
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.
- KVRAF
- 12555 posts since 7 Dec, 2004
This is likely because when you compute the transform with anything but a rectangular window, you're actually computing the modulated/product version of the signal combined with the window. In order to get the normalized output levels you need to normalize the window to have a mean equal to the normalized rectangle == 1.0.JCJR wrote: ↑Sat Jul 25, 2020 2:48 am Recalled that DFT and iDFT are supposed to be completely reversible within rounding error, and recalled that a unit sample delta function yields equal amplitude harmonics but did not remember that the equal amplitude amplitude harmonic level in that case is supposed to be 1.0. Erroneously recalled it some lower value.
Code: Select all
const auto window_name = select_window<T>(window, window_type, width);
const auto reciprocal = T(1.0) / mean<T>(window, width);
// this is somewhat dumb from a precision standpoint
mul<T>(window, reciprocal, width);
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.
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.
-
- KVRist
- 439 posts since 8 May, 2007
Hi all,
Once again for exercising my new math package and investigating the topic of this thread, I have performed simulations, this time of a sampling algorithm for estimating the maximum absolute value of the sum of harmonics with randomly chosen parameters. This algorithm limits the sampling to the locations of the zeros of the highest harmonic, rather than sampling more densely at a predetermined, small interval. Again, because this may be of limited interest, I'll just post the URL:
Harmonic Addition Sampling Algorithm
Regards,
Dave Clark
Once again for exercising my new math package and investigating the topic of this thread, I have performed simulations, this time of a sampling algorithm for estimating the maximum absolute value of the sum of harmonics with randomly chosen parameters. This algorithm limits the sampling to the locations of the zeros of the highest harmonic, rather than sampling more densely at a predetermined, small interval. Again, because this may be of limited interest, I'll just post the URL:
Harmonic Addition Sampling Algorithm
Regards,
Dave Clark
- KVRist
- Topic Starter
- 180 posts since 18 Nov, 2017
What's the best method for "rendering" one frame and finding the peak?
I find that play the whole signal, sample by sample, and do a simple "max(currentMaxPeak, currentSample)" have the problem that, due to the low amount of samples, the analysis could end wrong if the frequency is high.
Here are some samples at ~20khz for example:
Its a good approch to reduce freq during the analysis? Or there are some fancy tricks?
Thanks
- KVRAF
- 12555 posts since 7 Dec, 2004
Given those three samples you can refine the result by computing the half-phase values. From the results pick the highest magnitude samples and a mid-point then repeat until you get the desired precision. There are many related variations to such an algorithm.
https://en.wikipedia.org/wiki/Newton%27s_method
Also you're still stuck on "frequency". You're thinking about the problem in the wrong way and not taking into account the rules from the sampling theorem and similar.
https://en.wikipedia.org/wiki/Nyquist%E ... ng_theorem
https://en.wikipedia.org/wiki/Newton%27s_method
Also you're still stuck on "frequency". You're thinking about the problem in the wrong way and not taking into account the rules from the sampling theorem and similar.
https://en.wikipedia.org/wiki/Nyquist%E ... ng_theorem
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.
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.