complex peakDetect(const signalVector &rxBurst, float *peakIndex, float *avgPwr) { complex maxVal = 0.0; float maxIndex = -1; float sumPower = 0.0; for (unsigned int i = 0; i < rxBurst.size(); i++) { float samplePower = rxBurst[i].norm2(); if (samplePower > maxVal.real()) { maxVal = samplePower; maxIndex = i; } sumPower += samplePower; } // interpolate around the peak // to save computation, we'll use early-late balancing float earlyIndex = maxIndex-1; float lateIndex = maxIndex+1; float incr = 0.5; while (incr > 1.0/1024.0) { complex earlyP = interpolatePoint(rxBurst,earlyIndex); complex lateP = interpolatePoint(rxBurst,lateIndex); if (earlyP < lateP) earlyIndex += incr; else if (earlyP > lateP) earlyIndex -= incr; else break; incr /= 2.0; lateIndex = earlyIndex + 2.0; } maxIndex = earlyIndex + 1.0; maxVal = interpolatePoint(rxBurst,maxIndex); if (peakIndex!=NULL) *peakIndex = maxIndex; if (avgPwr!=NULL) *avgPwr = (sumPower-maxVal.norm2()) / (rxBurst.size()-1); return maxVal; }
void spline::interpolateData() { debug("Interpolating spline data: "); int s = rawPoints.size(); int e = s - 1; //if we're looping, need to do if(loop) e = s + 2; for(int i=2; i<e; i++) { //put the start point on points.push_back(rawPoints[(i - 1)%s]); //see if that was the highest point if(rawPoints[(i-1)%s][2] > top[2]) top = rawPoints[(i-2)%s]; //interpolate all the points in between for(float u = SPLINE_RESOLUTION; u <= 1.0 - SPLINE_RESOLUTION; u += SPLINE_RESOLUTION) { //load up the point vector, use modulus division to prevent //an out of bounds. CWSpaceVector p[4]; p[0] = rawPoints[(i - 2) % s]; p[1] = rawPoints[(i - 1) % s]; p[2] = rawPoints[i % s]; p[3] = rawPoints[(i + 1) % s]; //interpolate it up! CWSpaceVector c = interpolatePoint(u, p); //see if it's the hightest yet if(c[2] > top[2]) top = c; if(c[2] < bottom[2]) bottom = c; //push that new point on the points vector points.push_back(c); } } printf("done\n"); }
void interpolateGrid() { point *p1; double temp; for(int i=0;i<length*gridResolution;i++) { for(int j=0;j<width*gridResolution;j++) { for(int k=0;k<height*gridResolution;k++) { p1 = new point(i/gridResolution,j/gridResolution,k/gridResolution); temp = interpolatePoint(p1); p1->getProperties()->setTemp(temp); grid[i][j][k] = *p1; } } } }
/** * Draws a line with interpolated colors */ Line bkgl::drawLine(Point p1, Point p2) { int x1 = p1.x; int y1 = p1.y; int x2 = p2.x; int y2 = p2.y; Line line; float dy = y2 - y1; float dx = x2 - x1; float m = dy / dx; // slope float b = y1 - m*(float)x1; // intercept int xStart = x1; int yStart = y1; int xEnd = x2; int yEnd = y2; float d1, d2; // distances used for color interpolation if (fabs(dx) > fabs(dy)) // slope < 1 { float ys; dx = (dx > 0) ? 1 : -1; // determine direction while (x1 != x2) { x1 += dx; // increment x ys = (m*(float)x1+b)+0.5; // +0.5 for rounding d1 = pointDistance(xStart, yStart, x1, ys); d2 = pointDistance(xStart, yStart, x2, y2); float distance = d1/d2; Point p = interpolatePoint(x1, ys, p1, p2, distance); if (y1 == y2) setPixel(p); else setPixel(p); line.push_back(p); } } else // slope >=1 { dy = (dy > 0) ? 1 : -1; // determine direction while (y1 != y2) { y1 += dy; // increment y x1 = (dx !=0) ? (((float)y1-b)/m)+0.5 : x1; // make sure dx != 0 d1 = pointDistance(xStart, yStart, x1, y1); d2 = pointDistance(xStart, yStart, x2, y2); float distance = d1/d2; Point p = interpolatePoint(x1, y1, p1, p2, distance); setPixel(p); line.push_back(p); } } //cerr << "Draw Line, Line size: " << line.size() << endl; return line; }