문제
C, C ++ 또는 C#로 작성된 .NET Windows Forms 프로젝트에 대한 디지털 로우 패스 필터 코드/라이브러리/클래스를 찾고 있습니다. 아마 극, 계수, 창, 그런 종류의 수를 설정해야 할 것입니다. 사용 가능한 GPL'D 코드를 사용할 수 없으며 다른 것이 무엇인지 모릅니다. 모든 제안에 감사드립니다.
해결책
다음은 최근 프로젝트를 위해 쓴 버터 워스 저지대 필터입니다.
그것은 나에게 주어진 상수로 마법의 숫자를 가지고 있습니다. 극, 계수 등으로 마법의 숫자를 만드는 방법을 알아낼 수 있다면 도움이 될 수 있습니다.
using System;
using System.Collections.Generic;
using System.Text;
namespace Filter
{
public class ButterworthLowPassFilter
{
//filter fc = 2hz, fs = 10hz
private const int LowPassOrder = 4;
private double[] inputValueModifier;
private double[] outputValueModifier;
private double[] inputValue;
private double[] outputValue;
private int valuePosition;
public ButterworthLowPassFilter()
{
inputValueModifier = new double[LowPassOrder];
inputValueModifier[0] = 0.098531160923927;
inputValueModifier[1] = 0.295593482771781;
inputValueModifier[2] = 0.295593482771781;
inputValueModifier[3] = 0.098531160923927;
outputValueModifier = new double[LowPassOrder];
outputValueModifier[0] = 1.0;
outputValueModifier[1] = -0.577240524806303;
outputValueModifier[2] = 0.421787048689562;
outputValueModifier[3] = -0.0562972364918427;
}
public double Filter(double inputValue)
{
if (this.inputValue == null && this.outputValue == null)
{
this.inputValue = new double[LowPassOrder];
this.outputValue = new double[LowPassOrder];
valuePosition = -1;
for (int i=0; i < LowPassOrder; i++)
{
this.inputValue[i] = inputValue;
this.outputValue[i] = inputValue;
}
return inputValue;
}
else if (this.inputValue != null && this.outputValue != null)
{
valuePosition = IncrementLowOrderPosition(valuePosition);
this.inputValue[valuePosition] = inputValue;
this.outputValue[valuePosition] = 0;
int j = valuePosition;
for (int i = 0; i < LowPassOrder; i++)
{
this.outputValue[valuePosition] += inputValueModifier[i] * this.inputValue[j] -
outputValueModifier[i] * this.outputValue[j];
j = DecrementLowOrderPosition(j);
}
return this.outputValue[valuePosition];
}
else
{
throw new Exception("Both inputValue and outputValue should either be null or not null. This should never be thrown.");
}
}
private int DecrementLowOrderPosition(int j)
{
if (--j < 0)
{
j += LowPassOrder;
}
return j;
}
private int IncrementLowOrderPosition(int position)
{
return ((position + 1) % LowPassOrder);
}
}
}
키이스
다른 팁
좋아, 나는 당신이 사용한 계수를 얻는 방법을 알았습니다. Windows 용 Octave를 다운로드하고 다음과 같이 버터 명령 (Matlab에서와 같이)을 실행했습니다.
b, a] = 버터 (3, .4, 'low')
이제 다른 FS 및 FC 매개 변수와 함께이 코드를 사용할 수 있습니다.
제휴하지 않습니다 StackOverflow