반응형
250x250
Notice
Recent Posts
Recent Comments
Link
«   2026/01   »
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 2 본문

카테고리 없음

치수 계산하기 - smooth filtering 2

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

윈도우 내 값들을 오름차순 정렬.

특정 순위(rank) 또는 백분위(percentile)에 해당하는 값을 반환.
- Percentile filter: 0~100 중 하나의 백분위값 (e.g., 20%)
- Rank filter: 윈도우 내 인덱스로 직접 지정 (e.g., 3번째 작은 값)

입력: [8, 3, 4, 2, 10], 커널 size = 5
정렬: [2, 3, 4, 8, 10]

  • 20% percentile → 1번째 값 → 3
  • 50% percentile → 중앙값 → 4
  • 80% percentile → 4번째 값 → 8

 

Median보다 더 다양한 filtering 특성이 가능
특정 방향성 있는 노이즈 억제 가능 (e.g. 아래쪽 스파이크 제거)

 

예제

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

// percentile 필터 함수
std::vector<double> percentileFilter(const std::vector<double>& signal, int windowSize, double percentile) {
    int half = windowSize / 2;
    int N = signal.size();
    std::vector<double> output(N);

    for (int i = 0; i < N; ++i) {
        std::vector<double> window;

        // 윈도우 추출
        for (int j = -half; j <= half; ++j) {
            int idx = i + j;
            if (idx < 0) idx = 0;
            if (idx >= N) idx = N - 1;
            window.push_back(signal[idx]);
        }

        // 정렬
        std::sort(window.begin(), window.end());

        // Percentile 인덱스 계산 (0~100 → 0~windowSize-1)
        int rank = std::floor((percentile / 100.0) * (windowSize - 1));
        output[i] = window[rank];
    }

    return output;
}

int main() {
    std::vector<double> input = {8, 3, 4, 2, 10, 7, 6};
    int windowSize = 5;
    double percentile = 20.0;  // 하위 20% 값

    std::vector<double> result = percentileFilter(input, windowSize, percentile);

    std::cout << "Filtered output: ";
    for (double val : result) {
        std::cout << val << " ";
    }
    std::cout << std::endl;
    return 0;
}

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