c语言中值滤波函数 c语言fir滤波器

如何用C语言实现低通滤波器float middle_filter(float middle_value [] , intcount)
{
float sample_value, data;
int i, j;
for (i=1; i for(j=count-1; j=i,--j){
if(middle_value[j-1]=middle_value[j]{
data=https://www.04ip.com/post/middle_value[j-1];
middle_value[j-1]=middle_value[j]
middle_value[j]=data;
}
}
sample_value=https://www.04ip.com/post/middle_value(count-1)/2];
return(sample_value);
}
fabs在c语言中意思是什么?fabs()属于C语言中的库函数 , 用于求浮点数x的绝对值 。
函数原型:double fabs(double x);
函数功能:函数fabs的作用是求浮点数x的绝对值 。
函数参数:参数x是一个浮点数 。
说明:函数fabs()的输入参数必须以double类型输入,函数返回值为double型 。因此,必须使用double类型变量作为接收返回值的数据 。
函数的返回值:函数返回x的绝对值 。
库函数介绍
库函数把一些常用到的函数编完放到一个文件里,供不同的人进行调用 。调用的时候把它所在的文件名用#include加到里面就可以了 。一般是放到lib文件里的 。
C语言的库函数并不是C语言本身的一部分,它是由编译程序根据一般用户的需要编制并提供用户使用的一组程序 。C的库函数极大地方便了用户,同时也补充了C语言本身的不足 。
事实上,在编写C语言程序时 , 应当尽可能多地使用库函数,这样既可以提高程序的运行效率,又可以提高编程的质量 。
以上内容参考 百度百科—fabs
c语言中fabs()是什么意思数学函数:fabs
原型:extern float fabs(float x);
用法:#include math.h
功能:求浮点数x的绝对值
说明:计算|x|, 当x不为负时返回x , 否则返回-x
举例:
// fabs.c
#include syslib.h
#include math.h
main()
{
float x;
clrscr(); // clear screen
textmode(0x00); // 6 lines per LCD screen
x=-74.12;
printf("|%f|=%f\n",x,fabs(x));
x=0;
printf("|%f|=%f\n",x,fabs(x));
x=74.12;
printf("|%f|=%f\n",x,fabs(x));
getchar();
return 0;
}
扩展资料:
程序判数滤波 采样的信号,如因常受到随机干扰传感器不稳定而引起严重失真时,可以采用此方法 。
方法是:根据生产经验确定两交采样允许的最大偏差△×,若先后两次采样的信号相减数值大于△×,表明输入的是干扰信号,应该去掉;
用上次采样值作为本次采样值,若小于、等于△×表明没有受到干,本次采样值效 。该方法适用于慢变化的物理参数的采样,如温度、物理位置等测量系统 。
程序判断滤波的C程序函数如下:
float program_detect_filter(float old_new_value[], float X)
{
float sample_value;
if (fabs(old_new_value[1]_old_new_value[0])X)
sample_value=https://www.04ip.com/post/old_new_value[0];
else
sample_value=https://www.04ip.com/post/old_new_value[1];
retrun(sample_value);
}
函数调用需一个一维的两个元素的数组(old_new_value[2],用于存放上次采样值(old_new_value[0],)和本次采样值(old_new_value[1],),函数中sample_value表示有效采样值,X表示根据根据经验确定的两次采样允许的最大偏差△× 。
参考资料来源:百度百科:fabs函数
c语言中值滤波问题?1. 是规定做中值滤波c语言中值滤波函数的点不含边缘c语言中值滤波函数的点(取决于中值滤波窗口大小) 。2,对图像边缘部分的信息进行镜像处理 。
C语言实现fir1函数#include stdio.h
#ifdef WIN32
#include conio.h
#endif
#define SAMPLEdouble/* define the type used for data samples */
void clear(int ntaps, SAMPLE z[])
{
int ii;
for (ii = 0; iintaps; 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; iintaps; ii) {
accum= h[ii] * z[ii];
}
/* shift delay line */
for (ii = ntaps - 2; ii = 0; ii--) {
z[ii1] = 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[ii1] = 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 = zstate;
*p_z = input;
end_ntaps = ntaps - state;
for (ii = 0; iiend_ntaps; ii) {
accum= *p_h* *p_z;
}
/* calculate the beginning part */
p_z = z;
for (ii = 0; iistate; ii) {
accum= *p_h* *p_z;
}
/* decrement the state, wrapping if below zero */
if (--state0) {
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[statentaps] = input;
/* calculate the filter */
p_h = h;
p_z = zstate;
accum = 0;
for (ii = 0; iintaps; ii) {
accum= *p_h* *p_z;
}
/* decrement state, wrapping if below zero */
if (--state0) {
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 = hntaps - state;
p_z = z;
accum = 0;
for (ii = 0; iintaps; ii) {
accum= *p_h* *p_z;
}
/* decrement state, wrapping if below zero */
if (--state0) {
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; iiNTAPS; ii) {
h2[ii] = h2[iiNTAPS] = h[ii];
}
/* test FIR algorithms */
printf("Testing fir_basic:\n");
clear(NTAPS, z);
for (ii = 0; iiIMP_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; iiIMP_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; iiIMP_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; iiIMP_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; iiIMP_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; iiIMP_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语言中值滤波函数 c语言fir滤波器】关于c语言中值滤波函数和c语言fir滤波器的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读