00001 00004 #include <bpm/bpm_messages.h> 00005 #include <bpm/bpm_process.h> 00006 00007 int sample_to_freq( double fs, int ns, int iS, double *f ) { 00008 /* 00009 @ingroup processing 00010 00011 This routine returns the frequency corresponding to the sample number, note 00012 that this routine is not aware of the nyquist bands, and just keeps on 00013 counting from 0 -> fs. 00014 00015 @param fs sampling frequency 00016 @param ns number of samples 00017 @param iS the queried sample to get the frequency of 00018 @param f the returned frequency 00019 00020 @return BPM_SUCCESS upon success, BPM_FAILURE upon failure 00021 */ 00022 00023 if ( iS < 0. ) { 00024 *f = 0.; 00025 return BPM_SUCCESS; 00026 } 00027 00028 if ( iS >= ns ) { 00029 *f = fs; // return sampling freq 00030 return BPM_SUCCESS; 00031 } 00032 00033 *f = (double) iS / ((double)ns) * fs; 00034 00035 return BPM_SUCCESS; 00036 }