1
$\begingroup$

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...

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$ Nov 16, 2015 at 6:24
  • 1
    $\begingroup$ dsp.stackexchange.com/q/5959/29 $\endgroup$
    – endolith
    Nov 16, 2015 at 16:46
  • $\begingroup$ 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). $\endgroup$ Nov 16, 2015 at 18:03
  • $\begingroup$ 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? $\endgroup$ Nov 16, 2015 at 22:32

4 Answers 4

2
$\begingroup$

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.

$\endgroup$
1
$\begingroup$
  • $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. :)

$\endgroup$
3
  • 2
    $\begingroup$ 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. $\endgroup$
    – Matt L.
    Nov 16, 2015 at 15:30
  • 1
    $\begingroup$ In addition to only working for sinusoidal input, the amplitude of the input sinusoid must also be constant and equal to 1. $\endgroup$
    – Jazzmaniac
    Nov 16, 2015 at 16:34
  • $\begingroup$ 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. $\endgroup$ Nov 16, 2015 at 18:05
1
$\begingroup$

(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.

$\endgroup$
2
  • 1
    $\begingroup$ 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). $\endgroup$ Nov 16, 2015 at 18:03
  • $\begingroup$ @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. $\endgroup$
    – Matt L.
    Nov 16, 2015 at 20:27
1
$\begingroup$

The function should be something like this:

SR=sampling rate
T=duration in second of the output
t=0:(1/SR):T
x=your sin wave input
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.

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$ Nov 16, 2015 at 13:07
  • $\begingroup$ Have you tried your "algorithm" for finding the period of a sinusoid? The result might be surprising ... $\endgroup$
    – Matt L.
    Nov 16, 2015 at 13:40
  • $\begingroup$ I've wrote a new solution to find period that works quite well $\endgroup$
    – Andrea
    Nov 16, 2015 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.