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;
}

댓글

이 블로그의 인기 게시물

windows에서 간단하게 크롬캐스트(Chromecast)를 통해 윈도우 화면 미러링 방법

간단한 cfar 알고리즘에 대해

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

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

python winsound를 이용한 윈도우 환경에서 소리 재생 예제