mirror of
https://github.com/simon987/wavelib.git
synced 2025-04-20 02:26:45 +00:00
Commit : Denoise First Commit
This commit is contained in:
parent
0297e002d5
commit
9a0a271e4d
40
denoise/denoise.c
Normal file
40
denoise/denoise.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "../header/wavelib.h"
|
||||||
|
|
||||||
|
int compare_double(const void* a, const void* b)
|
||||||
|
{
|
||||||
|
double arg1 = *(const double*)a;
|
||||||
|
double arg2 = *(const double*)b;
|
||||||
|
|
||||||
|
if (arg1 < arg2) return -1;
|
||||||
|
if (arg1 > arg2) return 1;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double median(double *x, int N) {
|
||||||
|
double sigma;
|
||||||
|
|
||||||
|
qsort(x, N, sizeof(double), compare_double);
|
||||||
|
|
||||||
|
if ((N % 2) == 0) {
|
||||||
|
sigma = (x[N/2 - 1] + x[N/2] ) / 2.0;
|
||||||
|
} else {
|
||||||
|
sigma = x[N/2];
|
||||||
|
}
|
||||||
|
|
||||||
|
return sigma;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
double x[10] = { -2.4, 100.9,33 ,34,0,-6, -74.3, 2.9789, 271, 42 };
|
||||||
|
|
||||||
|
|
||||||
|
printf("Median %g \n",median(x,10));
|
||||||
|
for(i = 0; i < 10;++i) {
|
||||||
|
printf("%g ",x[i]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user