Adding harmonics

From the stack exchange link: Where 𝑏𝑛 represents the amplitude of nth generated harmonic, given a sine input.

I don’t know this math to understand it but some of the discussion of harmonics seems to imply a specific harmonic.

I’m not well-versed in waveshaping functions, but my basic understanding is that they produce harmonics up to a certain degree. I don’t know if you can produce higher harmonics without producing lower ones. I don’t know how much control you can get over which exact harmonics are added & their amplitudes.

I suggested pitch shifting because it would absolutely allow you precise control over frequency & amplitude of what you’re adding to the signal, but it sounds like this wouldn’t give you what you want.

Your goal may certainly be possible, but I’m struggling a bit to understand exactly what sound you’re trying to produce

You sing into a mic, routing the audio through your plugin. What exactly is the goal, in terms of what the output actually sounds like?
“Adding harmonics” is a bit general – what exactly are you hoping to hear in your plugin’s output?

as I said above


Thanks for the reply. Did you watch my videos linked above ? One shows a comparison to a UAD enhancer that produces a number of harmonics as shown in the vid. The harmonics they add create the character of that preset. The effect the UAD has on a sine wave under test is the same as it does to any other Audio. It adds a harmonic “additive” on top of whatever comes into it. so the goal is to simulate any harmonic distortion by turning on a setting a level of specific harmonics. All harmonics by definition are pure sine waves at a frequency of n * fundamental. I want to add harmonic distortion and control the level of all harmonics being added like a mixer. The image I included has a knob under each harmonic. In the future I would run a sine wave into it and set the levels of each harmonic and store the preset.

you have posted no video links


Strange.

ok, so is the second video what your goal is? you want to be able to manipulate harmonics like that, almost akin to polyphony?

If your goal is just to produce pure sine waves at specific frequencies, then you could just use simple sine wave oscillators and set their frequencies by using pitch detection to find the input signal’s fundamental frequency and then multiplying by N


That’s not possible since it would rarely be mono phonic. It could be vocals, drums keys full mix guitar. Imagine you run any signal into an LA2a or other tube device. It adds harmonics to whatever comes in. Play 5 notes on a guitar and it creates the same harmonic profile to every note.

polyphonic pitch detection algorithms do exist


but again, I’m not sure that pure sine waves at specific frequencies is really what you want


Thanks. That wouldn’t be the right solution.

if you’re trying to emulate the way tube distortion works, my understanding is that analogue devices create harmonic distortion as a byproduct of hard or soft clipping. The frequency content added to the input signal, and the amplitudes of these frequencies, are created as a byproduct of the physical properties of the way that sound works & the laws of physics.

I could be wrong, but I don’t believe that any existing harmonic distortion models work by saying “add this specific frequency at this exact amplitude”
 they simply run the sound through an algorithm that models what happens when analogue tubes induce clipping.

You could possibly achieve control by using physical modeling synthesis to change the physical properties of the “tubes” that are driving the harmonic distortion, but that’s way outside my area of expertise.

Agreed this is not something that I’ve seen to adjust a certain harmonic but I want to explore it. Distortion by clipping is easy to do. But it’s across the board. No separate control. Clip the top of the waves gives different results from clipping the bottom etc. what I need will likely come from some method of simulation.

yes, that’s what I said

I think what you’re looking for is Chebyshev wave shaping.

These allow you to create individual harmonics in a sort of “additive” way. The math is a bit intimidating but its not anything too crazy once you break it down.

Take a look at “Coefficients of Chebyshev Polynomials of the First Kind” here:

If you convert that to C++, and create a gain slider for each of the harmonics you would have what I think you’re looking for. Just make sure the signal you send into the Chebyshev wave shapers never exceeds 0dB. A tanh() on the input would take care of that.

2 Likes

Simply add the harmonics like this (if x is your input and y is your output): y = x + ax^2 + bx^3 +
 , then change a, b, 
 to the desired values. Beware of aliasing when your harmonics are higher than the Nyquist frequency, you‘ll have to oversample in that case.

1 Like

Thanks for the suggestions above. I am studying the ideas.

The coefficients in front of the harmonics will actually not be equal to what you’d see in an analyzer: if you look at, e.g., https://mathworld.wolfram.com/TrigonometricPowerFormulas.html you will see that the x^3 term will not only generate a peak at three times your base frequency, but will also add a contribution to your base frequency itself. Likewise, the x^4 term will generate a peak at 4 times your base frequency, but will also add a bit to the peak at two times your base frequency, and so on. But it’s not hard to match your desired harmonics outcome to the coefficients in your power series.

just out of curiosity, how would you go about calculating how much the x^3 term contributes to the base frequency, how much the x^4 term contributes to the x^2 term, etc
?

1 Like

Well for example sin^3(x) = 0.75sin(x) - 0.25sin(3x). So if your waveshaper is just y = x^3 and you look what it does to a sine wave, you will actually see about -2.5 dB at your base frequency [20 log10(0.75) to convert your voltage to decibels] and only -12 dB at three times the base frequency. In other words, y = 0.75*x - x^3 should get you a contribution at three times the base frequency only.
In the same way, to get a peak at 4 times the incoming frequency only, it’s not y=x^4 but y = x^2 - x^4 (that’s how the cos(2x) terms will cancel each other out in the trigonometric power formulas).

1 Like

Can you take the original and flip the phase and add it to the modified version and cancel the bump in the result, sum the result back with the original and effectively cancel any bump on the original.

Another way to say this is you have the original coming in which you preserve and then you have the math performed on the original and now you have that version as well then you take the one with the math on it and subtract the original from it that should leave only the upper Harmonics correct?