TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcmodext
noise.c
Go to the documentation of this file.
1
5
/*****************************************************************************/
6
7
/*****************************************************************************/
8
#include "
libtpcmodext.h
"
9
/*****************************************************************************/
10
11
/*****************************************************************************/
21
int
noiseSD4Simulation
(
23
double
y,
26
double
t1,
29
double
dt,
32
double
hl,
34
double
a,
36
double
*sd,
39
char
*status,
41
int
verbose
42
) {
43
double
d, lambda, f;
44
45
if
(verbose>0) printf(
"noiseSD4Simulation(%g, %g, %g, %g, %g, *sd, ...)\n"
,
46
y, t1, dt, hl, a);
47
if
(status!=NULL) strcpy(status,
"invalid data"
);
48
if
(sd==NULL)
return
1;
49
if
(t1<0.0)
return
2;
50
if
(dt<=0.0)
return
3;
51
52
/* Decay factor (<=1) */
53
if
(hl<=0.0) {
54
d=1.0; lambda=0.0;
55
}
else
{
56
if
(status!=NULL) strcpy(status,
"invalid half-life"
);
57
lambda=
hl2lambda
(hl);
if
(lambda<0.0)
return
4;
58
d=
hlLambda2factor
(-lambda, t1, dt);
if
(d<0.0)
return
5;
59
}
60
/* SD */
61
f=y*d*dt;
62
if
(f<=0.0) *sd=0.0;
63
else
*sd=y*sqrt(a/f);
64
65
if
(status!=NULL) strcpy(status,
"ok"
);
66
return
(0);
67
}
68
/*****************************************************************************/
69
70
/*****************************************************************************/
79
int
noiseSD4SimulationFromDFT
(
85
DFT
*dft,
89
int
index,
91
double
pc,
93
double
*sd,
96
char
*status,
98
int
verbose
99
) {
100
int
ret, fi;
101
double
hl=0.0, t1, deltat;
102
double
*y;
103
DFT
mean
;
104
105
if
(verbose>0) printf(
"noiseSD4SimulationFromDFT(DFT, %d, %g, sd[], ...)\n"
,
106
index, pc);
107
if
(status!=NULL) strcpy(status,
"invalid data"
);
108
if
(dft==NULL || sd==NULL)
return
1;
109
if
(dft->
voiNr
<1 || dft->
frameNr
<1)
return
2;
110
if
(dft->
voiNr
>1 && index>=dft->
voiNr
)
return
3;
111
112
/* Check that valid frame times are available */
113
if
(status!=NULL) strcpy(status,
"invalid frame times"
);
114
for
(fi=0; fi<dft->
frameNr
; fi++)
115
if
(dft->
x2
[fi]<=dft->
x1
[fi] || dft->
x1
[fi]<0.0)
return
4;
116
if
(status!=NULL) strcpy(status,
"missing time unit"
);
117
if
(dft->
timeunit
!=TUNIT_SEC && dft->
timeunit
!=TUNIT_MIN)
return
5;
118
119
/* Check if isotope is available, if it is needed */
120
if
(dft->
decayCorrected
==
DFT_DECAY_CORRECTED
||
121
dft->
decayCorrected
==
DFT_DECAY_UNKNOWN
)
122
{
123
hl=
hlFromIsotope
(dft->
isotope
);
124
if
(status!=NULL) strcpy(status,
"missing isotope halflife"
);
125
if
(hl<=0.0)
return
6;
126
}
127
if
(verbose>1) printf(
"halflife := %g\n"
, hl);
128
129
/* Set pointer to activity concentration data */
130
dftInit
(&
mean
);
131
if
(dft->
voiNr
==1) {
132
y=dft->
voi
[0].
y
;
133
}
else
if
(index>=0) {
134
y=dft->
voi
[index].
y
;
135
}
else
{
136
/* Compute TAC mean */
137
ret=
dftMeanTAC
(dft, &
mean
);
if
(ret!=0) {
138
if
(status!=NULL) strcpy(status,
"cannot calculate mean TAC"
);
139
return
8;
140
}
141
/* and use that */
142
y=
mean
.voi[0].y;
143
}
144
145
/* Compute SD for each sample time */
146
if
(pc<=0.0) pc=1.0;
147
for
(fi=0; fi<dft->
frameNr
; fi++) {
148
t1=dft->
x1
[fi]; deltat=dft->
x2
[fi]-dft->
x1
[fi];
149
if
(dft->
timeunit
==TUNIT_SEC) {t1/=60.0; deltat/=60.0;}
150
ret=
noiseSD4Simulation
(y[fi], t1, deltat, hl, pc, sd+fi, status, verbose);
151
if
(ret!=0)
break
;
152
}
153
dftEmpty
(&
mean
);
154
if
(ret!=0) {
155
if
(status!=NULL)
156
sprintf(status,
"cannot calculate SD for noise simulation (%d)"
, ret);
157
return
(100+ret);
158
}
159
160
if
(status!=NULL) strcpy(status,
"ok"
);
161
return
0;
162
}
163
/*****************************************************************************/
164
165
/*****************************************************************************/
dftInit
void dftInit(DFT *data)
Definition
dft.c:38
dftMeanTAC
int dftMeanTAC(DFT *dft, DFT *mean)
Definition
dft.c:1580
dftEmpty
void dftEmpty(DFT *data)
Definition
dft.c:20
hl2lambda
double hl2lambda(double halflife)
Definition
halflife.c:84
hlLambda2factor
double hlLambda2factor(double lambda, double frametime, double framedur)
Definition
halflife.c:98
hlFromIsotope
double hlFromIsotope(char *isocode)
Definition
halflife.c:55
DFT_DECAY_UNKNOWN
#define DFT_DECAY_UNKNOWN
Definition
libtpccurveio.h:442
DFT_DECAY_CORRECTED
#define DFT_DECAY_CORRECTED
Definition
libtpccurveio.h:444
mean
int mean(double *x, double *y, int nr, double *xmean, double *xsd, double *ymean, double *ysd)
Definition
pearson.c:341
libtpcmodext.h
Header file for libtpcmodext.
noiseSD4Simulation
int noiseSD4Simulation(double y, double t1, double dt, double hl, double a, double *sd, char *status, int verbose)
Definition
noise.c:21
noiseSD4SimulationFromDFT
int noiseSD4SimulationFromDFT(DFT *dft, int index, double pc, double *sd, char *status, int verbose)
Definition
noise.c:79
DFT
Definition
libtpccurveio.h:73
DFT::decayCorrected
char decayCorrected
Definition
libtpccurveio.h:92
DFT::voi
Voi * voi
Definition
libtpccurveio.h:108
DFT::timeunit
int timeunit
Definition
libtpccurveio.h:85
DFT::x1
double * x1
Definition
libtpccurveio.h:104
DFT::voiNr
int voiNr
Definition
libtpccurveio.h:78
DFT::x2
double * x2
Definition
libtpccurveio.h:106
DFT::frameNr
int frameNr
Definition
libtpccurveio.h:76
DFT::isotope
char isotope[8]
Definition
libtpccurveio.h:90
Voi::y
double * y
Definition
libtpccurveio.h:59
Generated on
for TPCCLIB by
1.17.0