RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
armaproc.cpp
Go to the documentation of this file.
1 //
2 // File = armaproc.cpp
3 //
4 
5 #include <fstream>
6 #include <stdlib.h>
7 #include <iostream>
8 
9 #include "armaproc.h"
10 #include "gausrand.h"
11 #include "mod_yuwa.h"
12 #include "yulewalk.h"
13 
14 using namespace std;
15 
16 //============================================
17 // default constructor
18 
19 template <class T>
21 {
22  Ar_Order = 0;
23  A_Coeffs = NULL;
24  B_Coeffs = NULL;
25  Old_Output = NULL;
26 }
27 //====================================
28 // destructor
29 
30 template <class T>
32 {
33  delete A_Coeffs;
34  delete B_Coeffs;
35  delete Old_Output;
36 }
37 
38 //============================================
39 // Function to dump ARMA parameters to output
40 // stream indicated by uout
41 
42 template <class T>
43 void
45 {
46  int indx;
47  uout << "Drv_Noise_Var = " << Drv_Noise_Var << std::endl;
48 
49  if (Ar_Order > 0) {
50  for (indx = 0; indx <= Ar_Order; indx++)
51  uout << "a[" << indx << "] = " << A_Coeffs[indx] << std::endl;
52  }
53 
54  if (Ma_Order > 0) {
55  for (indx = 0; indx <= Ma_Order; indx++)
56  uout << "b[" << indx << "] = " << B_Coeffs[indx] << std::endl;
57  }
58 
59  return;
60 }
61 
62 //=================================================
63 // function to generate an output sequence of
64 // length seq_len. If noise_seed_init is nonzero,
65 // value supplied will be used as the new seed
66 // for the noise generator. Otherwise, the stored
67 // value will be used.
68 
69 template <class T>
70 T*
71 ArmaProcess<T>::OutputSequence(long noise_seed_init, int seq_len)
72 {
73  int samp_indx, i;
74  T *out_seq, out_samp;
75  long noise_seed;
76  double std_dev;
77 
78  std_dev = sqrt(Drv_Noise_Var);
79  out_seq = new T[seq_len];
80 
81  if (noise_seed_init == 0)
82  noise_seed = Noise_Seed;
83  else
84  noise_seed = noise_seed_init;
85 
86  for (samp_indx = 0; samp_indx < seq_len; samp_indx++) {
87  for (i = Ma_Order; i > 0; i--) {
88  Old_Input[i] = Old_Input[i - 1];
89  }
90  out_samp = std_dev * GaussRandom(&noise_seed);
91  Old_Input[0] = out_samp;
92  for (i = 1; i <= Ma_Order; i++) {
93  out_samp += B_Coeffs[i] * Old_Input[i];
94  }
95  for (i = 0; i < Ar_Order; i++) {
96  out_samp -= A_Coeffs[i + 1] * Old_Output[i];
97  }
98  for (i = Ar_Order - 1; i > 0; i--) {
99  Old_Output[i] = Old_Output[i - 1];
100  }
101  Old_Output[0] = out_samp;
102 
103  out_seq[samp_indx] = out_samp;
104  } // end of loop over samp_indx
105 
106  Noise_Seed = noise_seed;
107  return (out_seq);
108 }
109 template <class T>
110 void
111 ArmaProcess<T>::GetParameters(int* ar_order, T* a_coeff, int* ma_order,
112  T* b_coeff)
113 {
114  int indx;
115  *ar_order = Ar_Order;
116  for (indx = 0; indx <= Ar_Order; indx++) {
117  a_coeff[indx] = A_Coeffs[indx];
118  }
119  *ma_order = Ma_Order;
120  for (indx = 1; indx <= Ma_Order; indx++) {
121  b_coeff[indx] = B_Coeffs[indx];
122  }
123  return;
124 }
125 //---------------------------------------------------
126 template <class T>
127 double
129 {
130  return (Drv_Noise_Var);
131 }
132 template class ArmaProcess<double>;
133 template class ArmaProcess<complex>;
double GetDrivingVariance(void)
Definition: armaproc.cpp:128
double GaussRandom(long *seed)
Definition: gausrand.cpp:10
complex sqrt(const complex _z)
Definition: complex.h:148
T * OutputSequence(long noise_seed, int seq_len)
Definition: armaproc.cpp:71
void DumpParameters(std::ostream &uout)
Definition: armaproc.cpp:44
ArmaProcess(void)
Definition: armaproc.cpp:20
~ArmaProcess(void)
Definition: armaproc.cpp:31
void GetParameters(int *ar_order, T *a_coeff, int *ma_order, T *b_coeff)
Definition: armaproc.cpp:111