detrend signal c source code

신호의 경향성을 없애는 detrend 함수의 소스 코드를 수록하였다.


신호처리/분석에서 FFT를 통해 신호의 주파수 성분을 분석할 때 먼저 detrend를 통해 경향성을 제거하는 것이 좋다. 신호의 경향성때문에 발생하는 저주파 성분이 신호 분석에 혼란을 주기도 한다.
아래 그림은 detrend 함수를 통해 신호의 경향성을 제거한 예이다.


detrend 함수의 소스 코드는 아래와 같다.

double detrend(double *pin, double *pout, int n, int is_nomal_out)
{
double x = 0;
double y = 0;
double a = 0;
double b = 0;
double sy = 0.0;
double sxy = 0.0;
double sxx = 0.0;
int i = 0;

i = 0;
x = (-n / 2.0 + 0.5);
while (i<n)
{
y = pin[i];
sy += y;
sxy += x * y;
sxx += x * x;

i++;
x += 1.0;
}

a = sxy / sxx;
b = sy / n;

i = 0;
x = (-n / 2.0 + 0.5);

if (is_nomal_out)
{
while (i<n)
{
pout[i] = pin[i] - (b + a*x);
i++;
x += 1.0;
}
}
else
{
while (i<n)
{
pout[i] = pin[i] - (a*i);
i++;
x += 1.0;
}
}

return b;
}

댓글

이 블로그의 인기 게시물

간단한 cfar 알고리즘에 대해

리눅스 파일 검색 명령어

바로 프로젝트 적용 가능한 FIR Filter (low/high/band pass filter )를 c나 python으로 만들기

간단한 칼만 필터(Kalman Filter) 소스 코드와 사용 예제

터미널 컬러 로그 메시지 출력 팁 ANSI Color