summaryrefslogtreecommitdiff
path: root/gascop.c
diff options
context:
space:
mode:
authorYuval Adam <yuv.adm@gmail.com>2014-10-12 11:13:45 +0300
committerYuval Adam <yuv.adm@gmail.com>2014-10-12 11:13:45 +0300
commitb0a2e35d328c1384bb254404cbbc8bb05965c6f7 (patch)
tree891df5e842aaee07e9d1deeae55335eb13029fe4 /gascop.c
parentf46d6e570f2d61aa615e7ec1775527150f5993f6 (diff)
Add two point moving average and improve phase detection
Diffstat (limited to 'gascop.c')
-rw-r--r--gascop.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/gascop.c b/gascop.c
index edae045..c6dcfab 100644
--- a/gascop.c
+++ b/gascop.c
@@ -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;
}