| 39 | } |
| 40 | |
| 41 | void |
| 42 | SpectrumView::interpolate(void) |
| 43 | { |
| 44 | unsigned int i, j; |
| 45 | unsigned int count = 1; |
| 46 | unsigned int zero_pos = 0; |
| 47 | SUFLOAT t = 0; |
| 48 | bool first = true; |
| 49 | SUFLOAT left = SIGDIGGER_SCANNER_DEFAULT_BIN_VALUE; |
| 50 | SUFLOAT right = SIGDIGGER_SCANNER_DEFAULT_BIN_VALUE; |
| 51 | bool inGap = false; |
| 52 | |
| 53 | // Find a bin with zero entries, measure its width, |
| 54 | // compute values in both ends and interpolate |
| 55 | |
| 56 | i = 0; |
| 57 | |
| 58 | for (i = 0; i < SIGDIGGER_SCANNER_SPECTRUM_SIZE; ++i) { |
| 59 | if (!inGap) { |
| 60 | if (this->psdCount[i] <= .5f) { |
| 61 | // Found zero! |
| 62 | inGap = true; |
| 63 | zero_pos = i; |
| 64 | count = 1; |
| 65 | |
| 66 | first = i == 0; |
| 67 | if (!first) |
| 68 | left = this->psd[i - 1]; |
| 69 | |
| 70 | } else { |
| 71 | this->psd[i] = this->psdAccum[i] / this->psdCount[i]; |
| 72 | if (this->psdCount[i] > SIGDIGGER_SCANNER_COUNT_MAX) { |
| 73 | this->psdCount[i] = SIGDIGGER_SCANNER_COUNT_RESET; |
| 74 | this->psdAccum[i] = this->psd[i] * SIGDIGGER_SCANNER_COUNT_RESET; |
| 75 | } |
| 76 | } |
| 77 | } else { |
| 78 | if (this->psdCount[i] <= .5f) { |
| 79 | ++count; |
| 80 | } else { |
| 81 | // End of gap of zeroes. Compute right and interpolate |
| 82 | inGap = false; |
| 83 | right = this->psd[i] = this->psdAccum[i] / this->psdCount[i]; |
| 84 | if (first) { |
| 85 | for (j = 0; j < count; ++j) |
| 86 | this->psd[j + zero_pos] = right; |
| 87 | } else { |
| 88 | for (j = 0; j < count; ++j) { |
| 89 | t = static_cast<SUFLOAT>(j + .5f) / count; |
| 90 | this->psd[j + zero_pos] = (1 - t) * left + t * right; |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // Deal with trailing zeroes, if any |
| 98 | if (inGap) |