Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Cycling SineGraph

Hey, to continue my original question posted today (here's the original question:

"Hey, I was wondering how do you change the amplitude and the amount of cycles in a Dual Sine Graph. The Dual Sine Graph code is:

// Graph the dual sine graph
// Declare variables and constant
const int SIZE = 41;
double xData[SIZE];
double yData[SIZE];
double zData[SIZE][SIZE];


// Use a for loop to go through each array point
// and store in a number that results from the equation
for (int i = 0; i < 41; i++)
{
xData[i] = (i - 20.0)/20.0 * PI;
yData[i] = (i - 20.0)/20.0 * PI;
}


// Use two for loops to go through each matrix point of zData
// and store in the results from an equation
for (i = 0; i < 41; i++)
{
for (int j = 0; j < 41; j++)
{

zData[j][i] = sin(xData[i])*cos(yData[j]);
}
}


// Convert the native C++ double arrays to NI data types for visualization.
CNiReal64Vector xVector(SIZE, xData);
CNiReal64Vector yVector(SIZE, yData);
CNiReal64Matrix zMatrix(SIZE, SIZE, *zData);


// Plot the data
m_c3DGraph.Plot3DSurface(xVector, yVector, zMatrix);


I am wondering in which part of the code can you change the amplitude and how do you change the amplitude. I am also wondering in which part of the graph can you change the period of the graph and the amount of cycles. For example, if the user wants the graph of amplitude 5, the period 10, and 5 iterations of the graph, how do I write that in code? Thanks."
)


================

To continue, how do I graph a continuous 2D Sine graph. I know that this code creates a regular sine graph:

// Generate the interval wave vector
CNiMath::SineWave(m_wave, 100, 1);

// Graph the first sine wave
m_cGraph.Plots.Item(1).PlotY(m_wave);

If the user decid
es to graph, let's say, 10 iterations of the sine graph, how do I write the code for it?
0 Kudos
Message 1 of 2
(2,840 Views)
Take a look at these two overloads of CNiMath::SineWave:


  • CNiMath::SineWave(CNiReal64Vector& x, unsigned int samples, double& phase, double amplitude, double freq);

  • CNiMath::SineWave(CNiReal64Vector& x, double& phase, double amplitude, double freq);



Note that these two overloads take a phase parameter by reference. This parameter specifies the initial phase at function call time and will contain the phase for the next portion of the sine wave at function return time. If you use the same double variable across multiple calls to these overloads of CNiMath::SineWave and if you don't modify the variable between calls, it should give you a continuous signal across the multiple calls.

- Elton
0 Kudos
Message 2 of 2
(2,840 Views)