Skip to content
Snippets Groups Projects
Commit d584672b authored by Ewan Barr's avatar Ewan Barr
Browse files

added output level scaling

parent 8420fb98
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,7 @@ public:
std::size_t naccumulate,
std::size_t nbits,
float input_level,
float output_level,
HandlerType& handler);
~FftSpectrometer();
......@@ -62,7 +63,6 @@ private:
std::size_t _fft_length;
std::size_t _naccumulate;
std::size_t _nbits;
float _input_level;
HandlerType& _handler;
cufftHandle _fft_plan;
int _nchans;
......
......@@ -15,12 +15,12 @@ FftSpectrometer<HandlerType>::FftSpectrometer(
std::size_t naccumulate,
std::size_t nbits,
float input_level,
float output_level,
HandlerType& handler)
: _buffer_bytes(buffer_bytes)
, _fft_length(fft_length)
, _naccumulate(naccumulate)
, _nbits(nbits)
, _input_level(input_level)
, _handler(handler)
, _fft_plan(0)
, _call_count(0)
......@@ -38,9 +38,9 @@ FftSpectrometer<HandlerType>::FftSpectrometer(
int batch = nsamps_per_buffer/_fft_length;
BOOST_LOG_TRIVIAL(debug) << "Calculating scales and offsets";
float dof = 2 * _naccumulate;
float scale = std::pow(_input_level * std::sqrt(static_cast<float>(_nchans)), 2);
float scale = std::pow(input_level * std::sqrt(static_cast<float>(_nchans)), 2);
float offset = scale * dof;
float scaling = scale * std::sqrt(2 * dof);
float scaling = scale * std::sqrt(2 * dof) / output_level;
BOOST_LOG_TRIVIAL(debug) << "Correction factors for 8-bit conversion: offset = " << offset << ", scaling = " << scaling;
BOOST_LOG_TRIVIAL(debug) << "Generating FFT plan";
int n[] = {static_cast<int>(_fft_length)};
......
......@@ -30,6 +30,7 @@ int main(int argc, char** argv)
int naccumulate;
int nbits;
float input_level;
float output_level;
std::time_t now = std::time(NULL);
std::tm * ptm = std::localtime(&now);
char buffer[32];
......@@ -63,6 +64,9 @@ int main(int argc, char** argv)
("input_level", po::value<float>(&input_level)->required(),
"The input power level (standard deviation, used for 8-bit conversion)")
("output_level", po::value<float>(&output_level)->required(),
"The output power level (standard deviation, used for 8-bit conversion)")
("outfile,o", po::value<std::string>(&filename)
->default_value(filename),
"The output file to write spectra to")
......@@ -101,7 +105,7 @@ int main(int argc, char** argv)
std::size_t buffer_bytes = client.data_buffer_size();
SimpleFileWriter sink(filename);
//NullSink sink;
effelsberg::edd::FftSpectrometer<decltype(sink)> spectrometer(buffer_bytes, fft_length, naccumulate, nbits, input_level, sink);
effelsberg::edd::FftSpectrometer<decltype(sink)> spectrometer(buffer_bytes, fft_length, naccumulate, nbits, input_level, output_level, sink);
DadaInputStream<decltype(spectrometer)> istream(input_key, log, spectrometer);
istream.start();
/**
......
......@@ -42,7 +42,7 @@ void FftSpectrometerTester::performance_test(
std::vector<char> header_block(4096);
RawBytes header_raw_bytes(header_block.data(), 4096, 4096);
NullSink null_sink;
FftSpectrometer<NullSink> spectrometer(input_block_bytes, fft_length, tscrunch, nbits, 16.0f, null_sink);
FftSpectrometer<NullSink> spectrometer(input_block_bytes, fft_length, tscrunch, nbits, 16.0f, 16.0f, null_sink);
spectrometer.init(header_raw_bytes);
for (int ii = 0; ii < 100; ++ii)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment