diff options
| author | Yuval Adam <yuv.adm@gmail.com> | 2014-10-12 11:13:45 +0300 |
|---|---|---|
| committer | Yuval Adam <yuv.adm@gmail.com> | 2014-10-12 11:13:45 +0300 |
| commit | b0a2e35d328c1384bb254404cbbc8bb05965c6f7 (patch) | |
| tree | 891df5e842aaee07e9d1deeae55335eb13029fe4 | |
| parent | f46d6e570f2d61aa615e7ec1775527150f5993f6 (diff) | |
Add two point moving average and improve phase detection
| -rw-r--r-- | gascop.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -235,7 +235,7 @@ int main(int argc, char **argv) { uint32_t j; int i, q; - int nph, ph = 4; /* anything higher than 3 */ + double nph, ph = 3; /* anything higher than 3 */ int ph_len = 0; @@ -255,12 +255,13 @@ int main(int argc, char **argv) { q = Gascop.data[j+1] - 127; /* Compute the instantaneous phase of the next IQ sample */ - nph = atan2(q, i); + /* But take the two point moving average to smooth the signal */ + nph = (atan2(q, i) / 2) + (ph / 2); - /* Check if we have completed a full circle by jumping phase, usually -2/-3 -> 2/3 */ + /* Check if we have completed a full circle by jumping phase */ /* Also add a high pass filter, anything less than 30 is noise */ - if ((nph - ph > 3) && (ph_len > 30)) { - /* printf("Phase jump from %4d to %4d after %4d samples\n", ph, nph, ph_len); */ + if ((ph < 0) && (nph > 0) && (ph_len > 30)) { + /* printf("Phase jump from %4f to %4f after %4d samples\n", ph, nph, ph_len); */ printf("%d,", ph_len); ph_len = 0; } |
