Author Topic: Bode plot for scope owners that don't have the option  (Read 6437 times)

0 Members and 1 Guest are viewing this topic.

Offline TheoBTopic starter

  • Regular Contributor
  • *
  • Posts: 159
  • Country: nl
Bode plot for scope owners that don't have the option
« on: January 03, 2025, 10:23:28 pm »
This topic shows how a step response can be used to make a Bode plot. All that is needed is a signal generator, a digital scope from which you can grab data and software to post process.
The software can be downloaded from https://github.com/tband/dho-remote

The software can work with and without injection transformer to analyse loop stability.

The conventional way of creating a Bode plot is to sweep a signal generator and monitor the transfer from input to output of a network. A few hundred frequency points are generated one by one with a (sine wave) signal generator and at each point a wait time is added.  This is needed for the updated frequency to settle and for the scope to measure the amplitude and phase on at least two channels. That's slow so you want to automate it. That is what the Bode option normally takes care of.

This method uses a step response and analyzes the transfer function in the frequency domain.

I've been discussing this idea in a Rigol DHO915s thread (the model with the Bode plot option) as Rigol really did a bad job implementing the Bode option. It shows wobbly waveforms and is inaccurate. It's basically useless. But this thread is focused purely on this model and this feature, so I thought let discuss the idea with a wider audience.

A video in which I demo the program measuring a crystal:


Another video in which I show how to analyze a negative feedback loop using an injection transformer:
https://www.youtube.com/watch?v=Dlk0V3aPnzg

For other scope brands the SCPI commands probably need to be changed a bit.
The  project can be found on GitHub:
https://github.com/tband/dho-remote.

LCR example:
2477989-0
23nF parallel with 68uH

2481373-1
More challenging, a 4.0MHz crystal. A 100Hz signal is used which is 4 decades lower than the frequency measured.

Bigger goal for the Rigol hackers is to implement a Bode plot option in the scope. The software will then run on Android and controls a signal generator via a network connection (or the internal AWG if available). It can use this step response method using a square wave or the stepped sine wave for larger dynamic range. But that's just day dreaming at the moment.
« Last Edit: February 01, 2025, 09:37:40 am by TheoB »
 

Offline Someone

  • Super Contributor
  • ***
  • Posts: 5188
  • Country: au
    • send complaints here
Re: Bode plot for scope owners that do not have that option
« Reply #1 on: January 03, 2025, 10:44:13 pm »
Thinking about this, I thought it's not the most efficient way to do it like this. Why not do it for 1000 frequency points in one go? Just have a generator generate them and analyze the transfer function in the frequency domain. The input signal can be anything as long as it has frequency components at the frequency of interest.
While that does work for some cases, the dynamic range of the acquisition front end becomes limiting. The value of an oscilloscope is the front end attenuators which provide gain when needed and are exploited when stepping/sweeping through different frequencies.

There are other more general reasons why sweeps are desirable:
https://audioroundtable.com/misc/Mueller.pdf
 

Offline TheoBTopic starter

  • Regular Contributor
  • *
  • Posts: 159
  • Country: nl
Re: Bode plot for scope owners that do not have that option
« Reply #2 on: January 04, 2025, 10:07:07 am »
That's true. If you need over 100dB of dynamic range you better use a swept sine wave. But for most common scenario's an impulse response just work fine. Here I measured a ceramic resonator which resonates around 3MHz.

I have a VNA which is much more suitable to measure S21 plots. At least for frequencies above 10kHz and with 50Ohm impedance. This is a nice complement as frequency range extends to near DC and scope load is 10MOhm.
« Last Edit: January 04, 2025, 10:16:14 am by TheoB »
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5652
  • Country: gw
Re: Bode plot for scope owners that do not have that option
« Reply #3 on: January 05, 2025, 01:17:32 pm »
With the sawtooth wave generator you will get much better input spectra for your Bode analyzer.
With square wave you will get harmonics only.
Readers discretion is advised..
 

Offline TheoBTopic starter

  • Regular Contributor
  • *
  • Posts: 159
  • Country: nl
Re: Bode plot for scope owners that do not have that option
« Reply #4 on: January 05, 2025, 04:15:30 pm »
Not exactly. A sawtooth has much less harmonics. Harmonics you get from fast transitions. A sawtooth does not really have that:
I'm not sure what your definition of sawtooth is but I also show here one with a fast and slow slope:
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 21481
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Bode plot for scope owners that do not have that option
« Reply #5 on: January 05, 2025, 05:04:29 pm »
Use a noise generator as a source.

Be aware that with two or more tones any non-linearities will generate intermodulation products which will interfere with the measurements.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Online TimFox

  • Super Contributor
  • ***
  • Posts: 9123
  • Country: us
  • Retired, now restoring antique test equipment
Re: Bode plot for scope owners that do not have that option
« Reply #6 on: January 05, 2025, 05:23:17 pm »
Not exactly. A sawtooth has much less harmonics. Harmonics you get from fast transitions. A sawtooth does not really have that:
I'm not sure what your definition of sawtooth is but I also show here one with a fast and slow slope:

Fourier series analysis shows that any time-periodic waveform contains frequency components at only the fundamental frequency (equal to the repetition rate) and integer harmonics of the fundamental frequency.

The last example is what is normally called a “sawtooth”, as used for CRT horizontal deflection (sweep).
The square wave (first example) and symmetric triangle wave (second example), due to time symmetry, contain only the fundamental and odd harmonics.  The asymmetric sawtooth (third example) contains even harmonics as well.
Since the triangle wave is the time integral of the square wave, the relative amplitude of the harmonics is lower than for the square wave.
A train of very narrow pulses gives a string of harmonics that falls off slowly with frequency (“picket fence” in both time and frequency), but requires a very high dynamic range to be useful here.
« Last Edit: January 05, 2025, 05:26:03 pm by TimFox »
 
The following users thanked this post: Someone, TheoB

Online gf

  • Super Contributor
  • ***
  • Posts: 1432
  • Country: de
Re: Bode plot for scope owners that do not have that option
« Reply #7 on: January 05, 2025, 06:30:34 pm »
Not exactly. A sawtooth has much less harmonics. Harmonics you get from fast transitions. A sawtooth does not really have that:

The amplitudes of sawtooth harmonics decrease with 20dB/decade, like square wave harmonics do, but unlike a square wave spectrum, it includes even and odd harmonics, i.e. you don't get "gaps". For a given peak-to-peak amplitude, the power is a few dB lower, though. I wonder why your sawtooth spectrum has zeros at N*10kHz (i.e. already at the 100th harmonic)? An ideal sawtooth spectrum should not have them. Maybe your edge is not steep enough?
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5652
  • Country: gw
Re: Bode plot for scope owners that do not have that option
« Reply #8 on: January 05, 2025, 07:22:17 pm »
Yup, missing "odd" in my second sentence above.
The sawtooth is the right hand side picture in your sim. A steep rising or falling edge.
Readers discretion is advised..
 

Offline Fungus

  • Super Contributor
  • ***
  • Posts: 17598
  • Country: 00
Re: Bode plot for scope owners that do not have that option
« Reply #9 on: January 05, 2025, 07:40:53 pm »
A sawtooth has much less harmonics.

A sawtooth has exactly twice as many harmonics as a square wave.

You can easily see it in the images you posted.

I'm not sure what your definition of sawtooth is but I also show here one with a fast and slow slope:

The middle one is a triangle wave, the one on the right is a sawtooth.

It gets it's name from ... a saw!
« Last Edit: January 05, 2025, 07:43:41 pm by Fungus »
 

Offline TheoBTopic starter

  • Regular Contributor
  • *
  • Posts: 159
  • Country: nl
Re: Bode plot for scope owners that do not have that option
« Reply #10 on: January 05, 2025, 08:26:51 pm »
Wow. That hurts.

I meant with less harmonics, fewer harmonics useful for this application.
I entered 1% for symmetry for the sawtooth. The instrument can go to zero as well. That explains the null around the 100rd harmonic.
Sawtooth is the best option as it gives the most harmonics in the first decade. It does give less power at higher frequencies though. The square wave lacks the even harmonics and the 25% duty cycle version misses the 4th and 8th harmonic. That's a nice compromise. At the end it's easy to play with the waveforms and see which one give the best performance. In my tests I don't see much difference. There should not be a lot of phase/amplitude change in the first decade. In the first decade the resolution is rather course. For high Q applications you really need a low frequency stimulus (for a crystal I used 300Hz) to measure around 4.9MHz.
« Last Edit: January 05, 2025, 10:24:17 pm by TheoB »
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 21481
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Bode plot for scope owners that do not have that option
« Reply #11 on: January 05, 2025, 08:31:44 pm »
With a square or sawtooth or noise stimulus, how do you take account of IMD (intermodulation distortion)?

Or are you presuming the UUT is linear? No magnetics? No saturation? No semiconductors?
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Online TimFox

  • Super Contributor
  • ***
  • Posts: 9123
  • Country: us
  • Retired, now restoring antique test equipment
Re: Bode plot for scope owners that do not have that option
« Reply #12 on: January 05, 2025, 08:35:46 pm »
English grammar note:  the square wave has fewer harmonics.
 
The following users thanked this post: TheoB

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5652
  • Country: gw
Re: Bode plot for scope owners that do not have that option
« Reply #13 on: January 05, 2025, 08:49:08 pm »
For measuring the crystals 300Hz is not enough, imho. You will get a picture, but the ser/par res peaks are rather narrow, so you would need something like x Hz.
What you can do is to wobble/sweep with the fundamental of the sawtooth, for example between 300Hz and 500Hz step 5Hz and reconstruct the graph off the particular bode_sweep_freq accordingly. The same when you want to go over several decades - do sweep w/ the fundamental freq from 1kHz to 20kHz step 100Hz for example, and reconstruct the graph off the 200 bode_sweep_freq (or do the step with 1/2/5 or 1/3/10 ratio, etc).
Like (linear, a crazy example):
1.    1000Hz -> bode1
2.    1100Hz -> bode2
..
199. 19.9kHz -> bode199
200. 20.0kHz -> bode200
and get all the bodeX together into a single graph (somehow) :) ..
« Last Edit: January 05, 2025, 09:36:16 pm by iMo »
Readers discretion is advised..
 

Offline TheoBTopic starter

  • Regular Contributor
  • *
  • Posts: 159
  • Country: nl
Re: Bode plot for scope owners that do not have that option
« Reply #14 on: January 05, 2025, 09:57:57 pm »
With a square or sawtooth or noise stimulus, how do you take account of IMD (intermodulation distortion)?

Or are you presuming the UUT is linear? No magnetics? No saturation? No semiconductors?
You don't. The assumption is a linear dut. To measure the transfer of a non-linear system you need to lower the amplitude until it becomes sufficient linear again. But you better spend some money to buy a proper instrument. This idea just opens Bode diagrams for hobbyist.
 

Offline TheoBTopic starter

  • Regular Contributor
  • *
  • Posts: 159
  • Country: nl
Re: Bode plot for scope owners that do not have that option
« Reply #15 on: January 05, 2025, 10:14:15 pm »
For measuring the crystals 300Hz is not enough, imho. You will get a picture, but the ser/par res peaks are rather narrow, so you would need something like x Hz.
What you can do is to wobble/sweep with the fundamental of the sawtooth, for example between 300Hz and 500Hz step 5Hz and reconstruct the graph off the particular bode_sweep_freq accordingly. The same when you want to go over several decades - do sweep w/ the fundamental freq from 1kHz to 20kHz step 100Hz for example, and reconstruct the graph off the 200 bode_sweep_freq (or do the step with 1/2/5 or 1/3/10 ratio, etc).
Like (linear, a crazy example):
1.    1000Hz -> bode1
2.    1100Hz -> bode2
..
199. 19.9kHz -> bode199
200. 20.0kHz -> bode200
and get all the bodeX together into a single graph (somehow) :) ..
Yes, that's what I had also in mind. I made a button that grabs and stores one dataset (with two channels). Everytime the button is pressed, a dataset is added. When you push plot all datasets are reduced to one dataset. That works good for two datasets (like 100Hz and 10kHz), but for sets with more overlap I have some issues with accuracy. Work in progress.
Anyhow, I placed a first version on GitHub.
 

Online mawyatt

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: Bode plot for scope owners that do not have that option
« Reply #16 on: January 06, 2025, 02:41:19 am »
With a square or sawtooth or noise stimulus, how do you take account of IMD (intermodulation distortion)?

Or are you presuming the UUT is linear? No magnetics? No saturation? No semiconductors?
You don't. The assumption is a linear dut. To measure the transfer of a non-linear system you need to lower the amplitude until it becomes sufficient linear again. But you better spend some money to buy a proper instrument. This idea just opens Bode diagrams for hobbyist.

Some instruments have Synchronous Sampling/Detection or Frequency Selective Sampling which basically limits the measurement bandwidth around the stimulus sine-wave frequency and reduces noise and unwanted outside influences allowing low levels of sine-wave stimulus. This feature has trickled down from the Higher End Instruments to where you don't need to spend a lot to get this within the Bode Function (SDS800X HD is one example of such) :-+

Best
« Last Edit: January 06, 2025, 02:55:41 am by mawyatt »
Curiosity killed the cat, also depleted my wallet!
~Wyatt Labs by Mike~
 

Online mawyatt

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: Bode plot for scope owners that do not have that option
« Reply #17 on: January 06, 2025, 03:27:41 am »
What about a Pseudo Random Pulse Sequence as a stimulus? Should be rich in frequency content and some AWGs can produce this directly or from a file.

Best
Curiosity killed the cat, also depleted my wallet!
~Wyatt Labs by Mike~
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 21481
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Bode plot for scope owners that do not have that option
« Reply #18 on: January 06, 2025, 08:56:48 am »
What about a Pseudo Random Pulse Sequence as a stimulus? Should be rich in frequency content and some AWGs can produce this directly or from a file.

Best

It can work.

I played around with it to see if a cheap SDR dongle could be used as a poor man's 1.5GHz scalar network analyser.

The principal limitations were IMD, dynamic range limited by the total power output (not the Rx frequency), and SDR sensitivity. Unsurprisingly the dongle's frequency response was far from flat, and had to be calibrated out.

Good enough to see general filter passband shapes, with a comb filter being a useful test case.

Overall, a noise diode was better.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5652
  • Country: gw
Re: Bode plot for scope owners that do not have that option
« Reply #19 on: January 06, 2025, 09:55:47 am »
The random square sequence (and Dirac) has been briefly discussed already in the the Rigol 914S thread..
« Last Edit: January 06, 2025, 11:08:52 am by iMo »
Readers discretion is advised..
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5652
  • Country: gw
Re: Bode plot for scope owners that do not have that option
« Reply #20 on: January 06, 2025, 10:03:03 am »
..When you push plot all datasets are reduced to one dataset. That works good for two datasets (like 100Hz and 10kHz), but for sets with more overlap I have some issues with accuracy. Work in progress.
Anyhow, I placed a first version on GitHub.

The first naive approach could be - simply merge all bode points (a Bpoint is {freq, magDB, phase}) from all bode data sets into a single array/record and sort all the Bpoints based on the ascending freq, in case there are Bpoints with the same freq (it may happen) make an average of them. 
« Last Edit: January 06, 2025, 11:08:11 am by iMo »
Readers discretion is advised..
 

Offline tszaboo

  • Super Contributor
  • ***
  • Posts: 8298
  • Country: nl
  • Current job: ATEX product design
Re: Bode plot for scope owners that do not have that option
« Reply #21 on: January 06, 2025, 10:07:30 am »
Few practical things:
You don't need 1000 points for a bode plot. It's useful with as little as 10 points per decade.
Sine wave is used because systems might be non-linear, where you cannot distinguish between harmonics from your DUT or the excitation.
And you need noise filtering or averaging to get really good results. How much depends on the frequency and your test setup. Better have it configurable. I guess most of the magic in the calculations goes into this, and I don't think scopes simply read the peak to peak values and call it a day.
Also you should make something functional first before optimizing it.
 
The following users thanked this post: Fungus

Offline iMo

  • Super Contributor
  • ***
  • Posts: 5652
  • Country: gw
Re: Bode plot for scope owners that do not have that option
« Reply #22 on: January 06, 2025, 11:17:23 am »
Also a windowing function may/will play a role (and based on its type the coefficient you have to multiply the resulting magnitudes with). Also the dynamic range (with say 10bits ADC ENOB) will not be better than 60dB with this approach. So this thread is rather an interesting investigation what is feasible to do with a minimal effort (and it could be used for some less demanding measurements as for example the square wave with a variable duty, period and amplitude is easy to produce)..

As I wrote in the 914S thread the new Quality Bode should be based on the individual bode points (with the sine wave input) and an "adaptive" settings made before each bode point measurement (thus you get the best results with >120dB range, imho).
« Last Edit: January 06, 2025, 11:32:47 am by iMo »
Readers discretion is advised..
 

Online gf

  • Super Contributor
  • ***
  • Posts: 1432
  • Country: de
Re: Bode plot for scope owners that do not have that option
« Reply #23 on: January 06, 2025, 11:57:03 am »
..When you push plot all datasets are reduced to one dataset. That works good for two datasets (like 100Hz and 10kHz), but for sets with more overlap I have some issues with accuracy. Work in progress.
Anyhow, I placed a first version on GitHub.

The first naive approach could be - simply merge all bode points (a Bpoint is {freq, magDB, phase}) from all bode data sets into a single array/record and sort all the Bpoints based on the ascending freq, in case there are Bpoints with the same freq (it may happen) do an average of them.

When averaging duplicate Bode points of the same frequency, you should average the complex gain, not the magnitude/phase separately. And to ensure that noisy points due to a small stimulus amplitude don't ruin the result, I suggest calculating a weighted average (weighted by the stimulus amplitude at the particular frequency).

Another option is keeping the point with the largest stimulus amplitude if there are duplicates with the same frequency. However, this approach cannot improve the SNR, while averaging may enhance the SNR if there are multiple points with a large stimulus amplitude.

Another question is how to determine whether a particular FFT frequency point is considered a "Bode point" or not. If the stimulus is known to be a sum of sine waves (e.g., fundamental+harmonics), you could search for the peaks in the spectrum. For a stimulus with a continuous spectrum, or for a noise stimulus, this does not work, and the only way coming into my mind is to exclude FFT points with a stimulus power below a certain threshold, and treat all other FFT points as "Bode points". In this case, I would also prefer to average duplicate Bode points of the same frequency and not just keep the points with the largest stimulus amplitude, since there is a chance to encounter multiple acquisitions with a high stimulus amplitude, where averaging may enhance the SNR.
 
The following users thanked this post: TheoB

Online gf

  • Super Contributor
  • ***
  • Posts: 1432
  • Country: de
Re: Bode plot for scope owners that do not have that option
« Reply #24 on: January 06, 2025, 12:37:52 pm »
Also a windowing function may/will play a role (and based on its type the coefficient you have to multiply the resulting magnitudes with). Also the dynamic range (with say 10bits ADC ENOB) will not be better than 60dB with this approach. So this thread is rather an interesting investigation what is feasible to do with a minimal effort (and it could be used for some less demanding measurements as for example the square wave with a variable duty, period and amplitude is easy to produce)..

As I wrote in the 914S thread the new Quality Bode should be based on the individual bode points (with the sine wave input) and an "adaptive" settings made before each bode point measurement (thus you get the best results with >120dB range, imho).

A rectangular window also has an advantage: It has the lowest ENBW of all window functinos (-> best SNR). You can use a rectangular window function

1) if the stimulus is a sum of sine waves where the frequency of each sine
    wave is an exact integer multiple of the FFT bin spacing

2)  and if you do not have the requirement to filter out unwanted disturbancies
     between the stimulus frequencies with high stop band attenation, so that they
     don't leak into your measurements.

If condition (1) is not met (e.g., due to a frequency deviation between the signal generator time base and the scope time base), then spectral leakage becomes a potential problem that should be quantified for the desired frequency plan, and, if necessary, addressed by using a non-rectangular window function.

For a stimulus with continuous spectrum, or noise, I'd generally use a non-rectangular window function with high selectivity.

If you have the additional aim to filter out unwanted non-stimulus frequencies (disturbancies) with large stop band rejection, you will need a proper window function too.

In general there is always a trade-off between selectivity / stop band rejection of a window function and ENBW. There is no free lunch. You have to pay for a higher selectivity / stop band rejection / lower leakage by accepting more noise, or by using even more FFT points (-> longer measurement time).
« Last Edit: January 06, 2025, 12:46:04 pm by gf »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf