Strong with low pass filter
I have implemented a basic Karplus-Strong algorithm.
Ringbuffer, filling with white noise, output a sample from the front and append the average of first two elements to the end and delete the first element. Repeat last to steps.
For better results and control over them I tried to implement a extended version of the algorithm.
Therefore instead of an averaging filter I need a frequency filter like a low pass filter.
My averaging filter has two inputs and one output: avg(a,b) = (a+b)/2
The sample code on the wikipedia page gives as many outputs as inputs.
http://en.wikipedia.org/wiki/Low-pass_filter
I have found other (mathematic) versions like:
http://cnx.org/content/m15490/latest/
H(z) = (1+(1/z))/2
I guess z is a complex number.
Both version have two inputs but also two outputs.
How do I get one meaningful value out of this?
Or do I have to rewrite bigger parts of the algorithm?
If thats the case where can I find a good explanation of it?
Your filter is a specialization of the Finite Impulse Response filter. You're using the moving average method to select the coefficients, using N = 1. It already is a low-pass filter.
Calculating the coefficient and order for the filter to tune it to a specific frequency response involves tricky math. Best thing to do is to use a software package to calculate the coefficients if moving average doesn't fit your bill. Matlab is the usual choice, GNU Octave is an open source option.
Filters can expressed in a number of ways:
y[i] = h[0]*x[i] + h[1]*x[i-1] + h[2]*x[i-2] + ...
The second of these is actually a convolution of the h and x arrays. This is also the easiest to understand.
The previous answer explained where to start on constructing a filter. Assuming you have your filter coefficients, the h
's, then it is simply summing over the non-negative ones.
I believe I see what you are asking. Though you do not need more than one output. From the Wikipedia page the Karplus-Strong string synthesis algorithm needs a buffer of length L. If we have M filter coefficients ( h
) that gives an output of the form,
y[i] = x[i] + h[0]*y[iL] + h[1]*y[i-(L+1)] + h[2]*y[i-(L+2)] + ...
The Karplus-Strong synthesis from here uses a ring buffer to hold the last L outputs, y[i-1],...,y[iL]
. This is initialised to be the x[i]
noise values for i<=L
; however, for i>L
x[i]=0
. The algorithm will be space efficient as you only store L values. The signal x[i]
for i>L
is just added to the ring buffer.
Finally, as a note of warning, if you are not careful with both the number of coefficients h
and the values the outputs y
may not have the desired behaviour.
上一篇: 切比雪夫LPF引入噪音
下一篇: 低通滤波器强大