// file: csnr_cal_11.cc // // this function computes the histogram of the energy of the signal // // system include file // #include // local include file // #include "global_constants.h" #include "calculate_snr_constants.h" #include "calculate_snr.h" // function: calculate_hist_cc // // arguments: // float**& bin_avgs_a: (output) midpoint of each bin // int**& bin_freqs_a: (output) count of each bin // float** energy_buffer_a: (input) buffer containing the energy of // each frame // int num_energy_vals_a: (input) number of energy points in // the buffer // int num_chans_a: (input) number of channels // int debug_mode_a: (input) debug mode // // return: an int to indicate status // // this function calculates the histogram of the energy of a signal // // int calculate_hist_cc (float**& bin_avgs_a, int**& bin_freqs_a, float** energy_buffer_a, int num_energy_vals_a, int num_chans_a, int debug_mode_a) { // determine the width of the bin // float* max_value = new float[num_chans_a]; float* min_value = new float[num_chans_a]; float* bin_width = new float[num_chans_a]; for (int j = 0; j < num_chans_a; j++) { max_value[j] = calculate_max_cc(energy_buffer_a[j], num_energy_vals_a); min_value[j] = calculate_min_cc(energy_buffer_a[j], num_energy_vals_a); bin_width[j] = (max_value[j] - min_value[j]) / CSNR_NUM_BINS; } // initialize the bins // for (int j = 0; j < num_chans_a; j++) { for (int i = 0; i < CSNR_NUM_BINS; i++) { bin_freqs_a[j][i] = 0; bin_avgs_a[j][i] = 0; } } // determine what goes to which bin // for (int j = 0; j < num_chans_a; j++) { for (int i = 0; i < num_energy_vals_a; i++) { // limit the data // float num = energy_buffer_a[j][i]; if (num < min_value[j]) { num = min_value[j]; } else if (num > max_value[j]) { num = max_value[j]; } // calculate which bin the data should go and increment the count // int index = (int)rint((num - min_value[j]) / bin_width[j]); bin_freqs_a[j][index]++; bin_avgs_a[j][index] += num; } } for (int j = 0; j < num_chans_a; j++) { for (int i = 0; i < CSNR_NUM_BINS; i++) { if (bin_freqs_a[j][i] == 0) { bin_avgs_a[j][i] = bin_width[j] * i - bin_width[j] / 2; } else { bin_avgs_a[j][i] /= bin_freqs_a[j][i]; } } } if (debug_mode_a > DEBUG_BRIEF) { for (int j = 0; j < num_chans_a; j++) { for (int i = 0; i < CSNR_NUM_BINS; i++) { fprintf(stdout, "chan %d :: bin [%d] :: freq = %d value = %.2f\n", j, i, bin_freqs_a[j][i], bin_avgs_a[j][i]); } } } // delete memory // if (max_value != (float*)NULL) { delete [] max_value; max_value = (float*)NULL; } if (min_value != (float*)NULL) { delete [] min_value; min_value = (float*)NULL; } if (bin_width != (float*)NULL) { delete [] bin_width; bin_width = (float*)NULL; } // exit gracefully // return TRUE; }