Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

glitchy waveform graph with two plots

hi again,

I am having a pretty significant problem right now... here's the situation:  I am trying to plot two binary graphs on a waveform graph... one plot is white (for good data) and one plot is red (for bad data).  Both plots are used to graph the same data because there isn't a line that can change colors, so i need to create one.  My solution was to have two plots and while plotting white data (good data), plot NaN's for the red plot... and while plot red data (bad data), plot NaN's for the white plot. 

But, here's my problem.  im graphing chunks at a time:  first binary chunk of good data, first binary chunk of bad data, second binary chunk of good data, second binary chunk of bad data.... all the way to the end of the data.  it seems that i am getting a blank spot at the end of each chunk (see attached picture) and there is a gap between every red/white transition.  Is there anyting to fix this?


Thank you so much!



edit:  for the attached graph, the data is supposed to be: 

white: 010101010 (last 0 is a blank)
red: 000000000 (the last 0 is a blank)
white: 01 (the 1's horizontal is not graphed... it's a blank)
red:  00 (last 0 is a blank)
white: 1001 (last 1 is blanked)
red: 0011 (last 1 is blanked)

so on and so forth...

Message Edited by njuneardave on 10-19-2007 09:08 AM

0 Kudos
Message 1 of 10
(4,897 Views)
just updating this.  i still don't know of an answer to my problems.  any help?


thanks.
0 Kudos
Message 2 of 10
(4,862 Views)
Hi njuneardave,

So far I have been unable to reproduce the behavior that you have been seing. Can you post a small code snippet that I can run to show me the behavior? Of course, I am using Measurement Studio 8.1.1 and so maybe we fixed a bug that prevents me from seeing the behavior. Providing me with an example will help me determine the issue faster.

Thanks

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 3 of 10
(4,852 Views)
sure.  it's a little convoluted, but i will try to explain it.


            // basebandBits is my string of 1's and 0's.
            // flagArray is the exact same length as basebandBits.  if i want to graph the bit as white (i.e. no error), flagArray[index] = 0.  if the bit is to be graphed
            // in red, flagArray[index] = 1.  my algorithm was to find groups of same color and graph the group.... meaning, if i find a white, graph as many whites as possible
            // for efficiency reasons. 
            int index = 0;
            // loop through the string of 1's and 0's
            while (index < basebandBits.Length)
            {
                // these lists hold the info to be graphed.
                ArrayList goodIndices = new ArrayList();
                ArrayList badIndices = new ArrayList();

                // while the flagArray[index] value is zero (i.e. no error, therefore, white graph)
                while (flagArray[index] == 0)
                {
                    // add the actual value to be graphed (either a 1 or 0) to goodIndices.  cast it as double per
                    // PlotYAppend param reqs.
                    goodIndices.Add(Convert.ToInt32(basebandBits.Substring(index,1)));
                    // add a NaN to the badIndices array so that the graph is effectively blanked out over this index.
                    badIndices.Add(Double.NaN);
                   // determine if the next index is out of range (longer than baseband string)
                    if (index + 1 < basebandBits.Length)
                    {
                        // if not, increase the index and grab the next bit in the array.
                        index++;
                    }
                    else
                    {
                        index++;
                        break;
                    }
                }
                // these double arrays will be filled with the values populated in the ArrayLists.
                // PlotYAppend will plot these arrays.
                double[] goodDataToPlot =new double[goodIndices.Count];
                double[] badDataNans = new double[badIndices.Count];
                for (int x = 0; x < goodIndices.Count; x++)
                {
                    goodDataToPlot[x] = Convert.ToInt32(goodIndices[x]);
                    badDataNans[x] = Double.NaN;
                }

                // plot.
                signalPlotGood.PlotYAppend(goodDataToPlot);
                signalPlotBad.PlotYAppend(badDataNans);                                                                                                               

                // clear the ArrayLists.
                goodIndices.Clear();
                badIndices.Clear();


0 Kudos
Message 4 of 10
(4,851 Views)
(continued...)



                // now, you have plotted as many non-error bits as possible and you have run into
                // at least one error bit.  find all the consecutive error bits and plot them.
                while (flagArray[index] == 1)
                {
                    // add the actual bit value of the error bits to badIndices (red graph)
                    badIndices.Add(Convert.ToInt32(basebandBits.Substring(index,1)));
                   // add a NaN to blank out the white graph.
                    goodIndices.Add(Double.NaN);
                    if (index + 1 < basebandBits.Length)
                    {
                        index++;
                    }
                    else
                    {
                        index++;
                        break;
                    }
                }

                // same process as above.  convert the arraylist to a double[] to plot
                double[] goodDataNans =new double[goodIndices.Count];
                double[] badDataToPlot = new double[badIndices.Count];
                for (int x = 0; x < badIndices.Count; x++)
                {       
                    badDataToPlot[x] = Convert.ToInt32(badIndices[x]);
                    goodDataNans[x] = Double.NaN;
                }
                // plot
                signalPlotGood.PlotYAppend(goodDataNans);
                signalPlotBad.PlotYAppend(badDataToPlot);

                goodIndices.Clear();
                badIndices.Clear();
            }


if you have any questions about the code, feel free to ask me.  again, the bits are correctly plotted, but the last bit of each array is simply left ungraphed.  i am using a waveform graph with linestep set as "XYStep."  Version 8.1.1.  I originally made this graph with version 7, and i didnt want to rewrite old code or have to replace the graph with a digital graph.
0 Kudos
Message 5 of 10
(4,848 Views)
Hi njuneardave!

I think that you are seeing expected behavior.  When the graph plots these points, it only plots single points.  Thus when you tell the graph to plot 01, for example, at x value 0, a single point at 0 will be plotted, and at x value 1, a single point at 1 will be plotted.  These points are then connected by lines.  Because the plot is not defined for x = 2, there is no completion of the line from 1 to 2. 

I think that there may be a better solution to your issue, by using one plot.  If you plot the first data set, and then use the plotyappend method to append the second data set, you can plot your two data sets only using one plot.  Then, before you call the plotyappend method, you can create a new Pen object, and change the color of the Pen to go from white to red, and vice-versa.  For an example of how to create this new Pen object and use it, see the example located at:

<National Instruments>\MeasurementStudioVS2005( or 2003 )\DotNET\Examples\UI\WindowsForms\ComplexGraph\CustomPlotDrawing

I hope this helps!

NickB
0 Kudos
Message 6 of 10
(4,844 Views)
Nick,

Thanks for the advice, but i'm somewhat worried about efficiency.  I will be plotting several signals (on multiple instances of waveform graphs) of 2000+ bits.  would it just be quicker to use PlotYAppend and physically draw lines up, down, and left?
0 Kudos
Message 7 of 10
(4,834 Views)
njuneardave,

I think that you should be able to use the same code architecture that you are currently using.  You will just have one array that contains all your data points. Whether your data points are to be graphed as good or bad data is determined by looking at the corresponding flagarray index.  You will have the one large outer while loop that checks that you are still within the bounds of your array, and then two inner while loops checking the value of the flagarray index, like you are currently doing.  If the index is 0, then graph the data using plotyappend, but make sure that your pen color is white.  Then when the flagarray index changes to 1, you can jump down into the second while loop that again just plots the data using plotyappend, but changes the pen color to red.  Let me know if you have any questions!

NickB
0 Kudos
Message 8 of 10
(4,825 Views)

Nick,

 

Thanks for the help, I really appreciate it.  So basically, I can just do this:

 

(when data is good.  data is the double[] of binary to plot... i.e. [0, 1, 1, 0, 0, 1, 0])

Graphics graphics = e.Graphics;
Pen pen = new Pen(Color.White);

PlotYAppend(data);

(when data is bad)

Graphics graphics = e.Graphics;
Pen pen = new Pen(Color.Red);

PlotYAppend(data);

 

will this affect any zooming or panning capabilities?  I won't be able to try this until tomorrow, so I figure I should utilize this time to better understand it.

 

 

thanks again for all of your helpfulness.

Message Edited by njuneardave on 10-23-2007 01:27 PM

0 Kudos
Message 9 of 10
(4,812 Views)
njuneardave,

It turned out to be a little more complicated than that, so I went ahead and wrote up a little example that I think accomplishes what you're looking for.  It doesn't necessarily implement the best programming practice... but I think it displays the functionality you should need.  Let me know if you have any questions about it!

NickB
0 Kudos
Message 10 of 10
(4,797 Views)