c语言中值滤波子函数 c++实现中值滤波-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

c语言中值滤波子函数 c++实现中值滤波

C语言实现fir1函数

#include stdio.h

创新互联2013年至今,先为善左等服务建站,善左等地企业,进行企业商务咨询服务。为善左企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

#ifdef WIN32

#include conio.h

#endif

#define SAMPLE double /* define the type used for data samples */

void clear(int ntaps, SAMPLE z[])

{

int ii;

for (ii = 0; ii ntaps; ii++) {

z[ii] = 0;

}

}

SAMPLE fir_basic(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[])

{

int ii;

SAMPLE accum;

/* store input at the beginning of the delay line */

z[0] = input;

/* calc FIR */

accum = 0;

for (ii = 0; ii ntaps; ii++) {

accum += h[ii] * z[ii];

}

/* shift delay line */

for (ii = ntaps - 2; ii = 0; ii--) {

z[ii + 1] = z[ii];

}

return accum;

}

SAMPLE fir_circular(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[],

int *p_state)

{

int ii, state;

SAMPLE accum;

state = *p_state; /* copy the filter's state to a local */

/* store input at the beginning of the delay line */

z[state] = input;

if (++state = ntaps) { /* incr state and check for wrap */

state = 0;

}

/* calc FIR and shift data */

accum = 0;

for (ii = ntaps - 1; ii = 0; ii--) {

accum += h[ii] * z[state];

if (++state = ntaps) { /* incr state and check for wrap */

state = 0;

}

}

*p_state = state; /* return new state to caller */

return accum;

}

SAMPLE fir_shuffle(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[])

{

int ii;

SAMPLE accum;

/* store input at the beginning of the delay line */

z[0] = input;

/* calc FIR and shift data */

accum = h[ntaps - 1] * z[ntaps - 1];

for (ii = ntaps - 2; ii = 0; ii--) {

accum += h[ii] * z[ii];

z[ii + 1] = z[ii];

}

return accum;

}

SAMPLE fir_split(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[],

int *p_state)

{

int ii, end_ntaps, state = *p_state;

SAMPLE accum;

SAMPLE const *p_h;

SAMPLE *p_z;

/* setup the filter */

accum = 0;

p_h = h;

/* calculate the end part */

p_z = z + state;

*p_z = input;

end_ntaps = ntaps - state;

for (ii = 0; ii end_ntaps; ii++) {

accum += *p_h++ * *p_z++;

}

/* calculate the beginning part */

p_z = z;

for (ii = 0; ii state; ii++) {

accum += *p_h++ * *p_z++;

}

/* decrement the state, wrapping if below zero */

if (--state 0) {

state += ntaps;

}

*p_state = state; /* return new state to caller */

return accum;

}

SAMPLE fir_double_z(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[],

int *p_state)

{

SAMPLE accum;

int ii, state = *p_state;

SAMPLE const *p_h, *p_z;

/* store input at the beginning of the delay line as well as ntaps more */

z[state] = z[state + ntaps] = input;

/* calculate the filter */

p_h = h;

p_z = z + state;

accum = 0;

for (ii = 0; ii ntaps; ii++) {

accum += *p_h++ * *p_z++;

}

/* decrement state, wrapping if below zero */

if (--state 0) {

state += ntaps;

}

*p_state = state; /* return new state to caller */

return accum;

}

SAMPLE fir_double_h(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[],

int *p_state)

{

SAMPLE accum;

int ii, state = *p_state;

SAMPLE const *p_h, *p_z;

/* store input at the beginning of the delay line */

z[state] = input;

/* calculate the filter */

p_h = h + ntaps - state;

p_z = z;

accum = 0;

for (ii = 0; ii ntaps; ii++) {

accum += *p_h++ * *p_z++;

}

/* decrement state, wrapping if below zero */

if (--state 0) {

state += ntaps;

}

*p_state = state; /* return new state to caller */

return accum;

}

int main(void)

{

#define NTAPS 6

static const SAMPLE h[NTAPS] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };

static SAMPLE h2[2 * NTAPS];

static SAMPLE z[2 * NTAPS];

#define IMP_SIZE (3 * NTAPS)

static SAMPLE imp[IMP_SIZE];

SAMPLE output;

int ii, state;

/* make impulse input signal */

clear(IMP_SIZE, imp);

imp[5] = 1.0;

/* create a SAMPLEd h */

for (ii = 0; ii NTAPS; ii++) {

h2[ii] = h2[ii + NTAPS] = h[ii];

}

/* test FIR algorithms */

printf("Testing fir_basic:\n ");

clear(NTAPS, z);

for (ii = 0; ii IMP_SIZE; ii++) {

output = fir_basic(imp[ii], NTAPS, h, z);

printf("%3.1lf ", (double) output);

}

printf("\n\n");

printf("Testing fir_shuffle:\n ");

clear(NTAPS, z);

state = 0;

for (ii = 0; ii IMP_SIZE; ii++) {

output = fir_shuffle(imp[ii], NTAPS, h, z);

printf("%3.1lf ", (double) output);

}

printf("\n\n");

printf("Testing fir_circular:\n ");

clear(NTAPS, z);

state = 0;

for (ii = 0; ii IMP_SIZE; ii++) {

output = fir_circular(imp[ii], NTAPS, h, z, state);

printf("%3.1lf ", (double) output);

}

printf("\n\n");

printf("Testing fir_split:\n ");

clear(NTAPS, z);

state = 0;

for (ii = 0; ii IMP_SIZE; ii++) {

output = fir_split(imp[ii], NTAPS, h, z, state);

printf("%3.1lf ", (double) output);

}

printf("\n\n");

printf("Testing fir_double_z:\n ");

clear(2 * NTAPS, z);

state = 0;

for (ii = 0; ii IMP_SIZE; ii++) {

output = fir_double_z(imp[ii], NTAPS, h, z, state);

printf("%3.1lf ", (double) output);

}

printf("\n\n");

printf("Testing fir_double_h:\n ");

clear(NTAPS, z);

state = 0;

for (ii = 0; ii IMP_SIZE; ii++) {

output = fir_double_h(imp[ii], NTAPS, h2, z, state);

printf("%3.1lf ", (double) output);

}

#ifdef WIN32

printf("\n\nHit any key to continue.");

getch();

#endif

return 0;

}

1. fir_basic: 实现基本的FIR滤波器

2. fir_circular: 说明环行buffer是如何实现FIR的。

3. fir_shuffle: 一些TI的处理器上使用的shuffle down技巧

4. fir_split: 把FIR滤波器展开为两块,避免使用环行缓存。

5. fir_double_z: 使用双精度的延迟线,使可以使用一个flat buffer。

6. fir_double_h: 使用双精度的系数,使可以使用一个flat buffer。

c语言中值滤波问题?

1. 是规定做中值滤波的点不含边缘的点(取决于中值滤波窗口大小)。 2,对图像边缘部分的信息进行镜像处理。

怎样写数字滤波程序?

可以告诉你方法:算数平均滤波,就是求出k次采样值的总和,再除以k;中值滤波法,是把k个采样值按照从小到大排列顺序,然后找到位于最中间的那个值;最后一种不知道你们老师的防脉冲是什么意思,猜测可能是去掉k次采样值中大于或小于某个值,剩余值求平均数。

让别人免费给你写程序基本上不可能,这个得花时间和精力。

求大神,c语言的一个矩阵相乘(两个3*3的矩阵),中值滤波问题

按照题目要求写如下代码,后面附结果,如果满意,望采纳!

#include stdio.h

#include stdlib.h

#include string.h

double A[3][16] = {160,163,167,80,83,85,155,158,159,20,22,23,170,173,176,179,

   159,158,155,75,78,80,156,159,153,25,23,21,167,168,166,164,

   153,155,157,81,84,82,154,153,158,27,25,24,168,172,171,170}; 

double mask[3][3] = {1,2,1,

 2,4,2,

 1,2,1};

void myfilter(double* p)

{

int i,j;

for (i = 1; i = 14; ++i)

{

/* code */

double sum = 0;

for(j=0;j3;++j)

{

sum += A[j][i-1]*mask[j][0] + A[j][i]*mask[j][1] + A[j][i+1]*mask[j][2];

}

// printf("sum=%lf\n", sum);

*p++ = sum/16;

}

return;

}

int main(int argc, char const *argv[])

{

/* code */

double ans[14];

double * p = ans;

myfilter(p);

int i;

for(i=0;i14;++i)

{

printf("%.4lf\n", ans[i]);

}

printf("\n");

system("pause");

return 0;

}

中值滤波程序的问题。如果我把子函数的程序放在主函数中就可以达到预期效果,但是下面这样做就不行了。

int maopao(unsigned char n1,unsigned char n2,unsigned char n3,unsigned char n4,unsigned char n5,

unsigned char n6,unsigned char n7,unsigned char n8,unsigned char n9)

{

int ii,jj,t;

int a[9]={n1,n2,n3,n4,n5,n6,n7,n8,n9};

for(ii=0;ii8;ii++)

{

for (jj=0;jj8-ii;jj++)

{

if (a[jj]a[jj+1])

{

t=a[jj];

a[jj]=a[jj+1];

a[jj+1]=t;

}

}

}

return a[4];

}

C语言实现 一组数如 1 2 3 4 5 6 7递推中值滤波 数组长度为3?

0,1,2,3,4,5} ;.0,1,2,3,4,5} ; c } ?Char a = “ string” ; ????Int a [] = “ string” ; 首先,a 是正确的,尽管数组的长度没有值,但它会自动确认数组的长度。C 的问题在于字符串的第一个地址被赋给了一个 char 变量。


本文题目:c语言中值滤波子函数 c++实现中值滤波
浏览地址:http://kswsj.cn/article/docgscd.html

其他资讯