0

我已经实现了一个基本的 Karplus-Strong 算法。
Ringbuffer,填充白噪声,从前面输出一个样本,并将前两个元素的平均值附加到末尾并删除第一个元素。重复最后的步骤。

为了获得更好的结果和对它们的控制,我尝试实现该算法的扩展版本。
因此,我需要一个像低通滤波器这样的频率滤波器,而不是一个平均滤波器。
我的平均滤波器有两个输入和一个输出:avg(a,b) = (a+b)/2

维基百科页面上的示例代码提供与输入一样多的输出。
http://en.wikipedia.org/wiki/Low-pass_filter

我找到了其他(数学)版本,例如:
http
://cnx.org/content/m15490/latest/ H(z) = (1+(1/z))/2
我猜 z 是一个复数。

两个版本都有两个输入,但也有两个输出。
我如何从中获得一个有意义的价值?
还是我必须重写算法的更大部分?
如果是这样,我在哪里可以找到一个很好的解释?

4

2 回答 2

2

您的过滤器是有限脉冲响应过滤器的特化。您正在使用移动平均法来选择系数,使用 N = 1。它已经是一个低通滤波器。

计算滤波器的系数和阶数以将其调整到特定的频率响应涉及棘手的数学问题。如果移动平均线不符合您的要求,最好的办法是使用软件包来计算系数。Matlab 是通常的选择,GNU Octave 是一个开源选项。

于 2009-12-12T21:06:19.693 回答
0

过滤器可以用多种方式表示:

  1. 在复杂的平原上,您的示例 H(z) = (1+(1/z))/2
  2. 作为过滤器,y[i] = h[0]*x[i] + h[1]*x[i-1] + h[2]*x[i-2] + ...
  3. 在频域中,Y[f] = H[f] * X[f]

其中第二个实际上是 h 和 x 数组的卷积。这也是最容易理解的。

上一个答案解释了从哪里开始构建过滤器。假设你有你的滤波器系数,h那么它只是对非负数求和。

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[i-L] + 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[i-L]. 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.

于 2009-12-12T23:31:49.260 回答