summaryrefslogtreecommitdiff
path: root/src/signalProcessing/hilbert/testHilbert.c
blob: 98c4f803423c765b9fcd75f0b5acb53d19ece302 (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 *  Copyright (C) 2008 - INRIA - Arnaud TORSET
 *
 *  This file must be used under the terms of the CeCILL.
 *  This source file is licensed as described in the file COPYING, which
 *  you should have received as part of this distribution.  The terms
 *  are also available at
 *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 *
 */



#include <stdio.h>
#include <assert.h>
#include <math.h>
#include "hilbert.h"


static void dhilbertaTest(void){
	int i;
	double in[16]={1, 2, 3, 4, 5,6,7,8,9, 10,11,12,13,14,15,16};
	/*double resR[4]={1,2,3,4};
	double resI[4]={1,-1,-1,1};*/	
	doubleComplex *out;	
	
	out = malloc((uint)9*sizeof(doubleComplex));
	dhilberta(in, 1, 9, out);
	
	for (i=0;i<9;i++){
		printf("%f+%f *i\n",zreals (out[i]),zimags(out[i]));
		/*assert( (fabs(zreals(out[i])-resR[i]) / fabs(zreals(out[i])) )<1e-16);
		assert( (fabs(zimags(out[i])-resI[i]) / fabs(zimags(out[i])) )<1e-16);*/
	}

}

static void shilbertaTest(void){
	int i;
	float in[4]={1.0f, 2.0f, 3.0f, 4.0f};
	/*float resR[4]={1.0f,2.0f,3.0f,4.0f};
	float resI[4]={1.0f,-1.0f,-1.0f,1.0f};	*/
	floatComplex out[4];	
	
	
	shilberta(in, 1, 4, out);
	
	for (i=0;i<4;i++){
		printf("%f+%f *i\n",creals (out[i]),cimags(out[i]));
		/*assert( (fabs(creals(out[i])-resR[i]) / fabs(creals(out[i])) )<1e-6);
		assert( (fabs(cimags(out[i])-resI[i]) / fabs(cimags(out[i])) )<1e-6);*/
	}
}

static int hilbertTest(void){
	dhilbertaTest();
	shilbertaTest();
	return 0;
}


int main (void){
	assert(hilbertTest()==0);
	return 0;
}