⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 win.c

📁 通过软件实现对各种指定信号的加窗处理
💻 C
字号:
#include <ansi_c.h>
#include <analysis.h>
#include <cvirte.h>		/* Needed if linking in external compiler; harmless otherwise */
#include <userint.h>
#include "Win.h"
#define PI 3.1415926

static int panelHandle;
static double *wave;
static int samples;

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, "Win.uir", PANEL)) < 0)
		return -1;
	DisplayPanel (panelHandle);
	RunUserInterface ();
	return 0;
}

int CVICALLBACK GenerateWave (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	double amp;
    double sampcyc;
    double f;
    double phase;
    double cycnum;
    
	switch (event)
		{
		case EVENT_COMMIT:
		  GetCtrlVal(panelHandle,PANEL_AMP,&amp);     
		  GetCtrlVal(panelHandle,PANEL_SAMPCYC,&sampcyc);
		  f=1.0/sampcyc;
		  GetCtrlVal(panelHandle,PANEL_CYCNUM,&cycnum);     
		  GetCtrlVal(panelHandle,PANEL_PHASE,&phase);  
		  samples=cycnum*sampcyc;
		  wave=malloc(samples*sizeof(double));
		  SineWave(samples,amp,f,&phase,wave);
		  DeleteGraphPlot(panelHandle,PANEL_GRAPH,-1,VAL_IMMEDIATE_DRAW);
		  PlotY(panelHandle,PANEL_GRAPH,wave,samples,VAL_DOUBLE,VAL_THIN_LINE,VAL_EMPTY_SQUARE,VAL_SOLID,1,VAL_RED);
		  
		  break;
		}
	return 0;
}

int CVICALLBACK AddWin (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	int wintype=0;
    int i;
    double *window;
    double *tempwave;
    
	switch (event)
		{
		case EVENT_COMMIT:
		    GetCtrlVal(panelHandle,PANEL_WINTYPE,&wintype);
		    window=malloc(samples*sizeof(double));
		    tempwave=malloc(samples*sizeof(double));
		    Copy1D(wave,samples,tempwave);
		    switch(wintype)
		      {case 0:
		             HamWin(tempwave,samples);
		             for(i=0;i<samples;i++)
		               window[i]=0.54-0.46*cos(2.0*PI*i/samples);
		             break;
		       case 1:
		             BkmanWin(tempwave,samples);
		             for(i=0;i<samples;i++)
		               window[i]=0.42-0.5*cos(2.0*PI*i/samples)+0.08*cos(4*PI*i/samples);
		       case 2:
		             TriWin(tempwave,samples);
		             for(i=0;i<samples;i++)
		               window[i]=(1.0-fabs(2.0*i-samples))/samples;
		       case 3:
		             HanWin(tempwave,samples);
		             for(i=0;i<samples;i++)
		               window[i]=0.5-0.5*cos(2.0*PI*i/samples);
		      
		     	  break;
		      }	
	        DeleteGraphPlot(panelHandle,PANEL_WINGRAPH,-1,VAL_IMMEDIATE_DRAW);
		    PlotY(panelHandle,PANEL_WINGRAPH,window,samples,VAL_DOUBLE,VAL_THIN_LINE,VAL_EMPTY_SQUARE,VAL_SOLID,1,VAL_RED);
			DeleteGraphPlot(panelHandle,PANEL_FINALGRAPH,-1,VAL_IMMEDIATE_DRAW);
		    PlotY(panelHandle,PANEL_FINALGRAPH,tempwave,samples,VAL_DOUBLE,VAL_THIN_LINE,VAL_EMPTY_SQUARE,VAL_SOLID,1,VAL_RED);
			free(window);
			free(tempwave);
			
			break;
		}
	return 0;
}

int CVICALLBACK Close (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	switch (event)
		{
		case EVENT_COMMIT:
		    free(wave);
			QuitUserInterface (0);
			break;
		}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -