Doxygen Source Code Documentation
model_trnglwave_ap.c
Go to the documentation of this file.00001 /***************************************************************************** 00002 Major portions of this software are copyrighted by the Medical College 00003 of Wisconsin, 1994-2000, and are released under the Gnu General Public 00004 License, Version 2. See the file README.Copyright for details. 00005 ******************************************************************************/ 00006 00007 /* 00008 This file contains routines to initialize and implement the 00009 triangular wave (amplitude and phase parameters) signal model. 00010 00011 File: model_trnglrwave_ap.c 00012 Author: B. Douglas Ward 00013 Date: 29 May 1997 00014 */ 00015 00016 00017 /*---------------------------------------------------------------------------*/ 00018 00019 #include <math.h> 00020 #include "NLfit_model.h" 00021 00022 void signal_model 00023 ( 00024 float * gs, /* parameters for signal model */ 00025 int ts_length, /* length of time series data */ 00026 float ** x_array, /* independent variable matrix */ 00027 float * ts_array /* estimated signal model time series */ 00028 ); 00029 00030 00031 /*---------------------------------------------------------------------------*/ 00032 /* 00033 Routine to initialize the signal model by defining the number of parameters 00034 in the signal model, the name of the signal model, and the default values 00035 for the minimum and maximum parameter constraints. 00036 */ 00037 00038 DEFINE_MODEL_PROTOTYPE 00039 00040 MODEL_interface * initialize_model () 00041 { 00042 MODEL_interface * mi = NULL; 00043 00044 00045 /*----- allocate memory space for model interface -----*/ 00046 mi = (MODEL_interface *) XtMalloc (sizeof(MODEL_interface)); 00047 00048 00049 /*----- define interface for the triangular wave model -----*/ 00050 00051 /*----- name of this model -----*/ 00052 strcpy (mi->label, "TrnglrWave_AP"); 00053 00054 /*----- this is a signal model -----*/ 00055 mi->model_type = MODEL_SIGNAL_TYPE; 00056 00057 /*----- number of parameters in the model -----*/ 00058 mi->params = 2; 00059 00060 /*----- parameter labels -----*/ 00061 strcpy (mi->plabel[0], "amplitude"); 00062 strcpy (mi->plabel[1], "phase"); 00063 00064 /*----- minimum and maximum parameter constraints -----*/ 00065 mi->min_constr[0] = -100.0; mi->max_constr[0] = 100.0; 00066 mi->min_constr[1] = -90.0; mi->max_constr[1] = 0.00; 00067 00068 /*----- function which implements the model -----*/ 00069 mi->call_func = &signal_model; 00070 00071 00072 /*----- return pointer to the model interface -----*/ 00073 return (mi); 00074 } 00075 00076 00077 /*---------------------------------------------------------------------------*/ 00078 /* 00079 Routine to calculate the time series which results from using the 00080 triangular wave model with specified amplitude and phase parameters. 00081 00082 Definition of model parameters: 00083 00084 gs[0] = amplitude of triangular wave 00085 gs[1] = phase angle of triangular wave (degrees) 00086 */ 00087 00088 void signal_model 00089 ( 00090 float * gs, /* parameters for signal model */ 00091 int ts_length, /* length of time series data */ 00092 float ** x_array, /* independent variable matrix */ 00093 float * ts_array /* estimated signal model time series */ 00094 ) 00095 00096 { 00097 const float FREQ = 0.125; /* frequency of the triangular wave */ 00098 int it; /* time index */ 00099 float t; /* time */ 00100 float fval; /* time series value at time t */ 00101 float cycles; /* number of cycles since initial time */ 00102 00103 00104 /*----- calculate time series corresponding to the given parameters -----*/ 00105 for (it = 0; it < ts_length; it++) 00106 { 00107 t = x_array[it][1]; 00108 cycles = FREQ*t + gs[1]/360.0; 00109 cycles = cycles - (int)cycles; 00110 if (cycles <= 0.25) 00111 fval = gs[0] * (cycles/0.25); 00112 else 00113 if ((cycles > 0.25) && (cycles <= 0.75)) 00114 fval = gs[0] * (2.0 - (cycles/0.25)); 00115 else 00116 fval = gs[0] * ((cycles/0.25) - 4.0); 00117 ts_array[it] = fval; 00118 } 00119 00120 } 00121 00122 00123 00124