// file: $SPEECH_HOMEWORK4/hw4/class/snr_ratio/v1.0/snr_cal_4.cc // // isip include files // #include "signal_noise_ratio.h" #include "signal_noise_ratio_constants.h" #include // method: calculate_snr_cc // // arguments: // float_4** cdf (input) the cdf of the channels // float_4** energy (input) the energy of the channels // int_4 num_energy (input) the number of energy // float_4* max (input) the maximum energy for each channel // float_4* min (input) the minimum energy for each channel // float_4* mean (input) the mean energy for each channel // float_4 snr (output) the snr for each channel // // return: a logical_1 indicating status // logical_1 Signal::calculate_snr_cc(int_4** cdf_a, float_4** energy_a, int_4 num_energy_a, float_4* max_a, float_4* min_a, float_4** mean_a, float_4* snr_a) { // check arguments // if (snr_a == (float_4*)NULL) { error_handler_cc((char_1*)"calculate_snr_cc", (char_1*)"output memory is not allocated"); } // calculate the bin number of the signal and noise using the // thresholds // int_4 sbin = (int_4) (signal_threshold_d * num_energy_a); int_4 nbin = (int_4) (noise_threshold_d * num_energy_a); // loop over all channels // for (int_4 channel=0;channel < num_chans_d; channel++) { // find the noise energy using the noise threshold // float_4 noise = min_a[channel]; int_4 index = cdf_a[0][channel]; int_4 bin = 0; while (index < nbin) index = cdf_a[++bin][channel]; // retrieve the mean energy as the noise // noise = mean_a[bin][channel]; // now it's time to find the signal energy // float_4 signal = min_a[channel]; while (index < sbin) index = cdf_a[++bin][channel]; // retrieve the mean energy as the noise // signal = mean_a[bin][channel]; // calculate the SNR // snr_a[channel] = (float_4) (10 * log10((signal-noise) / noise)); } // exit gracefully // return ISIP_TRUE; }