analogdevicesinc / scopy

A software oscilloscope and signal analysis toolset
http://wiki.analog.com/scopy
GNU General Public License v3.0
379 stars 157 forks source link

Spectrum Analyzer: incorrect fundamental frequency reading #475

Open drbautista opened 5 years ago

drbautista commented 5 years ago

OS: Windows 10 64bit Scopy Version: c61d592 Firmware Version: v0.20

Steps to Reproduce:

  1. Spectrum Analyzer Setting: Sweep Setting: Start: 0Hz; Stop: 1MHz Center: 500kHz; Span: 1MHz Enable both channels.
  2. Signal Generator Setting: Channel 1: Waveform: Sinewave Amplitude: 10V; Frequency: 300kHz Phase: 0; offset: 0 Channel 2: Waveform: Sinewave Amplitude: 10V; Frequency: 750kHz Phase: 0; offset: 0
  3. Connect Scope ch1+ to AWG1; ch1- to GND
  4. Connect Scope ch2+ to AWG2; ch2- to GND
  5. Run Both instrument bug1a

With this sweep setting, the fundamental frequency readings are correct.

  1. Set Sweep setting stop: 500kHz, making the 750kHz fundamental frequency outside the Sweep setting:

bug1b

channel 2's fundamental frequency reading is now incorrect.

dNechita commented 5 years ago

You just experienced the aliasing effect. Since you told the instrument to look for signals with frequencies up to 500 kHz, the sample rate has been automatically adjusted for this range of frequency (sample rate is now half of what it was when you first set the stop frequency to 1 MHz). As a consequence the 750 kHz signal and all signals with higher frequencies than 500 kHz cannot be sampled properly thus introducing alias components. For more info lookup for aliasing and Nyquist.

rgetz commented 5 years ago

Isn't the spectrum analyzer the max sample rate so this doesn't happen?

Why does the sample rate change?

adisuciu commented 5 years ago

This is how I understand it: possible FFT bin sizes are fixed power of 2 values from 256 to 32768. In order to get as much of the signal as possible, we adjust the "oversampling_ratio" parameter to an appropriate value in order to get the samplerate at least 2x stop frequency.

If we keep samplerate at maximum value for all sweeps, we need to increase the buffer size by a lot for low stop frequencies, increasing both CPU and memory usage.

rgetz commented 5 years ago

32k is realitivily small in terms of capture - isn't it? I get that this is directly relates to bin size and screen refresh rates. But what is settjng this limit? It should be able to go much higher if we wanted to. Shouldn't it? Or is there a limit in GNU Radio I don't understand?

You are right - it would be nice if one pixel = one bin, but users can already zoom in (set start/stop very close), that this breaks. We don't need less than one pixel per bin.

What we want to do is have the sample rate as fast as possible to ensure aliasing doesn't occur, use that. What could happen is the do one FFT at max sample rate, analyze it, determine the max input frequency, and set the sample rate based on that. This doesn't need to display - only happen once every few seconds (or longer).

It's common of spectrum analyzers to sweep, to not refresh the screen every 1/30 of a second - but update 1/5 or every second depending on the settings.