Code Composer Studio中的中值过滤器

时间:2017-10-10 05:39:22

标签: c

我正在尝试为1D信号编写中值滤波器,但我无法将Code Composer Studio的输出与Matlab相同。请告诉我我的错误在哪里。

#include<stdio>
#include<math.h>
#include<signal.h>

void medianfilter(short*signal, int signalLength, short* output, int windowSize)
{
    int i,j,k;

    for (i=2; i < signalLength - 2; i++)
    {
        float window[5];
        for (j=0; j<5; j++)
        {
            window[j] = signal[i-2+j];
        }

        for (j=0;j<3;j++)
        {
            window[j] = signal[i - 2 + j];
        }
    }

    // Order elements (only half of them)
    for (j = 0; j < 3; j++)
    {
        //   Find position of minimum element
        int min = j;
        for (k = j + 1; k < 5; k++)
        {
            if (window[k] < window[min])
            min = k;
        }

        // Put found minimum element in its place
        float temp = window[j];
        window[j] = window[min];
        window[min] = temp;
    }

    // Get result - the middle element
    output[i - 2] = window[2];
}

0 个答案:

没有答案