aboutsummaryrefslogtreecommitdiff
path: root/src/modem_stats.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/modem_stats.c')
-rw-r--r--src/modem_stats.c80
1 files changed, 41 insertions, 39 deletions
diff --git a/src/modem_stats.c b/src/modem_stats.c
index df07e62..6f83baf 100644
--- a/src/modem_stats.c
+++ b/src/modem_stats.c
@@ -25,34 +25,33 @@
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#include "modem_stats.h"
+
#include <assert.h>
#include <math.h>
-#include "modem_stats.h"
+
#include "codec2_fdmdv.h"
#include "kiss_fft.h"
-void modem_stats_open(struct MODEM_STATS *f)
-{
- int i;
+void modem_stats_open(struct MODEM_STATS *f) {
+ int i;
- /* zero out all the stats */
+ /* zero out all the stats */
- memset(f, 0, sizeof(struct MODEM_STATS));
+ memset(f, 0, sizeof(struct MODEM_STATS));
- /* init the FFT */
+ /* init the FFT */
#ifndef __EMBEDDED__
- for(i=0; i<2*MODEM_STATS_NSPEC; i++)
- f->fft_buf[i] = 0.0;
- f->fft_cfg = (void*)kiss_fft_alloc (2*MODEM_STATS_NSPEC, 0, NULL, NULL);
- assert(f->fft_cfg != NULL);
+ for (i = 0; i < 2 * MODEM_STATS_NSPEC; i++) f->fft_buf[i] = 0.0;
+ f->fft_cfg = (void *)kiss_fft_alloc(2 * MODEM_STATS_NSPEC, 0, NULL, NULL);
+ assert(f->fft_cfg != NULL);
#endif
}
-void modem_stats_close(struct MODEM_STATS *f)
-{
+void modem_stats_close(struct MODEM_STATS *f) {
#ifndef __EMBEDDED__
- KISS_FFT_FREE(f->fft_cfg);
+ KISS_FFT_FREE(f->fft_cfg);
#endif
}
@@ -86,39 +85,42 @@ void modem_stats_close(struct MODEM_STATS *f)
\*---------------------------------------------------------------------------*/
#ifndef __EMBEDDED__
-void modem_stats_get_rx_spectrum(struct MODEM_STATS *f, float mag_spec_dB[], COMP rx_fdm[], int nin)
-{
- int i,j;
- COMP fft_in[2*MODEM_STATS_NSPEC];
- COMP fft_out[2*MODEM_STATS_NSPEC];
- float full_scale_dB;
+void modem_stats_get_rx_spectrum(struct MODEM_STATS *f, float mag_spec_dB[],
+ COMP rx_fdm[], int nin) {
+ int i, j;
+ COMP fft_in[2 * MODEM_STATS_NSPEC];
+ COMP fft_out[2 * MODEM_STATS_NSPEC];
+ float full_scale_dB;
- /* update buffer of input samples */
+ /* update buffer of input samples */
- for(i=0; i<2*MODEM_STATS_NSPEC-nin; i++)
- f->fft_buf[i] = f->fft_buf[i+nin];
- for(j=0; j<nin; j++,i++)
- f->fft_buf[i] = rx_fdm[j].real;
- assert(i == 2*MODEM_STATS_NSPEC);
+ for (i = 0; i < 2 * MODEM_STATS_NSPEC - nin; i++)
+ f->fft_buf[i] = f->fft_buf[i + nin];
+ for (j = 0; j < nin; j++, i++) f->fft_buf[i] = rx_fdm[j].real;
+ assert(i == 2 * MODEM_STATS_NSPEC);
- /* window and FFT */
+ /* window and FFT */
- for(i=0; i<2*MODEM_STATS_NSPEC; i++) {
- fft_in[i].real = f->fft_buf[i] * (0.5 - 0.5*cosf((float)i*2.0*M_PI/(2*MODEM_STATS_NSPEC)));
- fft_in[i].imag = 0.0;
- }
+ for (i = 0; i < 2 * MODEM_STATS_NSPEC; i++) {
+ fft_in[i].real =
+ f->fft_buf[i] *
+ (0.5 - 0.5 * cosf((float)i * 2.0 * M_PI / (2 * MODEM_STATS_NSPEC)));
+ fft_in[i].imag = 0.0;
+ }
- kiss_fft((kiss_fft_cfg)f->fft_cfg, (kiss_fft_cpx *)fft_in, (kiss_fft_cpx *)fft_out);
+ kiss_fft((kiss_fft_cfg)f->fft_cfg, (kiss_fft_cpx *)fft_in,
+ (kiss_fft_cpx *)fft_out);
- /* FFT scales up a signal of level 1 FDMDV_NSPEC */
+ /* FFT scales up a signal of level 1 FDMDV_NSPEC */
- full_scale_dB = 20*log10(MODEM_STATS_NSPEC*FDMDV_SCALE);
+ full_scale_dB = 20 * log10(MODEM_STATS_NSPEC * FDMDV_SCALE);
- /* scale and convert to dB */
+ /* scale and convert to dB */
- for(i=0; i<MODEM_STATS_NSPEC; i++) {
- mag_spec_dB[i] = 10.0*log10f(fft_out[i].real*fft_out[i].real + fft_out[i].imag*fft_out[i].imag + 1E-12);
- mag_spec_dB[i] -= full_scale_dB;
- }
+ for (i = 0; i < MODEM_STATS_NSPEC; i++) {
+ mag_spec_dB[i] = 10.0 * log10f(fft_out[i].real * fft_out[i].real +
+ fft_out[i].imag * fft_out[i].imag + 1E-12);
+ mag_spec_dB[i] -= full_scale_dB;
+ }
}
#endif