使用低通滤波器扩展 Karplus-Strong
我已经实现了基本的 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 是一个复数。
两个版本都有两个输入,但也有两个输出。
我如何从中获得有意义的价值?
或者我是否必须重写算法的更大部分?
如果是这样的话我在哪里可以找到一个很好的解释?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的滤波器是有限脉冲响应滤波器的特化。您使用移动平均法来选择系数,其中 N = 1。它已经是一个低通滤波器。
计算滤波器的系数和阶数以将其调整到特定的频率响应涉及棘手的数学。如果移动平均线不符合您的要求,最好的办法是使用软件包来计算系数。 Matlab 是通常的选择,GNU Octave 是一个开源选项。
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.
过滤器可以用多种方式表示:
y[i] = h[0]*x [i] + h[1]*x[i-1] + h[2]*x[i-2] + ...
其中第二个实际上是 h 和 x 数组的卷积。这也是最容易理解的。
前面的答案解释了从哪里开始构建过滤器。假设您有滤波器系数,即
h
,那么它只是对非负系数进行求和。我相信我明白你在问什么。尽管您不需要多个输出。从 Wikipedia 页面来看,Karplus-Strong 字符串合成算法需要长度为 L 的缓冲区。如果我们有 M 个滤波器系数 (
h
),它给出以下形式的输出:y[i] = x[i] + h[0]*y[iL] + h[1]*y[i-(L+1)] + h[2]*y[i-(L+2)] + ...
来自 这里的 Karplus-Strong 综合< /a> 使用环形缓冲区来保存最后 L 个输出,
y[i-1],...,y[iL]
。这被初始化为i<=L
的x[i]
噪声值;然而,对于i>L
x[i]=0
。该算法将节省空间,因为您只存储 L 值。i>L
的信号x[i]
只是添加到环形缓冲区中。最后,作为警告,如果您不小心处理系数
h
的数量和输出y
的值,则可能不会具有所需的行为。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[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 thex[i]
noise values fori<=L
; however, fori>L
x[i]=0
. The algorithm will be space efficient as you only store L values. The signalx[i]
fori>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 outputsy
may not have the desired behaviour.