2011-09-15 124 views
4

最近我參與處理來自不同設備的傳感器的數據。這些傳感器包括加速度計的,陀螺儀,磁強計等,這一切開始時我想隔離重力和偶然發現了這個鏈接(在Android android_frameworks_base /服務/ 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)時,研究信號處理。數學不應該是一個大問題。

我在問這個問題,因爲我看到有很多有關過濾器的問題。

非常感謝,

尤利安

+1

您可以在這裏得到很好的答案,而且在http://dsp.stackexchange.com/ –

+0

@INS:谷歌於codesearch一直關機。你可以給另一個鏈接嗎? – Ashwin

+0

@Ashwin完成。我已將源代碼放在問題 – INS

回答