use*_*319 19 c# matlab signal-processing
我需要用c#编写的低通和高通滤波器.我有这个过滤过程的双数组.我想如果我尝试将matlab Butterworth和Chebyshev算法转换为c#,那就更容易了.但我无法找到在互联网上butter.m和切比雪夫算法的代码,我不想MATLAB和信号处理工具设置成我的电脑.你能提供这些代码吗?谢谢..
Wou*_*ter 16
http://www.musicdsp.org/archive.php?classid=3#38
我在sEMG分析器软件中按照以下半模式实现了过滤器,效果很好.
public class FilterButterworth
{
/// <summary>
/// rez amount, from sqrt(2) to ~ 0.1
/// </summary>
private readonly float resonance;
private readonly float frequency;
private readonly int sampleRate;
private readonly PassType passType;
private readonly float c, a1, a2, a3, b1, b2;
/// <summary>
/// Array of input values, latest are in front
/// </summary>
private float[] inputHistory = new float[2];
/// <summary>
/// Array of output values, latest are in front
/// </summary>
private float[] outputHistory = new float[3];
public FilterButterworth(float frequency, int sampleRate, PassType passType, float resonance)
{
this.resonance = resonance;
this.frequency = frequency;
this.sampleRate = sampleRate;
this.passType = passType;
switch (passType)
{
case PassType.Lowpass:
c = 1.0f / (float)Math.Tan(Math.PI * frequency / sampleRate);
a1 = 1.0f / (1.0f + resonance * c + c * c);
a2 = 2f * a1;
a3 = a1;
b1 = 2.0f * (1.0f - c * c) * a1;
b2 = (1.0f - resonance * c + c * c) * a1;
break;
case PassType.Highpass:
c = (float)Math.Tan(Math.PI * frequency / sampleRate);
a1 = 1.0f / (1.0f + resonance * c + c * c);
a2 = -2f * a1;
a3 = a1;
b1 = 2.0f * (c * c - 1.0f) * a1;
b2 = (1.0f - resonance * c + c * c) * a1;
break;
}
}
public enum PassType
{
Highpass,
Lowpass,
}
public void Update(float newInput)
{
float newOutput = a1 * newInput + a2 * this.inputHistory[0] + a3 * this.inputHistory[1] - b1 * this.outputHistory[0] - b2 * this.outputHistory[1];
this.inputHistory[1] = this.inputHistory[0];
this.inputHistory[0] = newInput;
this.outputHistory[2] = this.outputHistory[1];
this.outputHistory[1] = this.outputHistory[0];
this.outputHistory[0] = newOutput;
}
public float Value
{
get { return this.outputHistory[0]; }
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,此过滤器是为音频DSP目的而创建的.要创建干净的输出,您需要将共振设置为sqrt(2).
Rei*_*ica 11
我发现这个看起来很有前景的在线工具:交互式数字滤波器设计:Butterworth/Bessel/Chebyshev滤波器
您只需输入您的要求:
单击"提交",它将计算以下信息:
您可以直接从递归关系中实现C#中的过滤器.
如果您只需要一些常量过滤器,那么您就完成了.但是,如果您需要能够在运行时调整过滤器参数,则需要执行更多操作.幸运的是,教授提供了他的工具的源代码,应该可以转换为C#.
| 归档时间: |
|
| 查看次数: |
48944 次 |
| 最近记录: |