int blockHighPassTest() { printf("Test BlockHighPass\t\t: "); BlockHighPass highPass(NULL, "TEST_HP"); // test initial state ASSERT(equal(10.0f, highPass.getFCut())); ASSERT(equal(0.0f, highPass.getU())); ASSERT(equal(0.0f, highPass.getY())); ASSERT(equal(0.0f, highPass.getDt())); // set dt highPass.setDt(0.1f); ASSERT(equal(0.1f, highPass.getDt())); // set state highPass.setU(1.0f); ASSERT(equal(1.0f, highPass.getU())); highPass.setY(1.0f); ASSERT(equal(1.0f, highPass.getY())); // test update ASSERT(equal(0.2746051f, highPass.update(2.0f))); // test end condition for (int i = 0; i < 100; i++) { highPass.update(2.0f); } ASSERT(equal(0.0f, highPass.getY())); ASSERT(equal(0.0f, highPass.update(2.0f))); printf("PASS\n"); return 0; }
void randist_bang(t_randist *x) { long possNum = x->possNum; float var1 = x->varFlt1; float var2 = x->varFlt2; // post("var1 = lf1 /n var2 = %f2", var1,var2); //Select which function to execute switch (x->distType) { case 0: x->randVar = equalDist(x,possNum); break; case 1: x->randVar = highPass(possNum); break; case 2: x->randVar = lowPass(possNum); break; case 3: x->randVar = triangle(possNum); break; case 4: x->randVar = gaussian(possNum, var1, var2); break; case 5: x->randVar = exponential(possNum, var2); break; default: post("error with distType"); break; } outlet_float(x->rand_out, x->randVar); }
// function containing the filtering of the data int filter() { insert(&buffered_raw_data, getNextData()); insert(&buffered_LP_data, lowPass(&buffered_raw_data, &buffered_LP_data)); insert(&buffered_HP_data, highPass(&buffered_LP_data, &buffered_HP_data)); insert(&buffered_derivative_square_data, derivative_square(&buffered_HP_data)); return movingWindowIntegration(&buffered_derivative_square_data); }
int derivative(){ // start = clock(); derX = highPass(); derYn = ( 2 * derX + derXn[0] - derXn[2] - 2 * derXn[3]) / 8; derXn[3] = derXn[2]; derXn[2] = derXn[1]; derXn[1] = derXn[0]; derXn[0] = derX; // end = clock(); // time_spent_der += (double)(end - start) / CLOCKS_PER_SEC; return derYn; }
int main() { //Two booleans are used when taking calculating the runtime int clockOn = 0; int totalClockOn = 1; //Variables used in calculating runtime clock_t start, clockBeforeRead, clockAfterRead, clockAfterLowPass, clockAfterHighPass, clockAfterDer, clockAfterSquare, clockAfterMWI, clockAfterIdentifyPeaks, end; double cpuTimeUsed; double timeReadData = 0; double timeLowPass = 0; double timeHighPass = 0; double timeDerivative = 0; double timeSquare = 0; double timeMWindowInt = 0; double timeIdentifyPeaks = 0; //The file to read from static const char filename[] = "ECG.txt"; FILE *file = fopen(filename, "r"); //Arrays and a variable to keep track of the values after each filter int input[13] = { 0 }; int afterLowpass[33] = { 0 }; int afterHighpass[5] = { 0 }; int afterDerivative = 0; int afterSquare[30] = { 0 }; int afterWindowIntegration[3] = { 0 }; int value; int counter = 0; if (totalClockOn) { start = clock(); } //The loops runs as long as it has not reached the end of the file while (!feof(file)) { if (clockOn) { clockBeforeRead = clock(); } counter++; //The nex value is saved in the variable "value" value = getNextData(file); insertArray(input, 13, value); /*if (clockOn) { clockAfterRead = clock(); timeReadData =+ ((double) ((clockAfterRead - clockBeforeRead)) / CLOCKS_PER_SEC ) * 1000; }*/ lowPass(input, afterLowpass); /*if (clockOn) { clockAfterLowPass = clock(); timeLowPass =+ ((double) ((clockAfterLowPass - clockAfterRead)) / CLOCKS_PER_SEC ) * 1000; }*/ highPass(afterLowpass, afterHighpass); /*if (clockOn) { clockAfterHighPass = clock(); timeHighPass =+ ((double) ((clockAfterHighPass - clockAfterLowPass)) / CLOCKS_PER_SEC ) * 1000; }*/ afterDerivative = derivative(afterHighpass); /*if (clockOn) { clockAfterDer = clock(); timeDerivative =+ ((double) ((clockAfterDer - clockAfterHighPass)) / CLOCKS_PER_SEC ) * 1000; }*/ square(afterDerivative, afterSquare); /*if (clockOn) { clockAfterSquare = clock(); timeSquare =+ ((double) ((clockAfterSquare - clockAfterDer)) / CLOCKS_PER_SEC ) * 1000; }*/ mWindowIntegration(afterSquare, afterWindowIntegration); if (clockOn) { clockAfterMWI = clock(); timeMWindowInt = +((double) ((clockAfterMWI - clockBeforeRead)) / CLOCKS_PER_SEC) * 1000; } identifyPeaks(afterWindowIntegration); if (clockOn) { clockAfterIdentifyPeaks = clock(); timeIdentifyPeaks = +((double) ((clockAfterIdentifyPeaks - clockAfterMWI)) / CLOCKS_PER_SEC) * 1000; } } if (totalClockOn) { end = clock(); cpuTimeUsed = ((double) ((end - start)) / CLOCKS_PER_SEC) * 1000; printf("Total cpu time: %f milliseconds\n", cpuTimeUsed); } if (clockOn) { //printf("Average time read data: %f nanoseconds\nAverage time Low Pass filter: %f nanoseconds\nAverage time High Pass filter: %f nanoseconds\n", timeReadData, timeLowPass, timeHighPass); //printf("Average time derivative filter: %f nanoseconds\nAverage time square filter: %f nanoseconds\nAverage time moving window integration filter: %f nanoseconds\n",timeDerivative, timeSquare, timeMWindowInt); printf("Time to apply filters: %f milliseconds\n", timeMWindowInt); printf("Time to identify peaks: %f milliseconds\n", timeIdentifyPeaks); } return 0; }