有关过滤器的一般文档

发布于 2024-12-04 15:25:00 字数 2670 浏览 1 评论 0原文

最近我参与处理来自不同设备的传感器的数据。这些传感器由加速度计、陀螺仪、磁力计等组成。这一切都始于我想要隔离重力并偶然发现了这个链接(代码来自 android android_frameworks_base / services /sensorservice / SecondOrderLowPassFilter.cpp ):

/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdint.h>
#include <sys/types.h>
#include <math.h>

#include <cutils/log.h>

#include "SecondOrderLowPassFilter.h"

// ---------------------------------------------------------------------------

namespace android {
// ---------------------------------------------------------------------------

SecondOrderLowPassFilter::SecondOrderLowPassFilter(float Q, float fc)
    : iQ(1.0f / Q), fc(fc)
{
}

void SecondOrderLowPassFilter::setSamplingPeriod(float dT)
{
    K = tanf(float(M_PI) * fc * dT);
    iD = 1.0f / (K*K + K*iQ + 1);
    a0 = K*K*iD;
    a1 = 2.0f * a0;
    b1 = 2.0f*(K*K - 1)*iD;
    b2 = (K*K - K*iQ + 1)*iD;
}

// ---------------------------------------------------------------------------

BiquadFilter::BiquadFilter(const SecondOrderLowPassFilter& s)
    : s(s)
{
}

float BiquadFilter::init(float x)
{
    x1 = x2 = x;
    y1 = y2 = x;
    return x;
}

float BiquadFilter::operator()(float x)
{
    float y = (x + x2)*s.a0 + x1*s.a1 - y1*s.b1 - y2*s.b2;
    x2 = x1;
    y2 = y1;
    x1 = x;
    y1 = y;
    return y;
}

// ---------------------------------------------------------------------------

CascadedBiquadFilter::CascadedBiquadFilter(const SecondOrderLowPassFilter& s)
    : mA(s), mB(s)
{
}

float CascadedBiquadFilter::init(float x)
{
    mA.init(x);
    mB.init(x);
    return x;
}

float CascadedBiquadFilter::operator()(float x)
{
    return mB(mA(x));
}

// ---------------------------------------------------------------------------
}; // namespace android

虽然该代码确实工作得很好,但我感觉我需要了解一些有关过滤器原理的基础知识。例如,也许我需要更改该过滤器中的某些内容。

我开始阅读维基百科(卡尔曼,低通,...),但我仍然觉得在开始修改别人的代码之前我需要更好地感受/接触这个理论。

所以我问你们,SO 用户,我可以阅读什么才能对过滤器有一个更全面的了解?任何链接、资源、文档都很好。

另外:我有工程师学位,但在研究信号处理时除了一些傅里叶变换(DFT)之外并没有完全研究滤波器。数学应该不是一个大问题。

我问这个问题是因为我看到有很多与过滤器相关的问题。

非常感谢,

尤利安

Lately I am involved in processing data from sensors from different devices. These sensors consist of accelerometers, gyroscopes, magnetometers etc. It all started when I wanted to isolate the gravitational force and stumbled upon this link (code from android android_frameworks_base / services / sensorservice / SecondOrderLowPassFilter.cpp ):

/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdint.h>
#include <sys/types.h>
#include <math.h>

#include <cutils/log.h>

#include "SecondOrderLowPassFilter.h"

// ---------------------------------------------------------------------------

namespace android {
// ---------------------------------------------------------------------------

SecondOrderLowPassFilter::SecondOrderLowPassFilter(float Q, float fc)
    : iQ(1.0f / Q), fc(fc)
{
}

void SecondOrderLowPassFilter::setSamplingPeriod(float dT)
{
    K = tanf(float(M_PI) * fc * dT);
    iD = 1.0f / (K*K + K*iQ + 1);
    a0 = K*K*iD;
    a1 = 2.0f * a0;
    b1 = 2.0f*(K*K - 1)*iD;
    b2 = (K*K - K*iQ + 1)*iD;
}

// ---------------------------------------------------------------------------

BiquadFilter::BiquadFilter(const SecondOrderLowPassFilter& s)
    : s(s)
{
}

float BiquadFilter::init(float x)
{
    x1 = x2 = x;
    y1 = y2 = x;
    return x;
}

float BiquadFilter::operator()(float x)
{
    float y = (x + x2)*s.a0 + x1*s.a1 - y1*s.b1 - y2*s.b2;
    x2 = x1;
    y2 = y1;
    x1 = x;
    y1 = y;
    return y;
}

// ---------------------------------------------------------------------------

CascadedBiquadFilter::CascadedBiquadFilter(const SecondOrderLowPassFilter& s)
    : mA(s), mB(s)
{
}

float CascadedBiquadFilter::init(float x)
{
    mA.init(x);
    mB.init(x);
    return x;
}

float CascadedBiquadFilter::operator()(float x)
{
    return mB(mA(x));
}

// ---------------------------------------------------------------------------
}; // namespace android

While that code does work quite well I feel like I need to understand some basics about the filter philosophy in general. For example maybe I need to change something in that filter.

I started reading on Wikipedia (Kalman, Low-Pass, ...) but I still feel like I need to feel/touch this theory better before starting to modify someone else's code.

So I'm asking you, SO users, what can I read in order to have a more than general idea about filters? Any link, resource, documentation will be good.

Also: I have an engineer degree but didn't quite study filters except for some Fourier transformations (DFT) when studying signal processing. Math should not be a big issue.

I'm asking this question because I saw there are MANY questions related to filters.

Thanks a lot,

Iulian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风筝在阴天搁浅。 2024-12-11 15:25:00

我在以下章节中的 dspguide 中找到了一个不太复杂的介绍


更多有趣的答案此处位于 dsp stackexchange


PS:我将其设为 wiki,以便人们可以添加他们的资源(欢迎贡献)。


I found a less complicated introduction at dspguide in the following chapters:


More interesting answers here on dsp stackexchange.


PS: I made this a wiki so people can add their resources (contributions are welcome).


~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文