01-25-2018 01:19 AM
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,
Solved! Go to Solution.
01-25-2018 10:55 AM
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.
01-30-2018 11:25 PM
Thank u very much Paul that is what i am looking for.
You said "A 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
01-31-2018 09:42 AM
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.