Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

SineGraph (continue) and 3D Sine

Hey, to continue my original question posted on Thursday (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 decides to graph, let's say, 10 iterations of the sine graph, how do I write the code for it?"


================
Answer by Elton Wells:


Elton Wells on 7/31/2003 answered:
"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"




==================
continuation of question


Here is what I have:
a CWGraph control on the main window dialog
a preferences dialog in which the user enters the amount of iterations
an edit box on the main window dialog that displays the amount of iterations


After the user enters in the iterations, the program should be able to display the SineGraph continuously based on the number of iterations. Each time the sine graph is drawn, the main dialog will display an edit box that shows what iteration it is on. For example, when it is on iteration 4, the sine graph should be drawing its fourth sine wave and the edit box should display the number 4. Do you know how to program this? Is there a way to graph a function then graph it again but resetting where the graph point should start at?




2nd question: in terms of 3D Graphing, how do you change the amplitude in the dual sine graph? How do you change the number of times it will appear on the 3D graph?
0 Kudos
Message 1 of 2
(2,997 Views)
To change the amplitude, do the following

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

To plot multiple iterations(for 2D plot)

for(counter=0;counter less then NUm_of_Iterations;counter++)

/*Generate your data using the Sinwave function, using the same phase variable*/
CNiMath::SineWave(data,samples,phase, amplitude,freq);

/*Using the same phase value will ensure you get a continuous sine wave*/


To plot multiple cycles, see post here

mix and match to apply to 3d graph

Hope this helps

Bilal Durrani
NI
Bilal Durrani
NI
Message 2 of 2
(2,997 Views)