Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the equivalent of PlotY method in WPF?

Solved!
Go to solution

Hello,

I want to draw a spectrum analyzer data on a graph. My graph  XAxes contains Frequency (MHz) and YAxes contains Amplitude (dBm).

I have a data equivalent to graph resolution width approximately 1800 (data[1800]). 

Graph start from 750 MHz and end 1250 MHz. When I want to draw data it always start 0 and end 1800. How can I accomplish this task?

 

In WinForms we had a PlotY method as follows and it enables us to produce desired output. What is the equivalent method in WPF?

 

public void PlotY(double[] yData, int startIndex, int length, double start, double increment);

 I have attached  two screenshooots which represents desired and actual graph representation respectively.

I also added my code.

 

Thanks in Advance,

Hakan,

 

0 Kudos
Message 1 of 4
(3,207 Views)
Solution
Accepted by topic author yrnhkn

 

The most direct fix is to include the frequency value corresponding to each sample value within the data itself. Using your example as a baseline, you can change the ChartCollection<double> to a ChartCollection<double, double>, and update the loop as shown below:

 

double start = 750e3;
double end = 1250e3;
double increment = (end - start) / (dataLength - 1);
for( int i = 0; i < dataLength; ++i )
    data.Append( start + i * increment, rand.Next( -80, -70 ) );

A Spectrum<double> would be another way to represent this data.


You may also be interested in this answer to another question about formatting the axis labels.

~ Paul H
0 Kudos
Message 2 of 4
(3,180 Views)

Thank u very much Paul that is what i am looking for.

 

You said "Spectrum<double> would be another way to represent this data" but i do not find any documantation for Spectrum type.

Would you please provide a example for me what does same thing as ChartCollection<double, double>.

 

Another question is how National Instruments decimates the data for example my screen resolution 1400 i.e my ChartCollection<double, double>(1400) and I have a 8k data?  

 

Best Regards,

 

Hakan

 

 

 

 

 

0 Kudos
Message 3 of 4
(3,150 Views)
Solution
Accepted by topic author yrnhkn

Unfortunately, the documentation for the spectrum data type is not available online, but it is included in the installed help on your local machine.

 

Here is an example of how you can update the GenerateData method to use a spectrum instead of a chart collection:

 

private void GenerateData( ) {
    double start = 750e3;
    double end = 1250e3;
    double increment = (end - start) / (dataLength - 1);
    double[] samples = new double[dataLength];
    for( int i = 0; i < dataLength; ++i )
        samples[i] = rand.Next( -80, -70 );

    var spectrum = Spectrum<double>.FromArray1D( samples );
    spectrum.StartFrequency = start;
    spectrum.FrequencyIncrement = increment;

    graph.DataSource = spectrum;
}

Regarding decimation, regardless of the data source the graph will try to optimize the amount of data it processes, while preserving the same visual appearance.

~ Paul H
0 Kudos
Message 4 of 4
(3,141 Views)