Open helioshk opened 1 year ago
It would be nice to have a better resolution than 1 dB (int) steps.
I asked chatgpt do do the modification. Not sure if it is proper, but it seems to be working and looks good. So I'll just leave it here. diff:
369,425c369,413 < if( now - last_start > settings.fft_average_seconds ) { < double hz_step = bandwidth / fft_data.size(); < double fft_hz_low = settings.center_freq - (bandwidth / 2.0); < double fft_hz_high = settings.center_freq + (bandwidth / 2.0); < double hz_low = fft_hz_low; < double hz_high = fft_hz_high; < < if( hz_low < settings.low_freq ) { < unsigned int lowsteps = std::ceil((settings.low_freq - fft_hz_low) / hz_step); < hz_low = fft_hz_low + (hz_step * lowsteps); < //std::cerr << "lowsteps: " << lowsteps << "\n"; < } < if( hz_high > settings.high_freq ) { < unsigned int highsteps = std::ceil((settings.high_freq - fft_hz_low) / hz_step); < hz_high = fft_hz_low + (hz_step * highsteps); < //std::cerr << "highsteps: " << highsteps << "\n"; < } < < // dump to output file < // create rtl_power-like header < // # date, time, Hz low, Hz high, Hz step, samples, dB, dB, dB, ... < // need only hz low and hz step < std::ofstream outfile (settings.fft_outfilename); < outfile << "date, time, " << (unsigned int)hz_low << ", " < << (unsigned int)hz_high << ", " < << hz_step << ", " < << "1"; < < size_t num_pts = fft_data_sums.size(); < // std::cerr << "processing " << num_pts << " points from " << fft_hz_low < // << " to " << fft_hz_high << std::endl; < < // uint32_t wrote = 0; < for (size_t i = 0; i < num_pts; ++i) < { < double cur_hz = fft_hz_low + (hz_step * i); < if( cur_hz >= hz_low && cur_hz <= hz_high ) { < outfile << ", " << (fft_data_sums[i] / sum_periods); < // ++wrote; < } else { < // nop < } < fft_data_sums[i] = 0; < } < outfile << std::endl; < < sum_periods = 0; < last_start = now; < < if( settings.oneshot == 1 ) { < outfile.close(); < running = false; < } < < // std::cerr << "log file updated; wrote " << wrote << " points out of " << fft_data.size() << std::endl; < < } --- > if (now - last_start > settings.fft_average_seconds) { > double hz_step = bandwidth / fft_data.size(); > double fft_hz_low = settings.center_freq - (bandwidth / 2.0); > double fft_hz_high = settings.center_freq + (bandwidth / 2.0); > double hz_low = fft_hz_low; > double hz_high = fft_hz_high; > > if (hz_low < settings.low_freq) { > unsigned int lowsteps = std::ceil((settings.low_freq - fft_hz_low) / hz_step); > hz_low = fft_hz_low + (hz_step * lowsteps); > } > if (hz_high > settings.high_freq) { > unsigned int highsteps = std::ceil((settings.high_freq - fft_hz_low) / hz_step); > hz_high = fft_hz_low + (hz_step * highsteps); > } > > // Dump to output file > // Create rtl_power-like header > // # date, time, Hz low, Hz high, Hz step, samples, dB, dB, dB, ... > // Need only hz low and hz step > std::ofstream outfile(settings.fft_outfilename); > outfile << "date, time, " << (unsigned int)hz_low << ", " > << (unsigned int)hz_high << ", " > << hz_step << ", " > << "1"; > > size_t num_pts = fft_data_sums.size(); > for (size_t i = 0; i < num_pts; ++i) { > double cur_hz = fft_hz_low + (hz_step * i); > if (cur_hz >= hz_low && cur_hz <= hz_high) { > outfile << ", " << static_cast<double>(fft_data_sums[i]) / sum_periods; > } > fft_data_sums[i] = 0; > } > outfile << std::endl; > > sum_periods = 0; > last_start = now; > > if (settings.oneshot == 1) { > outfile.close(); > running = false; > } > } >
If we do this, our output file values are no longer the same as rtl_power's format (float vs. int) and consumers of the csv file may break. Perhaps this could be made an option if there's interest.
It would be nice to have a better resolution than 1 dB (int) steps.
I asked chatgpt do do the modification. Not sure if it is proper, but it seems to be working and looks good. So I'll just leave it here. diff: