Hi All,
I have demodulated two AM files (I/Q) succesfully but for one of the I/Q
files which was Gnuradio (USRP) file i had to scale down I and Q components
before demodulation by multiplying by 0.0001 (experimental value) to get
the value that can be demodulated and heard on the PC speakers. The values
read from file were like these
I= 469.00000, Q=-273.0000, I=462.00000, Q=-263.0000,,,,,,,,,,
then i multiplied them by 0.0001 and then performed demodulation and result
was a success.
But for other file, the values read were like
I= -0.0014953613, Q= 0.0039367676, I=0.0018615723 ,Q = 0.0010681152
In this case no scaling of I/Q samples before demodulation was required and
AM demodulation was perfect.

My question, What is the rule of thumb for scaling values if one has to
make generic function to read and demodulate from file or live source. What
factor one can calculate to be multiplied to I/Q samples based on its
current content value. I have also noticed that whatever you multiply after
demodulation for gain (volume) will not give result if before demodulation
the I/Q values are not scaled. Any comments please.

Dani AI

Generated

Echoing 's observation about wildly different I/Q ranges and 's point about needing a baseline: a reliable approach is to detect the sample format and then normalize the complex samples to a known full-scale before any demodulation. Normalization avoids saturation or loss of resolution inside the demodulator and keeps post-demod audio gain from trying to compensate for pre-demod numeric errors.

Practical, easy rule of thumb:

  • Determine sample type from the file header if available; otherwise inspect min/max and the histogram of values to distinguish integer-like vs float-like samples.
  • Convert integers to float by dividing by their full‑scale (for example signed 16-bit use 32768.0). For float sources, compute observed peak and RMS.
  • Compute a single scaling factor for both I and Q so the complex amplitude keeps the same phase relationship. A safe target peak is about 0.8–0.95 (headroom prevents clipping).

Example normalization (conceptual C++):

float peak = 0.0f;
for (size_t i = 0; i < N; ++i) {
  peak = std::max(peak, std::fabs(I[i]));
  peak = std::max(peak, std::fabs(Q[i]));
}
float target = 0.9f;
float scale = target / (peak + 1e-12f);
for (size_t i = 0; i < N; ++i) { I[i] *= scale; Q[i] *= scale; }

Additional notes: subtract DC (mean) from I and Q before measuring amplitudes to avoid bias from offsets. For non‑stationary recordings, use a short-window or AGC instead of a single-file scale. For AM envelope detection scaling is important; for FM demod scaling mainly affects numerical precision and SNR but not carrier frequency. Finally, if post‑demod audio is too soft after correct normalization, use a controlled audio gain or limiter — but excessive post gain cannot recover samples already clipped or lost by pre-demod saturation.

You need a baseline value range to determine if scaling is necessary for your situation, and that may vary depending upon your audio gear. Just remember that data is just data - you need to determine if it makes sense in your situation. Some audio gear may deal with the scaling (down-sampling) if necessary. Others may not. You might want to look at some open source audio tools like VLC to see what they do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.