1 /*****************************************************************************
2    Major portions of this software are copyrighted by the Medical College
3    of Wisconsin, 1994-2000, and are released under the Gnu General Public
4    License, Version 2.  See the file README.Copyright for details.
5 ******************************************************************************/
6 
7 /*
8   This file contains routines to initialize and implement the
9   sine wave (amplitude and phase parameters) signal model.
10 
11   File:     model_sinewave_ap.c
12   Author:   B. Douglas Ward
13   Date:     29 May 1997
14 */
15 
16 
17 /*---------------------------------------------------------------------------*/
18 
19 #include <math.h>
20 #include "NLfit_model.h"
21 
22 void signal_model
23 (
24   float * gs,                /* parameters for signal model */
25   int ts_length,             /* length of time series data */
26   float ** x_array,          /* independent variable matrix */
27   float * ts_array           /* estimated signal model time series */
28 );
29 
30 
31 /*---------------------------------------------------------------------------*/
32 /*
33   Routine to initialize the signal model by defining the number of parameters
34   in the signal model, the name of the signal model, and the default values
35   for the minimum and maximum parameter constraints.
36 */
37 
38 DEFINE_MODEL_PROTOTYPE
39 
initialize_model()40 MODEL_interface * initialize_model ()
41 {
42   MODEL_interface * mi = NULL;
43 
44 
45   /*----- allocate memory space for model interface -----*/
46   mi = (MODEL_interface *) RwcMalloc (sizeof(MODEL_interface));
47 
48 
49   /*----- define interface for the sine wave model -----*/
50 
51   /*----- name of this model -----*/
52   strcpy (mi->label, "SineWave_AP");
53 
54   /*----- this is a signal model -----*/
55   mi->model_type = MODEL_SIGNAL_TYPE;
56 
57   /*----- number of parameters in the model -----*/
58   mi->params = 2;
59 
60   /*----- parameter labels -----*/
61   strcpy (mi->plabel[0], "amplitude");
62   strcpy (mi->plabel[1], "phase");
63 
64   /*----- minimum and maximum parameter constraints -----*/
65   mi->min_constr[0] =   -100.0;    mi->max_constr[0] =   100.0;
66   mi->min_constr[1] =    -90.0;    mi->max_constr[1] =     0.00;
67 
68   /*----- function which implements the model -----*/
69   mi->call_func = &signal_model;
70 
71 
72   /*----- return pointer to the model interface -----*/
73   return (mi);
74 }
75 
76 
77 /*---------------------------------------------------------------------------*/
78 /*
79   Routine to calculate the time series which results from using the
80   sine wave model with specified amplitude and phase
81   model parameters.
82 
83   Definition of model parameters:
84 
85 	gs[0] = amplitude of sinusoid
86 	gs[1] = phase angle of sinusoid (degrees)
87 */
88 
signal_model(float * gs,int ts_length,float ** x_array,float * ts_array)89 void signal_model
90 (
91   float * gs,                /* parameters for signal model */
92   int ts_length,             /* length of time series data */
93   float ** x_array,          /* independent variable matrix */
94   float * ts_array           /* estimated signal model time series */
95 )
96 
97 {
98   const float FREQ = 0.125f;         /* frequency of the sine wave */
99   int it;                           /* time index */
100   float t;                          /* time */
101   float fval;                       /* time series value at time t */
102 
103 #ifdef SOLARIS
104 # define sinf sin
105 #endif
106 
107 
108   /*----- calculate time series corresponding to the given parameters -----*/
109   for (it = 0;  it < ts_length;  it++)
110     {
111       t = x_array[it][1];
112       fval = gs[0] * sinf( 2.0f*PI*FREQ*t + (PI/180.0f)*gs[1] );
113       ts_array[it] = fval;
114     }
115 
116 }
117 
118 
119 
120 
121