# Creating odd harmonics without the fundamental

I'm interested in creating a series of odd only harmonics, without the fundamental, for audio use.

As an example the input could be a sine wave at specific frequency $f$ and output is $3f$, $5f$, $7f$, etc. - but without the original $1f$.

Since the $1f$ (in a real audio system) is unknown and the input is multi-tone, just filtering the $1f$ out is not an option.

Any idea for replacing an input of $1f$ with an output of $3f$, $5f$, $7f$, etc. ?

Edit: Additional information from the deleted post

Example: Let's assume the fundamental to be anything possible between 100 and 4000 Hz. Whats more, what if the input is multitone (as most music is...). 50 and 425 Hz input simulatenously ??

Im looking for a mathematical function which can recreate any fundamentals odd harmonics, in a multitone input...

• is your question about how to make a device where a single sinusoid goes in and what comes out is an (even or odd) harmonic only? the answer is "Tchebyshev polynomials". that gets you 1 harmonic. then you have to add up the outputs of several of these to get you a collection of harmonics. – robert bristow-johnson Nov 16 '15 at 6:24
• dsp.stackexchange.com/q/5959/29 – endolith Nov 16 '15 at 16:46
• actually my question is how to produce only harmonics 3,5,7 and cancel out the original F, without knowing what it might be (so I can;t just add a high pass filter). – Malcolm Rest Nov 16 '15 at 18:03
• you need to be much more clear about technically what you have for an input and what you are looking for in an output. if you want to "create" harmonics from where there were none, it's gonna be a non-linear function. if you want to remove the fundamental and, presumably, all even-order harmonics, that would be a special kind of tuned filter (which would need a pitch detector to tune it).  so which it is? – robert bristow-johnson Nov 16 '15 at 22:32

Im looking for a mathematical function which can recreate any fundamentals odd harmonics, in a multitone input...

(emphasis by me)

What you ask for is not possible. If you demand multiple tones and complex tones as they appear in music, then your problem leads to a conflict. A complex tone comes with overtones. Even if you have a process that adds odd harmonics to each sinusoidal component, then the even overtones of the fundamental frequency will contribute even harmonics. That is because an odd number multiplied with an even number is again even.

So circumvent that, you would have to identify the fundamental frequency of complex tones first, leading you directly to the problem of polyphonic pitch detection which remains mostly unsolved.

Maybe you should explain what you're really trying to accomplish, as in what the application is that you have in mind. With that information it's quite likely that we can come up with a relaxed set of requirements that can actually be implemented.

• $y(t) = x(t)^3 - \frac 3 4 x(t)$ (3rd harmonic)
• $y(t) = x(t)^5 - \frac {10} {16} x(t)$ (harmonics 3, 5)
• $y(t) = x(t)^7 - \frac {35} {64} x(t)$ (harmonics 3, 5, 7)
• etc.

Presumably this is a sampled system, so you could choose N based on your Nyquist frequency?

There's a pattern to the coefficients that cancel out the fundamental but I don't know what it is. :)

• Note that with these formulas the different harmonics have different scale factors. If you want the same scaling for all harmonics you just have to sum the appropriate Chebyshev polynomials. E.g., for the 3rd and 5th harmonic you'd get $y(t)=T_3(x(t))+T_5(x(t))$. Also note that this will only work for a sinusoidal input. – Matt L. Nov 16 '15 at 15:30
• In addition to only working for sinusoidal input, the amplitude of the input sinusoid must also be constant and equal to 1. – Jazzmaniac Nov 16 '15 at 16:34
• Yes. I pretty went off using Chebyshev for this problem, as the ouptut scaling (e.g. harmonics) are not linearly scaled to the input, The result si really bad sound. – Malcolm Rest Nov 16 '15 at 18:05

(Note that this answer was written before the question was edited in a way which made clear that the input is not sinusoidal, and that filtering out the fundamental frequency is also no option. Anyway, for the time being I'll leave it as is.)

One easy way to achieve this is to symmetrically clip the sinusoid, which will create all odd multiples of the fundamental frequency, and then use a high-pass filter to filter out the fundamental frequency.

• actually my question is how to produce only harmonics 3,5,7 and cancel out the original F, without knowing what it might be (so I can;t just add a high pass filter). – Malcolm Rest Nov 16 '15 at 18:03
• @Downvoter: If you check the edit history of the question, you'll see that with the initial version of the question (which I tried to answer) it was not clear that the input is multi-tone, and that filtering is not an option. – Matt L. Nov 16 '15 at 20:27

The function should be something like this:

SR=sampling rate
T=duration in second of the output
t=0:(1/SR):T
X=fft(x)
freq=index of max(mod(X)) from 0 to SR/2 (in [Hz])
ai=[1 1 0.5 ... ] %harmonics amplitude
y=zeros(length(t))
for i=1:n %n harmonics, n=floor(SR/2/(freq*2))-1 if you want all the harmonics
y=y+ai(i)*sin(2*pi*(2*i+1)*freq*t)
end


EDIT:

If x is a sin and you don't want to use FFT you can find the freq quite well in this way $O(n)$:

sgn=sign(x);
i=1;
periods=0;
Psmp=0;
while i<length(t)
if (sgn(i)~=sgn(i+1) && sgn(i+1)~=0) || sgn(i)==0
for j=(i+1):length(t)-1
if (sgn(j)~=sgn(j+1) && sgn(j+1)~=0) || sgn(j)==0
Psmp=Psmp+(j+j+(sgn(j)~=0))/2-(i+i+(sgn(i)~=0))/2;
periods=periods+1;
break;
end
end
i=j;
end
i=i+1;
end

if periods>0
Psmp=Psmp/periods/2;
P=Psmp/SR;
freq=1/P;
end


It makes a linear interpolation of each couples of samples about 0 and finds the average of the periods.

• Hi,thanks for the answer, but I'm looking for a plain math/trigonometric function for the harmonics re-creation, not FFT, for obvious reasons. – Malcolm Rest Nov 16 '15 at 13:07
• Have you tried your "algorithm" for finding the period of a sinusoid? The result might be surprising ... – Matt L. Nov 16 '15 at 13:40
• I've wrote a new solution to find period that works quite well – Andrea Nov 16 '15 at 20:44