반응형
250x250
Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Today
Total
관리 메뉴

폴크(FOLC)

치수 계산하기 - smooth filtering 4 본문

카테고리 없음

치수 계산하기 - smooth filtering 4

folcjin 2025. 6. 28. 10:25
728x90
반응형

Band-pass Filter (대역통과 필터)

  • 특정 주파수 범위만 통과시키고, 그 이외의 저주파와 고주파는 차단합니다.
  • 예: 515Hz만 통과 → 05Hz, 15Hz~ 이상은 제거

용도

  • 특정 이벤트나 센서가 생성하는 주파수만 추출하고 싶을 때
  • 잡음이 저역 또는 고역에 집중되어 있을 때

 

Notch Filter (대역저지 필터)

  • 특정 좁은 주파수 대역만 제거하고 나머지는 통과시킵니다.
  • 예: 60Hz 전력 노이즈 제거 (Line frequency)

용도

  • 주기적이고 명확한 간섭 신호(기계 진동, 전력 간섭 등) 제거
  • 신호 구조를 최대한 유지하면서 잡음만 제거하고자 할 때

 

예제

#include <iostream>
#include <vector>
#include <cmath>

const double PI = 3.14159265358979323846;

// 간단한 IIR 2차 Band-pass 필터 클래스
class BandPassFilter {
public:
    BandPassFilter(double sampleRate, double lowCut, double highCut) {
        double nyq = 0.5 * sampleRate;
        double low = lowCut / nyq;
        double high = highCut / nyq;

        // Butterworth 2차 설계 (biquad 형태)
        double theta = PI * (high - low);
        double d = 1.0 / std::tan(theta);
        double beta = 0.5 * ((1.0 - d) / (1.0 + d));
        a0 = 0.5 * (1.0 - beta);
        a1 = 0.0;
        a2 = -a0;
        b1 = -2.0 * beta;
        b2 = (1.0 - beta);

        x1 = x2 = y1 = y2 = 0.0;
    }

    double process(double input) {
        double output = a0 * input + a1 * x1 + a2 * x2
                        - b1 * y1 - b2 * y2;

        x2 = x1;
        x1 = input;
        y2 = y1;
        y1 = output;

        return output;
    }

private:
    double a0, a1, a2, b1, b2;
    double x1, x2, y1, y2;
};

int main() {
    // 예제 신호 (노이즈 + 10Hz 사인파)
    double fs = 100.0;  // 샘플링 주파수
    double f_target = 10.0;
    double duration = 2.0;
    int N = static_cast<int>(fs * duration);

    std::vector<double> signal(N);
    for (int i = 0; i < N; ++i) {
        double t = i / fs;
        signal[i] = sin(2 * PI * f_target * t) + 0.5 * sin(2 * PI * 60.0 * t); // 60Hz 노이즈 포함
    }

    // 8~12Hz Band-pass 필터
    BandPassFilter bpf(fs, 8.0, 12.0);

    // 필터링
    std::vector<double> filtered(N);
    for (int i = 0; i < N; ++i) {
        filtered[i] = bpf.process(signal[i]);
    }

    // 결과 출력 (일부만)
    for (int i = 0; i < 20; ++i) {
        std::cout << "raw: " << signal[i] << "\tfiltered: " << filtered[i] << "\n";
    }

    return 0;
}

728x90
반응형
사업자 정보 표시
사업자 등록번호 : -- | TEL : --