原创 Labwindows/cvi8.5学习日志(39)----低通滤波器

2010-7-29 10:31 4507 10 11 分类: 软件与OS

18269525-b962-4ed3-80b9-81e4b749f64e.jpg


/*****************************************************************************
// Labwindows/cvi8.5  低通滤波器 
// 改写自 Labwindows 自带的例程
// szlihongtao
// 2010-07-29
/*****************************************************************************  
#include <cvirte.h>  /* Needed if linking in external compiler; harmless otherwise */
#include <userint.h>
#include <math.h>
#include <analysis.h>
#include <ansi_c.h>
#include "sample3.h"
//*****************************************************************************
static int panelHandle;
static int typenn;
int num,status,seed;
//*****************************************************************************
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, "sample3.uir", PANEL)) < 0)
  return -1;
 DisplayPanel (panelHandle);
 RunUserInterface ();
 return 0;
}
//*****************************************************************************
int CVICALLBACK Filtertype (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 unsigned int f_disp0,f_disp1;
 
 switch (event)
 {
  case EVENT_COMMIT:
  {
       GetCtrlVal (panelHandle, PANEL_RING, &typenn); // 选择滤波器类型
      
       f_disp0=0;
       f_disp1=0;
       if (typenn==0)
       {   
        f_disp0=1;
        f_disp1=1;
       }
       else if (typenn==1)  
       {
        f_disp0=0;
        f_disp1=1;
       }  
       else ;       
         
   SetCtrlAttribute (panelHandle, PANEL_ATTENUATION, ATTR_DIMMED, f_disp0);   
   SetCtrlAttribute (panelHandle, PANEL_RIPPLE, ATTR_DIMMED, f_disp1);  
  }
 }
 return 0;
}
//*****************************************************************************
int CVICALLBACK Tuichu (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
 {
  case EVENT_COMMIT:
   QuitUserInterface (0);
   break;
 }
 return 0;
}
//*****************************************************************************
int CVICALLBACK Zhixing (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 //定义变量,分别表示滤波器纹波系数、衰减系数、截止频率,数组个数
 int order;
    double ripple,attenuation,samplefrequency,cutofffrequency;
    int n=400;
    //定义数组,x表示滤波前数组,y表示滤波后数组、datapoints表示白噪声干扰,numpoints表示正弦信号
    double x[500],y[500],datapoints[500],numpoints[500];


 switch (event)
 {
  case EVENT_COMMIT:
  {
       GetCtrlVal (panelHandle, PANEL_RING, &typenn); // 选择滤波器类型
    WhiteNoise(n,0.2,++seed,datapoints);  // 产生白噪声干扰信号
    SinePattern(n,1.0,0.0,3.0,numpoints);  // 产生正弦信号
    /*
    n=400
     3个完整的周波,每个周波占用133.33点,
     当取样频率为12KHz时候,可以理解为输入信号的频率为90Hz 
    */     


    Add1D (datapoints, numpoints, n, x); // 白噪声和正弦信号迭加
              // x表示滤波前数组
              
    DeleteGraphPlot (panelHandle, PANEL_GRAPH1, -1, VAL_DELAYED_DRAW);
    PlotY (panelHandle, PANEL_GRAPH1, x, n, VAL_DOUBLE, VAL_THIN_LINE, VAL_NO_POINT, VAL_SOLID, 1,VAL_BLACK);


             GetCtrlVal (PANEL, PANEL_RIPPLE, &ripple); //获取滤波器波纹系数  
                 
          GetCtrlVal (PANEL, PANEL_ATTENUATION, &attenuation);//获取滤波器衰减系数
             GetCtrlVal (PANEL, PANEL_ORDER, &order); //获取滤波器阶数
             GetCtrlVal (PANEL, PANEL_SAMPLEFRE, &samplefrequency);//获取采样频率 
             GetCtrlVal (PANEL, PANEL_CUTOFF, &cutofffrequency);//获取滤波器上限频率
             /*
               可以直接理解为RC滤波
             */


   if (typenn==0)
   {
    //巴特沃斯低通滤波
    Bw_LPF(x,n,samplefrequency,cutofffrequency,order,y);
   }
   if (typenn==1)
   {
    //切比雪夫低通滤波
    Ch_LPF(x,n,samplefrequency,cutofffrequency,ripple,order,y);
   }
   if (typenn==2)
   {
    //椭圆低通滤波
    Elp_LPF(x,n,samplefrequency,cutofffrequency,ripple,attenuation,order,y);
   }
   
             /*
               3dB衰减,峰值变为转换以前的0.707
             */


   DeleteGraphPlot (panelHandle, PANEL_GRAPH2, -1, VAL_DELAYED_DRAW);
   PlotY (panelHandle, PANEL_GRAPH2, y, n, VAL_DOUBLE, VAL_THIN_LINE, VAL_NO_POINT, VAL_SOLID, 1, VAL_RED);
   break;
  }
 }
 return 0;
}
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************


 

PARTNER CONTENT

文章评论1条评论)

登录后参与讨论

用户304799 2013-7-6 08:09

Labwindows/cvi8.5学习日志(39)----低通滤波器
相关推荐阅读
sz_lihongtao 2011-04-20 21:32
32bit无符号数快速开平方根
//*******************************************************************************// 32bit无符号数开平方根// ...
sz_lihongtao 2011-04-20 12:12
STM32学习日志(24)----使用dsp库的FFT函数测相位
attachment download/**  ****************************************************************************...
sz_lihongtao 2011-04-19 14:57
STM32学习日志(23)----使用dsp库的FFT函数.rar
attachment download/**  ****************************************************************************...
sz_lihongtao 2011-04-19 10:39
stm32 dsp lib V2.0
attachment downloadattachment download...
sz_lihongtao 2011-04-19 10:37
STM32学习日志(22)----使用DMA功能自动更新PWM的输出
attachment download/*******************************************************************************编...
sz_lihongtao 2010-09-08 21:59
Labwindows/cvi8.5学习日志(56)----任意波形发生器
//******************************************************************************// Labwindows/cvi8.5...
EE直播间
更多
我要评论
1
10
关闭 站长推荐上一条 /3 下一条