#include #include #include "pdp1.h" void freqanalysis(void); extern void realft(float data[], int n, int isign); // Function double frandbase2(void) {{{ double frandbase2(void) { static int counter2=0; return (revers_base(counter2++, 2)); } // }}} // Function double revers_base(int num, int n) {{{ double revers_base(int num, int n) { double power, rev; int inum, iquot, irem; rev = 0.; inum = num; power = 1.; do { iquot = inum/n; irem = inum - n*iquot; power /= n; rev += irem*power; inum = iquot; } while (inum > 0); return (rev); } // }}} //********************************************************************** // irand(iseed) returns values 1 through 2**31-2. // From "Random number generators: good ones are hard to find", S. Park // and K. Miller, Communications of ACM, October 1988, pp 1192-1201. // This is from page 1195, and is to work on any system for which // maxint is 2**31-1 or larger. Due earlier to Schrage, as cited by P&M. // // Note: OK values for iseed are 1 through 2**31-2. Give it 0 or 2*31-1 // and it will return the same values thereafter! // // C version 6/91, Bruce Langdon. // // Algorithm replaces seed by mod(a*seed,m). First represent // seed = q*hi + lo. Then // a*seed = a*q*hi + lo = (m - r)*hi + a*lo = (a*lo - r*hi) + m*hi, // and new seed = a*lo - r*hi unless negative; if so, then add m. // Function float frand(void) {{{ float frand(void) { long a = 16807, m = 2147483647, q = 127773, r = 2836; long hi, lo; float fnumb; hi = seed/q; lo = seed - q*hi; seed = a*lo - r*hi; // "seed" will always be a legal integer of 32 bits (including sign). if (seed <= 0) seed = seed + m; fnumb = seed/2147483646.0; return (fnumb); } // }}} // Returns bit reversed num in base 2 // Function double revers(unsigned int num) {{{ double revers(unsigned int num) { double f=0.5, sum=0.0; while(num) { if (num & 1) sum += f; // is 1st bit set? f *= 0.5; num >>= 1; // fast divide by 2 } return (sum); } // }}} // Function double fdist(double vv, int k, int isp) {{{ double fdist(double vv, int k, int isp) { double u; u = (vv - v0[isp][k])/vt[isp][k]; return (exp(-u*u*0.5)); } // }}} //********************************************************************** // time history accumulator; calculates and stores all history values, // and performs combing on history values when low on memory // Function void history(void) {{{ void history(void) { register int i, j, isp, k; static float jtemp[NSMAX]; static int count=1, nrftcount=0, nrfcount=0; //***** MCC rates ***** if (it[0]) { for (i=0; i= nfft) { freqanalysis(); thist_hi=0; } cur_hist[thist_hi]= exti; pow_hist[thist_hi]= exti*phi[0]; phi_hist[0][thist_hi] = phi[0]; phi_hist[1][thist_hi] = phi[nc/2]; Local_t_array[thist_hi] = t; thist_hi++; // Calculating the time ave. moments {{{ if (nrftcount == nfft) { nrfcount++; for (isp=0; isp= HISTMAX) { // comb time histories for (isp=0; isp 0.0) ? 0.0 : 180.0; for (i=1, j=2; i< freq_hi; i++, j+=2) { temp1[i]= sqrt(cur_fft[j]*cur_fft[j]+ cur_fft[j+1]*cur_fft[j+1])/freq_hi; if (fabs(cur_fft[j+1]) < 1e-30 && fabs(cur_fft[j]) < 1e-30) temp2[i]= 0.0; else temp2[i]= (180./M_PI)*atan2(cur_fft[j], cur_fft[j+1]); } for (i=0; i< freq_hi; i++) { cur_fft[i]= temp1[i]; cur_fft[freq_hi+i]= temp2[i]; } // }}} //*** Computing mag and phase of the power signal **** {{{ temp1[0]= fabs(pow_fft[0])/freq_hi/2; temp2[0]= (pow_fft[0] > 0.0) ? 0.0 : 180.0; for (i=1, j=2; i< freq_hi; i++, j+=2) { temp1[i]= sqrt(pow_fft[j]*pow_fft[j]+ pow_fft[j+1]*pow_fft[j+1])/freq_hi; if (fabs(pow_fft[j+1]) < 1e-30 && fabs(pow_fft[j]) < 1e-30) temp2[i]= 0.0; else temp2[i]= (180./M_PI)*atan2(pow_fft[j], pow_fft[j+1]); } for (i=0; i< freq_hi; i++) { pow_fft[i]= temp1[i]; pow_fft[freq_hi+i]= temp2[i]; } // }}} //*** Computing mag and phase of the voltage signal ** {{{ temp1[0]= fabs(phi_fft[0])/freq_hi/2; temp2[0]= (phi_fft[0] > 0.0) ? 0.0 : 180.0; for (i=1, j=2; i< freq_hi; i++, j+=2) { temp1[i]= sqrt(phi_fft[j]*phi_fft[j]+ phi_fft[j+1]*phi_fft[j+1])/freq_hi; if (fabs(phi_fft[j+1]) < 1e-30 && fabs(phi_fft[j]) < 1e-30) temp2[i]= 0.0; else temp2[i]= (180./M_PI)*atan2(phi_fft[j], phi_fft[j+1]); } for (i=0; i< freq_hi; i++) { phi_fft[i]= temp1[i]; phi_fft[freq_hi+i]= temp2[i]; } // }}} //*** Computing mag and phase of the mid-potential signal ** {{{ temp1[0]= fabs(mphi_fft[0])/freq_hi/2; temp2[0]= (mphi_fft[0] > 0.0) ? 0.0 : 180.0; for (i=1, j=2; i< freq_hi; i++, j+=2) { temp1[i]= sqrt(mphi_fft[j]*mphi_fft[j]+ mphi_fft[j+1]*mphi_fft[j+1])/freq_hi; if (fabs(mphi_fft[j+1]) < 1e-30 && fabs(mphi_fft[j]) < 1e-30) temp2[i]= 0.0; else temp2[i]= (180./M_PI)*atan2(mphi_fft[j], mphi_fft[j+1]); } for (i=0; i< freq_hi; i++) { mphi_fft[i]= temp1[i]; mphi_fft[freq_hi+i]= temp2[i]; } // }}} } // }}} // Modeline for ViM {{{1 // vim:set ts=4: // vim600:fdm=marker fdl=0 fdc=3: // 1}}}