Plagiate a bit: copy a graph from a data sheet

Now and then I want to look at some reference curves in data sheets or in reports or so. Sometimes, you might even want to plot the curve generated by someone else in the same graph as yours to be able to visualize and compare your data with theirs. We will show how you go from a PDF to a vector in MATLAB.

Let me describe some of the steps forward to eventually get hold of that precious data. Assume I want to look at a digital-to-analog converter from a certain vendor. For example the True 18-Bit, Voltage Output DAC ±0.5 LSB INL, ±0.5 LSB DNL”, AD5781, from Analog Devices. The data sheet is here:

On page 13 we might for example find the mid-scale error and we want to get that curve into our domain and be able to play around with it.

  1. Download the PDF to your favourite operating system (linux, which is free, …)
  2. Open it with your favourite PDF viewer (evince, which is free, …)
  3. Print the page in question to SVG format from evince.

    Screenshot-Print

  4. Open it with your favourite vector-based drawing tool (inkscape, which is free, …)

Inkscape

In inkscape, press the imported page and choose ungroup.

ink_it

Now, there will be a lot of individual lines and subgroups. Go to the graph that you are interested in and select it too. Then ungroup also that one. Dependent on how nested the figure is, continue to ungroup until you have access to that graph you are interested in. Perhaps move it to the side and double click on it and you will see that it is a spline/stroke.

ink_it2

Set the stroke-width to 1 pixel to avoid some blurred graphs later on. Select the graph in question and choose to export it to bitmap (PNG). Pick an overambitious amount of DPIs for now (you will reduce that number later down the road). Save to file.

Going MATLAB on the figure

  • Launch your favourite computing program (octave, which is free cannot be used today, as our CentOS system does not support it. Instead we will use MATLAB).

Run the command to read the file into MATLAB.


[imdata, immap, alpha] = imread('path2701.png','png');

and to look at the beauty:


imshow(imdata, immap);

Beware: the imshow and imdata and all those functions are a bit annoying…

Screenshot-Figure 1

Notice that dependent on your export options in inkscape you might get a transparent picture, something that MATLAB does not like unless you add the “alpha” to the output arguments above. Perhaps you need to run it through gimp or convert in order to remove the transparency (in gimp, remove alpha channel, for example). Otherwise, the imdata will be an all-0 matrix and show up as a big black chunk on your screen.

Then we run something cryptical and a somewhat ugly code:


imageWidth = length(imdata(1,:,1));
for x = 1:imageWidth
a(x) = mean( find( imdata(:,x,1) < 128 ) ) ;
end;
a(x) = length(imdata(:,1,1));
plot(a)

which gives us the graph (and vector) we are looking for. Notice that we are running a for loop through the x values (second dimension of the matrix). We then also have to “flip it”. Also notice that I use the mean function to average the pixels that are less than 128 (we know the picture is black-and-white) for one of the colors only. The picture does contain RGB information, though we only care about one of them in this examaple. If there are pixels scattered throughout the graph (in the Y direction) there might be some oddities coming out of this approach. A weighted mean could be used too – up to you. Since you are taking the graph from a datasheet, you cannot expect the results to be too accurate anyway.

Speaking of you, now, it is up to you to also scale it accordingly, etc., etc., such that it fits together with your data. Easy as a cake, or something.

Screenshot-Figure 1-1

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s