/*===================================================================================== File name: filter.C (IQ version) Originator: Digital Control Systems Group Texas Instruments Description: The Voltage Reconstruction based on switching functions and DC-Bus voltage ===================================================================================== History:------------------------------------------------------------------------------------- 04-15-2005 Version 3.20-------------------------------------------------------------------------------------*/#include "IQmathLib.h" // Include header for IQmath library// Don't forget to set a proper GLOBAL_Q in "IQmathLib.h" file#include "DSP281x_Device.h"#include "filter.h"void two_order_filter_calc(TWO_ORDER_FILT_CALC *v){ v->yn = _IQmpy(v->par->x0,v->xn) + _IQmpy(v->par->x1,v->xn_1) + _IQmpy(v->par->x2,v->xn_2) + _IQmpy(v->par->y1,v->yn_1) + _IQmpy(v->par->y2,v->yn_2); v->xn_2 = v->xn_1; v->xn_1 = v->xn; v->yn_2 = v->yn_1; v->yn_1 = v->yn;}void low_bpf_calc(LOW_BPF *v){ v->yn = _IQmpy(v->xn,v->filter_t) + _IQmpy(v->yn_1,_IQ(1.0) - v->filter_t); v->yn_1 = v->yn;}
/* * filter.h * * Created on: 2014-1-21 * Author: lizhiguo */#ifndef __FILTER_H__#define __FILTER_H__typedef struct{ _iq x0; _iq x1; _iq x2; _iq y1; _iq y2;}TOW_ORDER_FILTER_PAR;typedef struct{ _iq xn; _iq yn; _iq yn_1; _iq filter_t; void (*calc)();}LOW_BPF;#define LOW_BPF_DEFAULTS {0,0,0,_IQ(1.0),(void (*)(Uint32))low_bpf_calc}typedef struct { _iq xn; _iq yn; _iq xn_1; _iq xn_2; _iq yn_1; _iq yn_2; TOW_ORDER_FILTER_PAR *par; void (*calc)(); // Pointer to calculation function }TWO_ORDER_FILT_CALC;#define TOW_ORDER_FILTER_CALC_DEFAULTS {0,0,0,0,0,0,0,(void (*)(Uint32))two_order_filter_calc}typedef TWO_ORDER_FILT_CALC *TWO_ORDER_FILT_CALC_handle;void two_order_filter_calc(TWO_ORDER_FILT_CALC_handle);void low_bpf_calc(LOW_BPF *v);#define FILTER(s,f,o) f.xn = s;f.calc(&f);o = f.yn#define FILTER_PAR(p) (TOW_ORDER_FILTER_PAR *)(&p)#endif //