analogdevicesinc / scopy

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

Oscilloscope FFT: Erratic Behavior #1532

Open NanoExplorer opened 7 months ago

NanoExplorer commented 7 months ago

Environment:

Describe the bug When viewing the oscilloscope with FFT selected, changing the time configuration or memory depth for the oscilloscope display affects the FFT panel in strange and unexpected ways.

To Reproduce Steps to reproduce the behavior:

  1. I attached a random antenna to the oscilloscope probe via the BNC converter board. It easily picks up 60 Hz from the electricity mains.
  2. Open Oscilloscope and enable FFT in 'general settings'
  3. Set Time Base to 50 ms
  4. Click Run.
  5. 60 Hz waveform is shown on both ch1 and ch2, and both FFT channels show 60 Hz signal with harmonics at n*60 Hz. This is the expected behavior. See Fig. 1.
  6. Click + in time base selector to change base time to 100 ms. Now, FFT panel is frozen. Oscilloscope panel updates more slowly as expected, but FFT panel does not update.
  7. Change time base back to 50, then to 20, by clicking '-' twice.
  8. Now, FFT panel shows a vastly different spectrum, with peaks at 120 Hz and harmonics, with 60 Hz peaks and odd harmonics missing, even though the periodicity in the main oscilloscope panel is still showing a clear 60 hz periodicity. See Fig. 2.
  9. Change memory depth. If it is set to anything other than the lowest value, the FFT appears to only show noise. See Fig. 3

Expected behavior FFT panel should not be this dependent on probe settings. Of course there will be issues such as aliasing at extreme probe settings, but here that is not the case.

Screenshots Figure 1: 60 Hz wave with FFT showing peaks at 60 Hz and its harmonics.

image

Figure 2: 60 Hz wave with FFT showing no peaks at 60 Hz or its odd harmonics.

image

Figure 3: 60 Hz wave with high memory depth and FFT showing only noise.

image

Additional context ini file: https://gist.github.com/NanoExplorer/dfbb60c1112eb3026c9360ec92be52fb Sometimes the expected spectrum shows for a couple times after changing the time base, but it eventually goes back to the behavior I describe after a couple more changes. Or other strange things will happen, such as the primary harmonic becoming 15 Hz or 30 Hz depending on time base. Using the spectrum analyzer clearly shows no signal at these 15 Hz harmonics, but does show peaks at 60 Hz and its harmonics.

NanoExplorer commented 7 months ago

This could be the problem. In the function below, the x axis scale is only updated if the force parameter is true or the sample rate has changed. In my case I was probably triggering this function with the same sample rate and without force. https://github.com/analogdevicesinc/scopy/blob/d23b5e22fbdb5ab62e5e1aaefd90e8dcff5b9d94/src/oscilloscope.cpp#L2935-L2945

The function is probably being called from here: https://github.com/analogdevicesinc/scopy/blob/d23b5e22fbdb5ab62e5e1aaefd90e8dcff5b9d94/src/oscilloscope.cpp#L3002

I might see if I can try getting the source code to compile so I can change this and test it.