How to plot Y array with constant X increment

Q&A for C, C++, and/or C# developers using DPlot

Moderator: DPlotAdmin

Post Reply
rooney
Posts: 3
Joined: Thu Dec 27, 2007 11:21 am

How to plot Y array with constant X increment

Post by rooney »

I want to use DPLOT Jr to plot the values of an analog-to-digital converter (ADC).
The plot should display three curves as the the converter provides three analog channels.

The Y axis relate to the sample values of the converter. The x axis relates to the samples numbers (1, 2, 3, 4...).
A LabWindows program controls the ADC and reads blocks of 10000 samples. This blocks will be "send" to DPLOT as soon as they been read from the ADC.

For example: samples to read = 50000, block size = 10000, channels = 3
The LabWindows program reads the first block of 10000 samples of channel 1. Sends the data to DPLOT and read the next block of channel 1. The will be repeat 5 times for channel 1. Dlot should append the data always to the same curve as any data belongs to channel 1. X axis will be numberd from 1 to 50000.
Afterwards channel 2 will be read and send to DPLOT (in blocks of 10000 samples). Channel 2 should be the second curve in the same plot.
Afterwards channel 3 will be plotted the same way as channel 1 and 2.

To reduce memory requirements I don't want to create a x array holding values 1,2,3,4...
Is it possible to send Y data to DPLOT and the x axis increments automatically?
How to add data to a specific curve?+


Thanks for your help!!!!
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

From your description I think the easiest thing to do will be to call DPlot_AddData (or DPlot_AddData8), as in:

int DocNum=DPlot_Command(0,"[FileNew()]");
DPlot_AddData8(DocNum, DATA_XYXY, 10000, 1, &x[0], &y[0]);
DPlot_AddData8(DocNum, DATA_XYXY, 10000, 1, &x[10000], &y[10000]);
DPlot_AddData8(DocNum, DATA_XYXY, 10000, 1, &x[20000], &y[20000]);
DPlot_AddData8(DocNum, DATA_XYXY, 10000, 1, &x[30000], &y[30000]);
DPlot_AddData8(DocNum, DATA_XYXY, 10000, 1, &x[40000], &y[40000]);
.
.
DPlot_AddData8(DocNum, DATA_XYXY, 10000, 2, &x[0], &y[0]);

etc.
To reduce memory requirements I don't want to create a x array holding values 1,2,3,4...
Unfortunately there is no way to do this now. This will require a change to DPLOTLIB.DLL and/or to the executables. What would be nice is if the X pointer is NULL, then X values are automatically created. The only messy part about this is figuring out what should be done on subsequent calls - previous calls might have included X, for example. Perhaps the best solution is to just not worry about what has been done previously and if X is missing then assign the index of the point to X. I'll make a serious effort at adding this change to the next release (most likely available Jan 1).
Visualize Your Data
support@dplot.com
rooney
Posts: 3
Joined: Thu Dec 27, 2007 11:21 am

Post by rooney »

Thanks a lot!!!!!

If this feature would be included in the next release it would simplify some applications.
At the moment I may keep memory requirements low by reducing the block size.
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

'Tis done. Thanks for your input.
Visualize Your Data
support@dplot.com
rooney
Posts: 3
Joined: Thu Dec 27, 2007 11:21 am

It does not work

Post by rooney »

I've tested the new dll/lib and the new version of DPlot JR but some strange things are going on.

if I set x=NULL and execute the following function in my application
DPlot_AddData(DocNum, DATA_XYXY, samplesToRead, 1, &x[0], &y[0]);
the plot looks like this:
http://www.poms-engineering.at/share/new_dll_x=NULL.png

if I use x as array and fill the array
for(index = 1; index <= samplesToRead; index++)
{
x[index - 1] = (float)sensData.currentSample - sensData.firstReqSamp + index;
}
and execute DPlot_AddData(DocNum, DATA_XYXY, samplesToRead, 1, &x[0], &y[0]);
the plot looks like this:
http://www.poms-engineering.at/share/ne ... =array.png

With the older version the result looks like the plot with the new version when x=NULL


What's wrong?
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

Instead of:

DPlot_AddData(DocNum, DATA_XYXY, samplesToRead, 1, &x[0], &y[0]);

use

DPlot_AddData(DocNum, DATA_XYXY, samplesToRead, 1, NULL, &y[0]);
Visualize Your Data
support@dplot.com
User avatar
DPlotAdmin
Posts: 2312
Joined: Tue Jun 24, 2003 9:34 pm
Location: Vicksburg, Mississippi
Contact:

Post by DPlotAdmin »

I'm sorry, I should have paid more attention here. It was just dumb luck that version 2.1.5 worked for me initially. I've uploaded 2.1.5.1 just now (DPlot and DPlot Jr) and these will work as expected.

If you're a licensed user you can get version 2.1.5.1 with the Check for Updates command on the Help menu or by using the link in the last update message.
Visualize Your Data
support@dplot.com
Post Reply