//Programm zur Berechnung von Trend und Periodizitaet einer unregelmaessig beprobten Zeitreihe //Die Periodizität wird über die Korrelation mit einer (Co)Sinusschwingung ermittelt, indem die //"normierte" Zeitreihe (Mittelwert abgezogen, durch Standardabweichung dividiert) mit berechneten //Schwingungen verglichen wird. Die Korrelationskoeffizienten werden nach DAVIS ermittelt. //Die Summe der Abweichungsquadrate (SAQ) ist besser geeignet! Die Signifikanzgrenzen wurden nach //HARTUNG (1982) ermittelt. Es ergeben sich leichte Abweichungen zu den Tabellenwerken, da //aufgrund der numerischen Probleme auf eine Korrektur von der Normalverteilung auf die //STUDENT-Verteilung verzichtet wurde. Der Fehler wirkt sich bei den Korrelationskoeffizienten //bei n>100 an der 2. Nachkommastelle aus. //Program for the calculation of trend and periodicity of an unevenly sampled time series //The periodicity is calculated by a correlation of the sampled time series with a sine-oscillation //The sample time series is normed (average subtracted, divided by standard deviation). The //korrelation coefficient is calculated according to DAVIS. The sum of squared deviation may be more //efficient, therefore it is calculated too. In calculation od significance there are small //deviations to tables because of a missing correction to the STUDENT-distribution. This mistake //is significant only to the 2nd position after the delimiter at n>100. #include #include #include #include void welcome() { cout<<"Welcome to a special kind of time series analysis!\n"; cout<<"(C) Wolfgang Gossel, Muehlweg 49, D-06114 Halle\n"; cout<<"-------------------------------------------------------------\n"; cout<<"This time series analysis calculates\n"; cout<<"- statistical measures (average, variance, standarddeviation)\n"; cout<<"- a trend\n"; cout<<"- a periodogram\n"; cout<<"- the residuals of measurements, average, trend and periodicity analysis\n"; cout<<"of unevenly sampled datasets.\n"; cout<<"-------------------------------------------------------------\n"; } int datenein1(char datei_ein[]) { int a=0; double b=0.0; cout<<"Please write the name of the file\n"; cout<<"with the dataset to be analyzed!\n"; cout<<"The file must be a textfile with\n"; cout<<"- time (integer), ordered, and\n"; cout<<"- value (float)\n"; cout<<"and a blank between both columns.\n"; cout<<"File name:"; cin>>datei_ein; int i=0; ifstream fin(datei_ein); while (!fin.eof()) { fin>>a>>b; i++; } fin.close(); i=i-1; return i; } void null_setzen(int wert[], int i) { int a=0; for (a=0;a<=i-1;a++) { wert[a]=0; } } void null_setzen(double wert[], int i) { int a=0; for (a=0;a<=i-1;a++) { wert[a]=0.0; } } void datenein2(char datei_ein[], int i, int twert[], double messwert[], double koeff[]) { int a=0; int *atwert = new int[i]; null_setzen(atwert,i); ifstream fin(datei_ein); while (!fin.eof()) { fin>>atwert[a]>>messwert[a]; a++; } koeff[1]=atwert[0]; for (a=0;a<=i-1;a++) { twert[a]=atwert[a]-atwert[0]+1; } fin.close(); } double mittelwert(double wert[], int i) { int n=0; double sum=0.0,mittel=0.0; for (n=0;n<=i-1;n++) { sum=sum+wert[n]; } return mittel=sum/(i+1); } double varianz(double wert[], double koeff[], int i) { int n; double saq=0.0,var=0.0; for (n=0;n<=i-1;n++) { saq=saq+((wert[n]-koeff[2])*(wert[n]-koeff[2])); } return var=saq/i; } void aus_stat(double koeff[], int i) { cout<<"Average y: "<koeff[9]) { cout<<"The correlation coefficient is higher than the 99%-level of significance of about "<diffx) koeff[16]=diffx; //dxmin wird Minimum if (koeff[17]>koeff[13]; cout<<"\n- Increment: "; cin>>koeff[12]; float p_max=twert[i-1]/2; koeff[14]=(p_max-koeff[13])/koeff[12]; } void per_korr(int twert[], double messwert[], int i, double koeff[],double phi[],double ampl[], double kkk_per[], double saq_per[]) { int a=0,p=0,o=0,c=0,d=0,e=100; int min_phi; double omega=0.0, t=0.0, phi2=0.0, saq2=0.0, min_saq=0.0, min_ampl=0.0, k_ampl=0.0,s_ampl=0.0,k_help=0.0,k_phi=0.0,s_phi=0.0,saq3=0.0; double *y = new double[i]; double *saq = new double[e]; null_setzen(y,i); null_setzen(saq,e); for (a=0;a<=koeff[14]-1;a++) { cout<k_help) { phi[a]=phi2; k_help=k_phi; } } k_help=0.0; null_setzen(y,i); for (o=0;o<=koeff[3]+1;o++) { for (d=0;d<=i-1;d++) { t=koeff[5]+koeff[6]*twert[d]; y[d]=t+o*cos(omega*twert[d]+phi[a]); saq2=saq2+sqrt((y[d]-messwert[d])*(y[d]-messwert[d])); } k_ampl=kkk_ber(y,messwert,i); s_ampl=saq2; if (k_ampl>k_help) { ampl[a]=o; k_help=k_ampl; } null_setzen(y,i); k_ampl=0.0; } for (d=0;d<=i-1;d++) { t=koeff[5]+koeff[6]*twert[d]; y[d]=t+ampl[a]*cos(omega*twert[d]+phi[a]); saq3=saq3+((y[d]-messwert[d])*(y[d]-messwert[d])); } kkk_per[a]=kkk_ber(y,messwert,i); saq_per[a]=saq3; saq3=0.0; saq2=0.0; phi2=0.0; min_saq=0.0; } } void aus_per(int twert[], double messwert[], int i, double koeff[], double phi[], double ampl[],double kkk_per[], double saq_per[]) { int a=0, n=0, wahl=0; double p=0.0,kkk_e_t=0.0,kkk_e_p=0.0; double *t = new double[i]; double *fp = new double[i]; cout<<"In the following periodogram the intensities are given by correlation coefficients (cc) and\n"; cout<<"sums of quadratic deviations (qd).\n"; cout<<"The phase shift (Phi) and amplitudes (A) are calculated by optimization of these values.\n"; cout<<"Periode Phi A cc qd\n"; for (a=0;a<=koeff[14]-1;a++) { cout.width(5);cout<>n; wahl=(n-koeff[13])/koeff[12]; cout<<"time measurement FunctionValue Trend Residuals Trend FunctionValue period Residuals period"; for (a=0;a<=i-1;a++) { p=koeff[13]+koeff[12]*wahl; t[a]=koeff[5]+koeff[6]*twert[a]; fp[a]=t[a]+ampl[wahl]*cos((6.2831583/p)*twert[a]+phi[wahl]); cout.width(5);cout<>datei_aus; ofstream fout(datei_aus); fout<<"Time Measurement FunctionValue Trend Residuals Trend FunctionValue Periods Residuals Period"; for (a=0;a<=i-1;a++) { p=koeff[13]+(koeff[12]*wahl); t[a]=koeff[5]+koeff[6]*twert[a]; fp[a]=t[a]+koeff[4]*cos((6.2831583/p)*twert[a]); fout.width(5);fout<