Oscilloscope bandwidth simulated with Octave/Matlab - Page 1
Forum section: electronics / general

author: ik1zyw
author_rank: Contributor
timestamp: August 31, 2021, 11:12:11 am
content: Hello.I last used MATLAB three decades ago, when I studied the signal theory. Then never used either in my work life. I do remember practicalities, but not the whole theory, so I need help. Here's what I would like to do.I have bought a declared 150 MHz bandwidth oscilloscope. I feed to it an impulse train at 14 MHz, with the impulse being (probably) 10 ns long. Given the BW limit, the oscilloscope returns just a few of the harmonics in a curvy signal that looks like the impulse train only because I know what I'm feeding to it.I would like to build a GNU Octave simulation in order to get a plot similar to the oscilloscope output, which hopefully will tell me more about the system frequency response.Here's what I would do: define the impulse train in the time domain, FFT it, apply the low pass filter (-3 dB at 150 MHz), IFFT the result back to TD and plot it. If the LPF order and -3dB point are configurable, or swept, sooner or later I should plot a waveform close enough to what is shown on the oscilloscope. Shouldn't I? And yes, I know my impulse is probably more trapezoidal than real squared, but initially I'd keep the assumption that it is ideal.If I am not too far from a useful experiment, I need to be guided towards a working  code. I hope someone is willing to help.TIA,Paolo

author: RoGeorge
author_rank: Super Contributor
timestamp: August 31, 2021, 11:46:59 am
content: Would be easier to simulated with LTspice instead of Matlab or Octave, but there's a well known relation between an analog oscilloscope bandwidth and the rise time that can be seen on the oscilloscope display.\[ BW = \frac{0.35}{t_r} \]https://people.ece.ubc.ca/robertor/Links_files/Files/TEK-Understanding-Scope-BW-tr-Fidelity.pdfThe above thumb rule formula is usually not valid for digital oscilloscopes, because the digital ones use different type of filters and signal reconstruction than analog oscilloscopes.What model is the oscilloscope you want to find the bandwidth for?

author: snarkysparky
author_rank: Frequent Contributor
timestamp: August 31, 2021, 12:25:10 pm
content: There is no concept of time in Octave/Matlab. Just samples. You do the scaling yourself.So you have a pulse train that is high 10ns at a rate of 14 Mhz. 14 Mhz has a period of 71.43 ns.For oversampling lets pick the high time to be 100 samples.high = ones(1,100);%add the off timessignal = [ high zeros(1,614)];%repeat this sequence as long as you likerepeat = 5;full_signal = repmat(signal,1,repeat);% now make a filter[b a] = butter(2,0.01);FilteredSignal = filter(b,a,full_signal);plot(FilteredSignal);

author: tggzzz
author_rank: Super Contributor
timestamp: August 31, 2021, 12:30:09 pm
content: If you want to match the response you see on the scope's screen, you will need the same "shape" filter.Traditional analogue scopes used to have an approximation to a gaussian filter in order to preserve the time-domain waveshape. Filters implemented as DSP algorithms can have any shape the implementeer desired.

author: ik1zyw
author_rank: Contributor
timestamp: August 31, 2021, 12:39:23 pm
content: Thank you for the very insightful answers tackling three different aspects of my "project". I'm really glad I am going to learn (and relearn) something new.For RoGeorge question, I want to "reverse" an Hantek DSO2D15. The unreliable analog Tek was sold to fund the purchase of the DSO. It needed some servicing that I would be qualified to apply, but it was too large to be serviced in my home lab (and I did not have the second oscilloscope required for troubleshooting). I thought I had taken a picture of the same impulse generator on the analog scope, but that requires digging in 10 years worth of digital pictures.I will read the linked Tek document later today, and play with the kindly donated code by snarkysparky. I doubt we will ever know the DSP shape chosen by Hantek engineering team.Paolo

author: RoGeorge
author_rank: Super Contributor
timestamp: August 31, 2021, 02:39:42 pm
content: DSO2D15 seems to be a digital oscilloscope with 1GSa/s, 150Mhz analog bandwidth and 2.4ns raise time according to its specs.Analog oscilloscopes use to have aGaussianresponse when looked as filters, therefore you may want to change the type of filter from Butterworth to Gaussian. I don't know what is the typical response for a digital oscilloscope, but do not expect it to match the Gaussian response of the analog oscilloscopes. In any DSO, signal reconstruction when displaying the final trace can add terrible artifacts (for example caused by sin(x)/x interpolation).If the new DSO is specified as 150MHz, than it will be indeed a 150MHz DSO. In case the signal you see looks more deteriorated than expected, than you should check:- the probe is set to 10x (a 1x probe can not be used for 10ns pulses, has small bandwidth, shows rounded edges)- the 10x probe capacitor was calibrated with the square wave test signal, see the user manual for the procedure (if not calibrated, a square waveform can show either rounded corners or edge overshooting)- the impedance of the generator and the oscilloscope match, so to avoid seeing reflections that would add up with the original signal and distort it (usually seen as 1-2 stairs levels right after a big edge in signal)Chances to match the simulation with the displayed waveform exactly are close to zero. At most it will give only a very rough approximation, not enough to get any clarification regarding the exact analog bandwidth. To be sure that the DSO is OK, much easier would be to measure the raise time.Place a picture or a screen capture with the 14MHz signal, that might help to give a verdict.Are you trying to verify the DSO specs just out of curiosity, or do you suspect the DSO is defective?

author: rstofer
author_rank: Super Contributor
timestamp: August 31, 2021, 03:14:15 pm
content: I am posting the attached FFT project, written for Octave but workable in MATLAB, not because it is direct on point but just to show how easy it is to create signals and take the FFT.

author: ik1zyw
author_rank: Contributor
timestamp: August 31, 2021, 04:36:50 pm
content: Quote from: RoGeorge on August 31, 2021, 02:39:42 pmAll checked several times every time (I only forgot the theory and math). The best probe I have is a Greenpar 10:1 <1.4ns 250 MHz, but the result doesn't change much with all other probes. I attach how the impulse looks like.I've never seen the impulse train in the time domain with enough bandwidth, only its corresponding "comb" on a spectrum analyzer up to 1 GHz, so I don't know how it should look.Quote from: RoGeorge on August 31, 2021, 02:39:42 pmThe second picture is an attempt at measuring the rise time of a 10 kHz square wave generated by the embedded function generator, that is |BX-AX|=6.4 ns. I get the same value if I measure the rise time of the calibration signal or the square wave within my comb generator (or impulse generator, made using the delay of a 74AC XOR gate). I'm sure I am forgetting something, but this isn't the right Forum section to learn how to measure the rise time.Why am I doing it? To learn, so it's mainly out of curiosity. However I do fear that 150 MHz BW for 200€ seems too good to be true, so better learn how to check it!PaoloPS: thanks to who contributed with code too!

author: tggzzz
author_rank: Super Contributor
timestamp: August 31, 2021, 05:47:38 pm
content: Quote from: ik1zyw on August 31, 2021, 04:36:50 pmWhich is an excellent reason!At these frequencies probing technique is important. The ~80MHz ringing makes me guess you are using a *10 "high" impedance probe with a 15cm ground lead. To understand why, have a look athttps://entertaininghacks.wordpress.com/2015/04/23/scope-probe-accessory-improves-signal-fidelity/https://entertaininghacks.wordpress.com/2016/09/17/scope-probe-accessory-higher-frequency-results/More probing information is in the references inhttps://entertaininghacks.wordpress.com/library-2/scope-probe-reference-material/Be sure to understand how it is possible to use probes dangerously and safely

author: RoGeorge
author_rank: Super Contributor
timestamp: August 31, 2021, 06:08:47 pm
content: If it's for learning, you may want to read around page 31/196 about measuring the raise time, and at page 35/196 about that 0.35 magic number in the bandwidth formula. The pages before the two mentioned are an interesting read, too, they tell how come that we keep talking about Gaussian response in an oscilloscope amplifier:https://www.radiomuseum.org/forumdata/users/4767/file/Tektronix_VerticalAmplifierCircuits_Part1.pdfSame document at page 29/196 shows how a Gaussian response can be achieved in practice with a reasonable good approximation (a perfect Gaussian response can not be implemented in practice, it would require infinite time, but a good enough approximation can be achieved with cascaded RC cells).To get a visual representation of how the number of the cells (the order of the filter) affects the transient response, see the attached simulation for only 4 cells similar with the ones shown at page 29/196.Blue, Yellow, Red and Green are the ideal response for a 10ns/14MHz test signal on an oscilloscope with a bandwidth of 150, 100, 50 and 25 MHz respectively.First plot, V(in), is for the square test signal, V(halfway) after 2 RC stages, and the 3rd plot is after 4 RC stages. If you want you can download the attached .asc file and run it with LTspice, or add extra cells if you want even sharper cutting frequency above the specified BW.Back to your attached waveforms, I see a lot of ringing. That's one of the reasons I am saying would be close to impossible to match the simulation with what is seen on an oscilloscope.Most of those ringings are usually not from the oscilloscope, but from the probes. To reduce them:- use only the small spring pin for prebe GND connection, not the long wire with alligator- use the tip of the probe, not the long retractable hook- calibrate the probes (on DC coupling, with the test square wave signal)- if your oscilloscope has 50 ohms input, select that (or use feedthrough 50 ohms terminators near the osc side), a plain 1x 50 ohms cable/probe, and a series 50 ohms at the generator output (for your external square wave generator, not the internal osc test signal) in order to match the impedance of the source, the cable and the oscilloscope.My guess is most of the ringing is coming from the probes (a small part of it might be from the DSP but not much).See some good practices about probing techniques from W2AEW:#206: Importance of 10X Probe Compensation with your Oscilloscope#143: Transmission Line Terminations for Digital and RF signals - Intro/Tutorial#88: Cheap and simple TDR using an oscilloscope and 74AC14 Schmitt Trigger Inverter#68: Oscilloscope Probe Ground lead length affects on signal qualityHow to make a high performance oscilloscope probe socket

author: rstofer
author_rank: Super Contributor
timestamp: September 01, 2021, 03:31:32 pm
content: Somebody has been spending a lot of quality time with LTspice! That is some very slick work.

author: tggzzz
author_rank: Super Contributor
timestamp: September 01, 2021, 03:48:27 pm
content: Quote from: RoGeorge on August 31, 2021, 06:08:47 pmAn external terminator means the termination will be 50//20pF, and that will be visible with some waveforms.Most low-end scopes with a 50ohm input merely put a 50ohm resistor in parallel with the input, which is the same as an external terminator.Only high end scopes (and the Tektronix 485) have a real 50ohm input.

author: RoGeorge
author_rank: Super Contributor
timestamp: September 01, 2021, 09:27:47 pm
content: Quote from: rstofer on September 01, 2021, 03:31:32 pmGlad you like it, thank you, though it was offtopic because OP was asking for Octave/Matlab code to FFT -> filter -> iFFT.After seeing the big oscillations from the OP screen captures, I was curious how much of it could be caused by the worst filter (worst as in the most abrupt, but not self oscillating IIR), so here's the Octave code and attached plots for a brick low pass filter.The test square signal (14MHz/10ns on) was FFT-ed first, then every spectral component above the Fcutof the presumed low pass filter was removed, then iFFT to reconstruct the display trace:Code:F_cut(1) = 150_000_000; # 150MHz MUST be declared from hightest to lowestF_cut(2) = 100_000_000; # 100MHzF_cut(3) = 50_000_000; # 50MHzL = 1000; # number of samples to considerFs = 1_000_000_000; # 1GSa/s samplingTs = 1/Fs;t = (0:L-1)*Ts;F_tst = 14_000_000; # 14 MHz square wave test signalT_tst_on = 10e-9; # 10ns square wave level high durationT_tst_all = 1/F_tst;# generate the test signal waveform Sig_tstSig_tst(1) = 0; # start from 0Vfor i = 2:L;time = (i-1)*Ts;if (mod(time, T_tst_all) <= T_tst_on)Sig_tst(i) = 4.8; # Test signal level is 4.8VelseSig_tst(i) = 0; # Test signal level is 0Vendifendfor# plot the test signal (only the first 100 samples for clarity)subplot(2, 2, 1);set(gca, 'FontSize', 20)hold onplot(1_000_000_000*t(1:100), Sig_tst(1:100), 'b', 'linewidth', 3)#plot(1_000_000_000*t, Sig_tst)title ('Test signal')xlabel('t (ns)')ylabel('Test signal (V)')# double sided FFTY = fft(Sig_tst);# plot single sided spectrumP2 = abs(Y/L);P1 = P2(1:L/2+1);P1(2:end-1) = 2*P1(2:end-1);f = Fs*(0:(L/2))/L;subplot(2, 2, 2);set(gca, 'FontSize', 20)hold onplot(f/1_000_000, P1, 'b', 'linewidth', 3)title('Single-sided spectrum of the test signal')xlabel('f (MHz)')ylabel('Spectral amplitude')# brick low pass filter F_cut(1)for bin = 1:Lif bin <= L/2F_bin = (bin-1)*Fs/L;elseF_bin = (L-bin+1)*Fs/L;endifif F_bin > F_cut(1)Y(bin) = 0;endif;endfor;# back to time domainSig_DSP = ifft(Y);subplot(2, 2, 3);set(gca, 'FontSize', 20)hold onplot(1_000_000_000*t(1:100), Sig_DSP(1:100), 'b', 'linewidth', 3) # display first 100 samples#plot(1_000_000_000*t, Sig_DSP) # display all samplestitle ('DSP out signal, F_{cut} = 150MHz')xlabel('t (ns)')ylabel('Trace signal (V)')# single sided spectrum after low passP2 = abs(Y/L);P1 = P2(1:L/2+1);P1(2:end-1) = 2*P1(2:end-1);f = Fs*(0:(L/2))/L;subplot(2, 2, 4);set(gca, 'FontSize', 20)hold onplot(f/1_000_000, P1, 'b', 'linewidth', 3)title('Single-sided spectrum after brick low pass DSP')xlabel('f (MHz)')ylabel('Spectral amplitude after DSP')# brick low pass filter F_cut(1)for bin = 1:Lif bin <= L/2F_bin = (bin-1)*Fs/L;elseF_bin = (L-bin+1)*Fs/L;endifif F_bin > F_cut(2)Y(bin) = 0;endif;endfor;# back to time domainSig_DSP = ifft(Y);subplot(2, 2, 3);plot(1_000_000_000*t(1:100), Sig_DSP(1:100), 'g', 'linewidth', 3) # display first 100 samples# single sided spectrum after low passP2 = abs(Y/L);P1 = P2(1:L/2+1);P1(2:end-1) = 2*P1(2:end-1);f = Fs*(0:(L/2))/L;subplot(2, 2, 4);plot(f/1_000_000, P1, 'g', 'linewidth', 3)# brick low pass filter F_cut(3)for bin = 1:Lif bin <= L/2F_bin = (bin-1)*Fs/L;elseF_bin = (L-bin+1)*Fs/L;endifif F_bin > F_cut(3)Y(bin) = 0;endif;endfor;# back to time domainSig_DSP = ifft(Y);subplot(2, 2, 3);plot(1_000_000_000*t(1:100), Sig_DSP(1:100), 'r', 'linewidth', 3) # display first 100 samples# single sided spectrum after low passP2 = abs(Y/L);P1 = P2(1:L/2+1);P1(2:end-1) = 2*P1(2:end-1);f = Fs*(0:(L/2))/L;subplot(2, 2, 4);plot(f/1_000_000, P1, 'r', 'linewidth', 3)legend('{\fontsize{20} BW 150MHz }', '{\fontsize{20} BW 100MHz }', '{\fontsize{20} BW 50MHz }')Note the Gibbs artifacts that only a DSP can give. For example, looking at the blue 'Trace signal (V)' right before the raising edge, there is a fake dip in the blue trace wiggling. This type of artifact is impossible to have in an analog oscilloscope/amplifier, even in an overshooting one, because the analog trace can not know when a new rising edge will come (so to wiggle down in anticipation).The LTspice simulation (of an analog oscilloscope) clearly do not show any DSP wiggling artifacts no matter the BW.Similarly, note how the green 'Trace signal (V)' in the DSP filtering have a big overshoot above the blue trace, and it is higher than the original signal of max. 4.8V. Such artifacts would be impossible to see in an analog oscilloscope. In digital oscilloscopes, turning sin(x)/x interpolation on might alleviate these kind of issues, but not remove them completely.Such an overshoot is not possible to have in an analogue oscilloscope/amplifier with Gaussian response, and the LTspice simulation indeed does not show any overshoots.One may wonder how come that a DSP might have a "premonition" and know to wiggle more right before a raising edge, can a DSP guess the future?No, it can not. It just works with batches of samples (has memory, Fourier transform can not be made sample by sample, it can only be applied on batches of signal), so the wiggle (and the edge) displayed by the trace are delayed relative to the input signal.

author: rstofer
author_rank: Super Contributor
timestamp: September 01, 2021, 11:38:32 pm
content: Converting it to MATLAB was a PITA and I lost those nice underscores in the long constants. I should have just used Octave to begin with. My bad... It's not like I don't have it on my machine.Great work! And, yes, Octave is a fantastic free tool!

author: gf
author_rank: Super Contributor
timestamp: September 02, 2021, 09:22:45 am
content: Quote from: ik1zyw on August 31, 2021, 04:36:50 pmWhat is the grund truth waveform of this "impulse train" (at least the supposed waveform)?Is it really supposed to be just a 14MHz periodic rectangle with ~14% duty cycle? Hard to believe. What is the signal source?[ OTOH, the step in the 2nd image looks at least reasonable, even if there is significant ringing. ]Why did you capture at only 250MSa/s, if the scope is capable to do 1GSa/s? Since your aim is to display signals with frequency contents >= 125 MHz, 250MSa/s is not enough and will suffer from aliasing.The internal AWG of your scope (200MSa/s DDS) is supposedly too slow as signal source in order to cover your frequency range of interest. Since 200MSa/s imply a Nyquist frequency of 100MHz, the AWG is not supposed to output significant frequency contents beyond 100MHz (the practical cut-off of the analog reconstruction filter has be be even lower).

author: ik1zyw
author_rank: Contributor
timestamp: September 02, 2021, 09:45:22 am
content: I, the OP, spent the last day reading and watching the referenced material, then trying to improve the overall response of my scope+probe.It turns out that my fastest high-impedance probe came with a BNC adapter so I could get rid of the 15 cm ground lead and repeat the rise-time experiment (still to be calculated with the freshly learned formula). The attached picture shows the result and can be compared to the one in reply #7. The edge shape doesn't change with the generator frequency (10 kHz vs 200 kHz).According to gf's reply while typing this text, I need 1) to repeat the experiment with proper sampling and 2) get a generator with a known rise time (suggestions for a DIY solution?). The impulse is generated with this circuithttps://ik1zyw.blogspot.com/2011/05/comb-generator-full-diagram.htmland the duty cycle is calculated considering average values in data sheet (rise/fall time, propagation delay). At that time I needed a wide comb and now I understand it is not the right circuit to check the performance of an oscilloscope (still I'd like to see that output!).I am glad I am not the only one learning from my own initial question, and I thank everyone who has spent precious time writing the software. I will play with it to visualise answers to other questions I have in mind, while it is clear that the simulation I was after would not match the real world system. All this while learning the important details behind a DSO, as I come from analog scopes.I won't mind if this thread continues regardless it gets away from my question. This is the Programming forum after all!Paolo

author: tggzzz
author_rank: Super Contributor
timestamp: September 02, 2021, 10:09:11 am
content: Quote from: ik1zyw on September 02, 2021, 09:45:22 amGood to see someone that listens and thinks. That's not always guaranteed!QuoteIt wouldn't. Anthropomorhic explanation: the scope and signal don't "know" when the next transition will occur. Mathematical explanation and experiment, seehttps://entertaininghacks.wordpress.com/2018/05/08/digital-signal-integrity-and-bandwidth-signals-risetime-is-important-period-is-irrelevant/Nonetheless, and importantly, the short ground lead has significantly reduced the ringing.You might also care to understand the theory and practice of "low" impedance resistive divider Z0 probes. You can make them at home, unlike conventional probes, and at 100MHz their resistance is ~7 timeshigherthan so-called high impedance *10 probes.

author: RoGeorge
author_rank: Super Contributor
timestamp: September 02, 2021, 01:16:44 pm
content: Well done, the latest waveform already looks better.For a DIY pulse generator, the one shown by w2aew is good and easy to make#88: Cheap and simple TDR using an oscilloscope and 74AC14 Schmitt Trigger Inverter, then you'll remain with a nice tool to measure cables by Time Domain Reflectometry, too.Since the generator fits on a small PCB, you can put a BNC on the same board and plug it straight into the oscilloscope's BNC connector, without any wires or probes in between. Do not use a breadboard, use a PCB clad and solder all the parts in a compact way, Manhattan/dead bug stile. Having a ground plane on the PCB is very important, too. Do not skip the Vcc decoupling capacitors either. You must have both uF range and nF range capacitors in parallel. Usually there is a 10nF, 100nF, 10uF or similar, all in parallel. Keep any connection as short as possible, and the signal edges will look even better.The frequency is not important, can be 10 kHz or 10 MHz, it doesn't matter much. What matters is how fast the edges are. The sharper the edge, the widest the generated frequency comb, though a very wide spectrum (caused when the generator gives a train of very narrow Von spikes) might confuse a digital oscilloscope if it's DSP part is not well crafted.