java对PPG的基线漂移的一种处理办法(中值滤波)

传进去所有采集的离散点 

//滑动均值滤波器
    public static List<Double> getAverageValue(List<Double> list){

        double[]start=getList(list);
        MovingAverageFilter maf=new MovingAverageFilter();
        double[] result=maf.movingAverageFilter(start);
        List<Double> fflist=getArray(result);
        List<Double> listH=getDifferenceValuetwo(list,fflist);
        return listH;
    }

 创建滤波器

/**
 * @authorseerhuitao 滑动滤波器
 * @create2018/6/13
 */
/*
 * 功能 对音频数据进行滑动滤波,使其更好的识别  时间:2015/9/11
 */
public class MovingAverageFilter  {
    private  double[] mBufout = null;
    private final int mWindowSize = 10;
    // 移动均值滤波,原始数组最后的mwindowSize-1 个元素没有处理。
    public double[] movingAverageFilter(double[] buf) {

        double[] winArray = new double[mWindowSize];

        mBufout = new double[buf.length];
        int OIndex = 0;

        System.arraycopy(buf, 0, mBufout, 0,
                buf.length);

        for (int i = 0; i < buf.length; i++) {

            int wIndex = 0;


            if ((i + mWindowSize) > buf.length) break;

            for (int j = i; j < (mWindowSize + i); j++) {
                winArray[wIndex] = buf[j];
                wIndex ++;
            }

            mBufout[OIndex] = mean(winArray);
            OIndex ++;

        }

        return mBufout;

    }
    public static double mean(double[] array) {
        long sum = 0;
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        return (double) (sum / array.length);
    }
}
public static List<Double> getArray(double[] d){
        List<Double> list=new ArrayList<>();
        for(int i=0;i<d.length;i++){
            list.add(d[i]);
        }
        return list;
    }
//对数据里面的差值进行减法运算,处理尖刺
    public static List<Double> getDifferenceValuetwo(List<Double> filter,List<Double> filter2){

        List<Double> filterH=new ArrayList<>();
        for(int j=0;j<filter.size();j++)
        {
            double h=filter.get(j)-filter2.get(j);
            if(h<4000&&h>-4000){
                filterH.add(h);
            }
        }
        return filterH;
    }

 

参考资料:http://www.doc88.com/p-2095619270288.html

参考资料:http://www.docin.com/p-788823382.html

展开阅读全文

没有更多推荐了,返回首页