TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpccm
convolut.c
Go to the documentation of this file.
1
4
/*****************************************************************************/
5
#include "tpcclibConfig.h"
6
/*****************************************************************************/
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include <math.h>
10
#include <time.h>
11
#include <string.h>
12
/*****************************************************************************/
13
#include "
tpccm.h
"
14
/*****************************************************************************/
15
16
/*****************************************************************************/
27
int
convolve1D
(
29
double
*data,
31
const
int
n,
33
double
*kernel,
35
const
int
m,
37
double
*out
38
) {
39
if
(n<1 || m<1 || data==NULL || kernel==NULL || out==NULL || out==data)
return
(1);
40
41
for
(
int
di=0; di<n; di++) out[di]=0.0;
42
43
for
(
int
di=m-1; di<n; di++) {
44
int
dj=di;
45
for
(
int
k=0; k<m; k++)
46
out[di] += data[dj--] * kernel[k];
47
}
48
49
for
(
int
di=0; di<n && di<m-1; di++) {
50
int
k=0;
51
for
(
int
dj=di; dj>=0; dj--)
52
out[di] += data[dj] * kernel[k++];
53
}
54
55
return
(0);
56
}
57
/*****************************************************************************/
58
59
/*****************************************************************************/
66
int
simIsSteadyInterval
(
68
double
*x,
70
const
int
n,
73
double
*f
74
) {
75
if
(f!=NULL) *f=nan(
""
);
76
if
(x==NULL || n<2)
return
(0);
77
//if(!(fabs(x[0])>1.0E-12)) return(0); // on purpose, to catch NaN
78
79
double
d, freq=nan(
""
);
80
int
isdif=0;
81
for
(
int
i=1; i<n; i++) {
82
d=x[i]-x[i-1];
83
if
(!(d>1.0E-12))
return
(0);
// interval must be > 0
84
if
(isnan(freq)) {freq=d;
continue
;}
// first interval
85
if
(fabs(freq-d)<1.0E-12)
continue
;
// same interval as before
86
isdif++;
// different
87
if
(d<freq) freq=d;
// save smaller interval
88
}
89
if
(f!=NULL) *f=freq;
90
if
(isdif>0)
return
(0);
// variable intervals
91
/* Check that first sample time is at the midpoint of interval starting from 0 */
92
d=0.5*freq;
//printf("d=%g x[0]=%g\n", d, x[0]);
93
if
(fabs(x[0]-d)>1.0E-06)
return
(0);
94
return
(1);
95
}
96
/*****************************************************************************/
97
98
/*****************************************************************************/
convolve1D
int convolve1D(double *data, const int n, double *kernel, const int m, double *out)
Calculates the convolution sum of a discrete real data set data[0..n-1] and a discretized response fu...
Definition
convolut.c:27
simIsSteadyInterval
int simIsSteadyInterval(double *x, const int n, double *f)
Definition
convolut.c:66
tpccm.h
Header file for libtpccm.
Generated on
for TPCCLIB by
1.17.0