#include
#include
#include /* Needed if linking in external compiler; harmless otherwise */
#include
#include "sample4.h"
static int panelHandle,i;
static double fai1,fai2,detafai;
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0) /* Needed if linking in external compiler; harmless otherwise */
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "sample4.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
return 0;
}
int CVICALLBACK AcquireData (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
double x2[200],y1[200],z[200];
double phase1,rxy,rxyy,ry,phase3,b1;
double x1[200],datapoints[200],y[200],a,b,fai,afterfilter[400];
double phase,phase2,sigmaf,sigmaa,phase4;
int n=200,i;
//原始信号的相位
phase=30;
//标准信号的相位
phase2=0;
phase3=90;
switch (event)
{
case EVENT_COMMIT:
//无噪声的正弦信号
SineWave (n, 5.0, 0.01, &phase, x1);
//显示理想幅值
SetCtrlVal (panelHandle, PANEL_AVALUE, 5.0);
//显示理想相位
SetCtrlVal (panelHandle, PANEL_PHASE, 30.0);
//白噪声信号
WhiteNoise(n,1.0,1,x2);
// 产生两个标准信号
SineWave (n, 3.0, 0.01, &phase2,y);
SineWave (n, 3.0, 0.01, &phase3, y1);
//产生带有噪声的信号
Add1D (x1, x2, n, datapoints);
//图形显示原始波形
DeleteGraphPlot (panelHandle, PANEL_WAVEFORM, -1, VAL_IMMEDIATE_DRAW);
PlotY (panelHandle, PANEL_WAVEFORM, datapoints, n, VAL_DOUBLE,
VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLACK);
//自相关运算
Correlate(datapoints,n,datapoints,n,afterfilter);
for (i=0; i {
afterfilter[i]= afterfilter[i]/n;
}
//显示经过自相关处理之后的波形
DeleteGraphPlot (panelHandle, PANEL_WAVEFORM2, -1, VAL_IMMEDIATE_DRAW);
PlotY (panelHandle, PANEL_WAVEFORM2, afterfilter, n, VAL_DOUBLE,
VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLACK);
//按照前面介绍的方法求取信号的幅值和相位
Mul1D (datapoints, y, n, z);
Sum1D (z, n, &rxy);
rxy=rxy/n;
Clear1D (z, n);
Mul1D (datapoints, y1, n, z);
Sum1D (z, n, &rxyy);
rxyy=rxyy/n;
Clear1D (z, n);
Mul1D (y, y, n, z);
Sum1D (z, n, &ry);
ry=ry/n;
b=sqrt(2*ry);
fai=atan(rxyy/rxy);
fai1=fai*180/3.1415926;
a=2*rxy/(b*cos(fai));
SetCtrlVal (panelHandle, PANEL_AMEASURE, a);
SetCtrlVal (panelHandle, PANEL_FAIVALUE, fai1);
break;
case EVENT_RIGHT_CLICK:
break;
}
return 0;
}
int CVICALLBACK Quit (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface(0);
break;
case EVENT_RIGHT_CLICK:
break;
}
return 0;
}