(file) Return to doppler_test.c CVS log (file) Jump to this file's LXR Page (dir) Up to [CENS] / emstar / devel / loc / ar

File: [CENS] / emstar / devel / loc / ar / doppler_test.c (download) / (as text)
Revision: 1.3, Fri Oct 21 16:36:02 2005 UTC (4 years, 1 month ago) by girod
Branch: MAIN
CVS Tags: pregeonet, acoustic-05-18-06, PRE_TOSNIC_FIX, PRE_64BIT, HEAD, ESS_RELEASE_3_5, ESS_RELEASE_3_4, ESS_CONNECTIVITY, ESS_CENTROUTE_TESTING, CYCLOPS_RELEASE_CANDIDATE_2_0, CYCLOPS_PRERELEASE_STABLE, CENTROUTE_EMSTAR_SOCKETS, BG_1_0, BANGLADESH_ARSENIC_1_2, BANGLADESH_ARSENIC_1_1, AMARSS_JR_DEPLOYMENT_6_05_07
Changes since 1.2: +1 -0 lines
added several features

* fixed estimation of noise floor, added normalization after clip extraction
* fixed confidence values to be against the better noise estimates
* recombination scaled by SNR.. (is this good?)
* added code to get noise stats

/*
 *
 * Copyright (c) 2005 The Regents of the University of California.  All 
 * rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Neither the name of the University nor the names of its
 *   contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

/*
 *  test program determines max autocorrelation for different seed values
 */

#include "ar.h"

int main(int argc, char **argv)
{
  int i,j;
  int chirp_len = CHIRP_CHIPS*MOD_FACTOR*RANGE_FACTOR;
  int test_code = 57;

  int16_t *bpsk = g_new(int16_t,chirp_len);
  int16_t *bpsk2 = g_new(int16_t,chirp_len);
  float *f_input;
  float *f_input2;
  float *correl;
  complex *fft_input;
  complex *fft_input2;
  complex *fft_correl;
  f_input = g_new(float,chirp_len);
  f_input2 = g_new(float,chirp_len);
  correl = g_new(float,chirp_len);
  fft_input = g_new(complex,chirp_len);
  fft_input2 = g_new(complex,chirp_len);
  fft_correl = g_new(complex,chirp_len);

  /* generate 0 rate */
  ar_pn_generate_chirp(bpsk2, chirp_len, test_code, 0, 1.0);
  for (j=0; j<chirp_len; j++) 
    f_input2[j] = (float)bpsk2[j];
  nl_fft(f_input2, fft_input2, chirp_len);

  for (i=8192-100; i<8192+100; i++) {
    ar_pn_generate_chirp(bpsk, chirp_len, test_code, 0, 
			 i / 8192.0);

    /* convert to float */
    for (j=0; j<chirp_len; j++) 
      f_input[j] = (float)bpsk[j];

    nl_fft(f_input, fft_input, chirp_len);
    nl_fd_correl(fft_correl, correl, fft_input, fft_input2, chirp_len);

    int max_ind = 0;
    float max = 0;
    for (j=0; j<chirp_len; j++) {
      if (fabs(correl[j]) > max) {
	max = fabs(correl[j]);
	max_ind = j;
      }
    }

    int start = (max_ind + 5) % chirp_len;
    int stop = (max_ind - 5 + chirp_len) % chirp_len;
    
    float mean = 0;
    int count = 0;
    for (j=start; ; ) {
      if (fabsf(correl[j]) > 300) {
	mean += correl[j];
	count++;
      }
      j++;
      if (j == stop) break;
      if (j == chirp_len) j = 0;
    }
    mean /= (float)count;

    float variance = 0;
    count = 0;
    for (j=start; ; ) {
      if (fabsf(correl[j]) > 300) {
	variance += sqrf((correl[j] - mean));
	count++;
      }
      j++;
      if (j == stop) break;
      if (j == chirp_len) j = 0;
    }
    variance /= (float)count;
    float sigma = sqrtf(variance);

    float frac = fabs(correl[max_ind]) / sigma;
    printf ("%f\t%f\t%f\t%f\t%d\n", i / 8192.0, correl[max_ind], sigma, frac, max_ind);

    if (i == 8192) {
      fprintf(stderr, "#h correl lc\n");
      for (j=0; j<chirp_len; j++) {
	fprintf(stderr, "%f %f\n", correl[j], logf(fabsf(correl[j])));
      }
    }
  }

  return 0;
}

CENS CVS Mailing List
Powered by
ViewCVS 0.9.2