// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> bool AmplitudeProcessor_msbb::computeAmplitude(const DoubleArray &data, size_t i1, size_t i2, size_t si1, size_t si2, double offset, AmplitudeIndex *dt, AmplitudeValue *amplitude, double *period, double *snr) { /* * Low-level signal amplitude computation. This is magnitude specific. * * Input: * f double array of length n * i1,i2 indices defining the measurement window, * 0 <= i1 < i2 <= n * offset this is subtracted from the samples in f before * computation * * Output: * dt Point at which the measurement was mad/completed. May * be the peak time or end of integration. * amplitude amplitude. This may be a peak amplitude as well as a * sum or integral. * period dominant period of the signal. Optional. If the period * is not computed, set it to -1. */ size_t imax = find_absmax(data.size(), (const double*)data.data(), si1, si2, offset); double amax = fabs(data[imax] - offset); double pmax = -1; double pstd = 0; // standard error of period if ( !measure_period(data.size(), static_cast<const double*>(data.data()), imax, offset, &pmax, &pstd) ) pmax = -1; if ( amax < *_noiseAmplitude * _config.snrMin ) { amplitude->value = amax / *_noiseAmplitude; setStatus(LowSNR, amplitude->value); return false; } dt->index = imax; *period = pmax; amplitude->value = amax; if ( _usedComponent <= SecondHorizontal ) { if ( _streamConfig[_usedComponent].gain != 0.0 ) amplitude->value /= _streamConfig[_usedComponent].gain; else { setStatus(MissingGain, 0.0); return false; } } else return false; return true; }
void main(void) { #define SWITCHES *(unsigned char volatile *)(0xB580) #define PORTA *(unsigned char volatile *)(0x1000) #define TCTL1 *(unsigned char volatile *)(0x1020) #define DDRD *(unsigned char volatile *)(0x1009) #define SPCR *(unsigned char volatile *)(0x1028) #define TCTL2 *(unsigned char volatile *)(0x1021) #define TMSK2 *(unsigned char volatile *)(0x1024) #define TIC1 *(unsigned int volatile *)(0x1010) #define OPTION *(unsigned char volatile *)(0x1039) #define ADCTL *(unsigned char volatile *)(0x1030) #define ADR1 *(unsigned char volatile *)(0x1031) #define ADR2 *(unsigned char volatile *)(0x1032) #define ADR3 *(unsigned char volatile *)(0x1033) #define ADR4 *(unsigned char volatile *)(0x1034) #define TOC2 *(unsigned int volatile *)(0x1018) #define TCNT *(unsigned int volatile *)(0x100E) #define TFLG1 *(unsigned char volatile *)(0x1023) INT16U v1,v2,average,ontime,period,duty,freq; INT8U voltage, disphigh, displow; initialize_hardware(); display_titles(); while(1) { get_voltage_from_sample(&v1, &v2, &average); v1 = 2.2*v1; v2 = 2.2*v2; average = 2*average; //display average dsp(2,3,15); dsp(0,((average / 100) %10) + 0x30,0); dsp(2,3,17); dsp(0,((average / 10) %10) + 0x30,0); dsp(0,((average / 1) %10) + 0x30,0); //display hight voltage dsp(2,2,3); dsp(0,((v1 / 100) %10) + 0x30,0); dsp(2,2,5); dsp(0,((v1 / 10) %10) + 0x30,0); dsp(0,((v1 / 1) %10) + 0x30,0); //display low voltage dsp(2,3,3); dsp(0,((v2 / 100) %10) + 0x30,0); dsp(2,3,5); dsp(0,((v2 / 10) %10) + 0x30,0); dsp(0,((v2 / 1) %10) + 0x30,0); if(v1 > 350) { period = measure_period(); ontime = measure_ontime(); //display duty cycle duty = (ontime*10)/(period/10); dsp(2,2,15); dsp(0,((duty / 100) %10) + 0x30,0); dsp(0,((duty / 10) %10) + 0x30,0); dsp(0,((duty / 1) %10) + 0x30,0); period /= 20; ontime /= 20; //display frequency freq = 100000/period; dsp(2,1,10); dsp(0,((freq / 1000) %10) + 0x30,0); dsp(0,((freq / 100) %10) + 0x30,0); dsp(0,((freq / 10) %10) + 0x30,0); dsp(0,((freq / 1) %10) + 0x30,0); } } }