So I have been lately looking at a python implementation of Karplus Strong algorithm, or more particularly of the system:

\$ y[n] = \alpha y[n-M] + x[n] \$

From what I understand, \$ x[n] \$ is supposed to be a signal defined from 0..M-1 and 0 everywhere else. Also \$ y[n] = 0 \forall n < 0 \$

Now if we start \$ x\$ with a random input noise of M samples, then we'll get back a signal of fundamental frequency M from the above system.

To simulate a guitar chord of say following notes: D4,A4,D4,E4... One calculates the required frequencies as: \$ 440 \times 2^\frac{n}{12} \$ where n would be number of half tones between A4 and the required harmonic.

Now the sources I have referred to, (for instance, http://www.cs.princeton.edu/courses/archive/spr08/cos126/assignments/guitar.html) Calculate the M (the buffer/delay of system) as:

\$ M = \frac{F_s}{F_o} \$ where \$ F_s \$ is the sampling frequency, while \$ F_o \$ is the frequency of the signal I am interested in (say D4)

So for \$ F_s = 44100 Hz \$ and \$ F_o = 441 Hz \$ then \$ M = 100 \$

This calculation confused me. It seems like now I'll get a signal whose fundamental frequency is 100 Hz, when I needed a signal whose fundamental frequency was 441 Hz. So according to my understanding, shouldn't M be simply, \$ M = F_o\$ which will then give my requried signal.

Thanks :D

  • \$\begingroup\$ I'd say you were asking in the wrong place for this. \$\endgroup\$ – user1844 Oct 16 '14 at 19:43
  • \$\begingroup\$ Can you suggest me some better forum for the same? Thanks \$\endgroup\$ – Dhruv Kapur Oct 16 '14 at 20:11
  • \$\begingroup\$ I think this is okay, because it is fundamentally a DSP question. \$\endgroup\$ – Zuofu Oct 16 '14 at 20:37

You are confusing normalized frequency with real frequency (Hz). Wikipedia Normalized Frequency.

The equation for the fundamental frequency (\$f_0\$) given number of delay units in the "string" (\$M\$) should be \$f_0=\frac{F_s}{M}\$, as the website states. Note that the Karplus Strong algorithm (formulated for a plucked string) is no more than a feedback comb filter initialized to a noise burst, which has frequency response: \$H(\omega)=\frac{1}{1-\alpha e^{-j \omega M }}\$, where \$\alpha\$ is the scaling factor from your original difference equation.

Here is the magnitude plot with \$\alpha=.5\$ and \$M = 10\$:

Wolfram Alpha Plot

Note that the peaks are at \$\omega = 0, \pi/5, 2\pi/5...\$ This implies the fundamental frequency is at \$\omega_0 = \pi/5\$, which corresponds to the "real" frequency of \$44100/10 = 4410\$ Hz (assuming 44100 samples / sec). Remember that the fifth harmonic in this case is \$\omega_5 =5\pi/5 = \pi\$. This corresponds to what we expect, the fifth harmonic is 22050 Hz, the highest frequency we can represent with a sample rate of 44100 samples / sec.

Think about what happens in the frequency domain: over time, the initialized noise burse (which looks fairly uniform in frequency) gets filtered by the peaked harmonic response of the filter, which produces the harmonics you expect for a plucked string.

  • \$\begingroup\$ Thanks Zuofo. However I'm still confused when you say that 'the equation for the fundamental frequency give number of delay units in the "string" shoud be...' How do we know this? \$\endgroup\$ – Dhruv Kapur Oct 16 '14 at 21:13
  • \$\begingroup\$ I got that from the frequency response of the filter, which I derived by taking the Z-transform of the difference equation (and then substituting z=e^(jw)). In "normalized" frequency units, the fundamental is w0=2pi/M, which when we change to "real" frequency units, we get f0=Fs/M. Note that the way the Discrete-Fourier Transform is defined, Fs is mapped to a normalized frequency of 2*pi. \$\endgroup\$ – Zuofu Oct 16 '14 at 21:21
  • \$\begingroup\$ Hmm. I think your explanation helps, and I can see how harmonics of the fundamental will come by the comb filter. I'm still struggling getting the numbers around though. Can you point me to some resource that does a good job at explaining the concept of the normalized frequency? \$\endgroup\$ – Dhruv Kapur Oct 17 '14 at 14:33
  • \$\begingroup\$ See: mobiledevdesign.com/news/… \$\endgroup\$ – Zuofu Oct 17 '14 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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