svn commit: r245188 - user/adrian/ath_radar_stuff/src/spectral_fft
Adrian Chadd
adrian at FreeBSD.org
Tue Jan 8 22:23:14 UTC 2013
Author: adrian
Date: Tue Jan 8 22:23:12 2013
New Revision: 245188
URL: http://svnweb.freebsd.org/changeset/base/245188
Log:
Add in a very hacky and mostly incorrect rolling average and slightly
decaying max-hold implementation.
Plot the max in red, and the current average-ish in blue.
Modified:
user/adrian/ath_radar_stuff/src/spectral_fft/fft_eval.c
user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.c
user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.h
Modified: user/adrian/ath_radar_stuff/src/spectral_fft/fft_eval.c
==============================================================================
--- user/adrian/ath_radar_stuff/src/spectral_fft/fft_eval.c Tue Jan 8 22:23:09 2013 (r245187)
+++ user/adrian/ath_radar_stuff/src/spectral_fft/fft_eval.c Tue Jan 8 22:23:12 2013 (r245188)
@@ -231,20 +231,23 @@ int draw_picture(int highlight, int star
float signal;
int freqKhz = i;
- /* Fetch dBm value at the given frequency in KHz */
- signal = (float) fft_fetch_freq(freqKhz);
x = X_SCALE * (freqKhz - (startfreq * 1000)) / 1000;
+ /* Fetch dBm value at the given frequency in KHz */
+ signal = (float) fft_fetch_freq_avg(freqKhz);
+ color = BMASK | AMASK;
+ opacity = 64;
y = 400 - (400.0 + Y_SCALE * signal);
+ if (bigpixel(pixels, x, y, color, opacity) < 0)
+ continue;
+ /* .. and the max */
+ signal = (float) fft_fetch_freq_max(freqKhz);
color = RMASK | AMASK;
opacity = 255;
-
-// printf(" (%d) %d,%d\n", freqKhz, x, y);
-
+ y = 400 - (400.0 + Y_SCALE * signal);
if (bigpixel(pixels, x, y, color, opacity) < 0)
continue;
-
}
SDL_BlitSurface(surface, NULL, screen, NULL);
Modified: user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.c
==============================================================================
--- user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.c Tue Jan 8 22:23:09 2013 (r245187)
+++ user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.c Tue Jan 8 22:23:12 2013 (r245188)
@@ -70,30 +70,40 @@ fft_add_sample(struct radar_entry *re, s
continue;
/* XXX until i figure out what's going on */
- if (fe->pri.bins[i].dBm == 0 || fe->pri.bins[i].dBm < -185)
+ if (fe->pri.bins[i].dBm == 0 || fe->pri.bins[i].dBm < -185) // || fe->pri.bins[i].dBm > -10)
continue;
- /* Store the current dBm value */
- fdata.pts[fidx] = fe->pri.bins[i].dBm;
+ /* Rolling/decaying average */
+ fdata.avg_pts[fidx] = (((fdata.avg_pts[fidx] * 100) / 90) + fe->pri.bins[i].dBm) / 2;
+
+ /* Max */
+ if (fdata.max_pts[fidx] == 0 || fe->pri.bins[i].dBm > fdata.max_pts[fidx]) {
+ fdata.max_pts[fidx] = fe->pri.bins[i].dBm;
+ } else {
+ fdata.max_pts[fidx] = ((fdata.max_pts[fidx] * 997) + (fe->pri.bins[i].dBm * 3)) / 1000;
+ }
}
}
int
-fft_fetch_freq(int freqKhz)
+fft_fetch_freq_avg(int freqKhz)
{
int fidx;
fidx = freq2fidx(freqKhz);
if (fidx < 0)
- return -150; /* XXX */
+ return -180; /* XXX */
+
+ return fdata.avg_pts[fidx];
+}
+int
+fft_fetch_freq_max(int freqKhz)
+{
+ int fidx;
-#if 0
- printf("%s: khz=%d, fidx=%d, val=%d\n",
- __func__,
- freqKhz,
- fidx,
- fdata.pts[fidx]);
-#endif
+ fidx = freq2fidx(freqKhz);
+ if (fidx < 0)
+ return -180; /* XXX */
- return fdata.pts[fidx];
+ return fdata.max_pts[fidx];
}
Modified: user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.h
==============================================================================
--- user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.h Tue Jan 8 22:23:09 2013 (r245187)
+++ user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.h Tue Jan 8 22:23:12 2013 (r245188)
@@ -10,12 +10,14 @@
((6000-2300)*FFT_HISTOGRAM_RESOLUTION)
struct fft_histogram_data {
- int pts[FFT_HISTOGRAM_SIZE];
+ int avg_pts[FFT_HISTOGRAM_SIZE];
+ int max_pts[FFT_HISTOGRAM_SIZE];
};
extern void fft_histogram_init(void);
extern void fft_add_sample(struct radar_entry *re,
struct radar_fft_entry *fe);
-extern int fft_fetch_freq(int freqKhz);
+extern int fft_fetch_freq_avg(int freqKhz);
+extern int fft_fetch_freq_max(int freqKhz);
#endif
More information about the svn-src-user
mailing list