Discussion board help and admin topics > Problems and Solutions for Accurate Measurements

Measuring power with analog oscilloscope

(1/4) > >>

My analog oscilloscope cannot multiply channels, as cannot most other analog oscilloscopes. If it could, then painting the areas under the curves and then counting pixels, were an option. Which is good in that it needs no special software, as ImageMagick can do that. When the channels cannot be multiplied, it is possible to do the same and count pixels in every column for both channels, but this needs writing a special software, and it is not very easy and reliable.

So i use gschem and a script, to calculate power. gschem is what i used to use for drawing circuit diagrams, also for ngspice simulations, but it is a very simple vector graphics editor, with very simple file format. This is the sch file to draw the oscilloscope traces.

--- Quote ---v 20130925 2
L 16503 20501 21503 20501 3 0 0 2 100 100
L 19000 22500 19000 18500 3 0 0 2 100 100
L 16503 16001 21503 16001 3 0 0 2 100 100
L 19000 18000 19000 14000 3 0 0 2 100 100
--- End quote ---

What follows is a simple example. The last two images are the traces of the first and second channels drawn with gschem. I drew them simply by hand based on the traces on the oscilloscope screen. It has to snap to grid, because the lines have to be joined, but for more precision the grid can be scaled down. The traces have to begin exactly at the beginning of the x axis, and end at the same x exactly at the end of the cycle, the calculation ends when the lines end for both channels. The images are simply screenshots taken from the gschem window with gimp, by selecying a region to grab.

Power is still V * I, even if the current is alternating. It is V * I at any moment, what we need is the average power. This is the python script to calculate the power.

--- Quote ---import sys

XLEFT = 16503
XRIGHT = 21503
Y1TOP = 22500
Y1BOTTOM = 18500
Y2BOTTOM = 14000

if (len(sys.argv) < 2):
   print ("\nUsage: power.py sch_file\n")
f = open(sys.argv[1], "r")
lines = []
for s in f:
   l = []
   i1 = -1
   if (s[0] != "L"): continue
   for j in range(0, 5):
      if (i1 == len(s)): break
      i0 = i1 + 1
      i1 = i0 + s[i0:].find(" ")
      if (s[i0:].find(" ") == -1): i1 = len(s)
      if (j and s[i0:i1].isdigit()): l.append(int(s[i0:i1]))
   lines.append([l[0], l[1], l[2], l[3]])
del lines[lines.index([16503, 20501, 21503, 20501])]
del lines[lines.index([19000, 22500, 19000, 18500])]
del lines[lines.index([16503, 16001, 21503, 16001])]
del lines[lines.index([19000, 18000, 19000, 14000])]
print ("\nChannel 1 scale (mV)?")
scale1 = int(sys.stdin.readline()) / 1000. / 500.
print ("Channel 2 scale (mV)?")
scale2 = int(sys.stdin.readline()) / 1000. / 500.
print ("Resistance (ohms)?")
r = float(sys.stdin.readline())
if (not r): r = 1e-3
power = 0.
half = (Y1TOP - Y1BOTTOM) / 2
for i in range(XLEFT, XRIGHT + 1, 10):
   current = voltage = y = 0.
   for j in range(0, len(lines)):
      if (i < lines[j][0] or i >= lines[j][2]): continue
      y = float(i - lines[j][0]) / (lines[j][2] - lines[j][0]) * \
         (lines[j][3] - lines[j][1]) + lines[j][1]
      if (lines[j][1] >= Y1BOTTOM):
         voltage = (y - Y1BOTTOM - half) * scale1
         current = (y - Y2BOTTOM - half) * scale2 / r
   if (y < Y2BOTTOM): break
   power += current * voltage
power = abs(power / (XRIGHT - XLEFT) * 10)
if (power < 1e-3):
   print ("Power was %.4f uW\n" % (power * 1e6))
elif (power < 1):
   print ("Power was %.4f mW\n" % (power * 1e3))
   print ("Power was %.4f W\n" % power)
--- End quote ---

And this was the result.

--- Quote ---Channel 1 scale (mV)?
Channel 2 scale (mV)?
Resistance (ohms)?
Power was 12.4585 mW
--- End quote ---

To somehow estimate the result, try to calculate the power assuming that both traces were sines, using the conventional way to calculate AC power.

Voltage amplitude was 2.2 * 10 = 22 V and current amplitude was 2.6 * 2 / 977 = 0.00532 A . Voltage root mean square was 22 / sqrt(2) = 15.556 V and current root mean square was .00532 / sqrt(2) = 0.00376 A .

If the current trace were sine, i estimate that the current did then cross 0 risingly approximately at 2.1 scales before the voltage, which is 0.84 times 2.5, which means that phi should be approximately 0.84 * 90 = 76 degrees.

Thus by the conventional calculation, the power was

15.556 * 0.00376 * cos(76) = 0.01415 W = 14.15 mW

This somewhat differs from the result calculated by the scipt, 12.46 mW, but this approximation is very rough and cannot give very precise results. But the result was a similar number, which shows that calculating power in that way works. This may not be the best way to measure power, but when there is no other way, at least it is possible to calculate power. It is some work of course, but it's not very difficult and doesn't take a very long time.

Hope it was useful for someone for some purpose.

Use this analog multiplier to multiply the i&v channels if your scope cannot.


--- Quote from: verpies on October 10, 2016, 11:51:34 PM ---Use this analog multiplier to multiply the i&v channels if your scope cannot.

--- End quote ---

Right, one has to buy it then. Or i'm pretty sure that one can make ones own analog multiplier, but it takes some time and effort. And what one gets is not that good, this painting job may not be easy. One may well end up drawing it all over by hand, not much better than drawing it in gschem. Too much is necessary, compared to the method that i described, that one can use right away. gschem is free and open source, if some didn't know, and i think some other vector graphics editors for circuit simulation are pretty similar, no matter what one uses. Or some other vector graphics editors may also write very simple files. Found no reason to try them though, as i use gschem anyway.

I use Linux with KDE desktop. I can configure KDE to change transparency (opacity) of a window, with alt + mouse wheel. I open the drawing of the traces in gschem, then the oscilloscope screen image in gimp. I put the gimp and gschem windows one on another, and change the transparency of either the gimp window or the gschem window. Then i can zoom in the graph in gschem, scale the image in gimp to its size, and move the gschem window, so that the graph exactly matches the screen image in gimp. Then i can draw the trace in gschem with short lines, on the oscilloscope screen image in gimp, this can be done pretty fast.

This is when you don't want to draw the lines just visually, either from the oscilloscope screen image or directly from the oscilloscope screen. This is what i did in the example above. And it may be the fastest way of doing it, after you get some experience, if you only want a rough estimation of power.

Any chance you post (in spare time) video explaining this process in details ? How do you snapshot analog scope screen ? Is the resolution important ? Video explanation would be useful especially for people with basic English.


[0] Message Index

[#] Next page

Go to full version