行业资讯

行业资讯

通过我们的最新动态了解我们

c语言滤波器(c语言滤波器设计)

发布时间:2023-05-13
阅读量:95

本文目录一览:

二阶滤波器用C语言怎么写

这个可比你想象的复杂多了,s是个复变量,1/(s+1)极点在晌大-1,要想用C语言写,必须理解清楚下面几个问题:

1、输入必须是个有限序列,比如(x+yi),x和y分别是两个长度为N的数组

2、要过滤的频率,必须是个整宴仿竖型值,或者是个整型区间

3、输出结果同样是两个长度为N的数组(p+qi)

4、整个程序需要使用最基本的复数运算,这一点C语言本身不提供,必须手工写复函数运算库

5、实现的时候具体算法还需要编,这里才是你问题的核心。

我可以送你一段FFT的程序,自己琢磨吧,和MATLAB的概念差别很大:

#include assert.h

#include math.h

#include stdio.h

#include stdlib.h

#include string.h

#include windows.h

#include "complex.h"

extern "C" {

// Discrete Fourier Transform (Basic Version, Without Any Enhancement)

// return - Without Special Meaning, constantly, zero

int DFT (long count, CComplex * input, CComplex * output)

{

assert(count);

assert(input);

assert(output);

CComplex F, X, T, W; int n, i;

long N = abs(count); long Inversing = count 大前 0? 1: -1;

for(n = 0; n N ; n++){ // compute from line 0 to N-1

F = CComplex(0.0f, 0.0f); // clear a line

for(i = 0; i N; i++) {

T = input[i];

W = HarmonicPI2(Inversing * n * i, N);

X = T * W;

F += X; // fininshing a line

}//next i

// save data to outpus

memcpy(output + n, F, sizeof(F));

}//next n

return 0;

}//end DFT

int fft (long count, CComplex * input, CComplex * output)

{

assert(count);

assert(input);

assert(output);

int N = abs(count); long Inversing = count 0? -1: 1;

if (N % 2 || N 5) return DFT(count, input, output);

long N2 = N / 2;

CComplex * iEven = new CComplex[N2]; memset(iEven, 0, sizeof(CComplex) * N2);

CComplex * oEven = new CComplex[N2]; memset(oEven, 0, sizeof(CComplex) * N2);

CComplex * iOdd = new CComplex[N2]; memset(iOdd , 0, sizeof(CComplex) * N2);

CComplex * oOdd = new CComplex[N2]; memset(oOdd , 0, sizeof(CComplex) * N2);

int i = 0; CComplex W;

for(i = 0; i N2; i++) {

iEven[i] = input[i * 2];

iOdd [i] = input[i * 2 + 1];

}//next i

fft(N2 * Inversing, iEven, oEven);

fft(N2 * Inversing, iOdd, oOdd );

for(i = 0; i N2; i++) {

W = HarmonicPI2(Inversing * (- i), N);

output[i] = oEven[i] + W * oOdd[i];

output[i + N2] = oEven[i] - W * oOdd[i];

}//next i

return 0;

}//end FFT

void __stdcall FFT(

long N, // Serial Length, N 0 for DFT, N 0 for iDFT - inversed Discrete Fourier Transform

double * inputReal, double * inputImaginary, // inputs

double * AmplitudeFrequences, double * PhaseFrequences) // outputs

{

if (N == 0) return;

if (!inputReal !inputImaginary) return;

short n = abs(N);

CComplex * input = new CComplex[n]; memset(input, 0, sizeof(CComplex) * n);

CComplex * output= new CComplex[n]; memset(output,0, sizeof(CComplex) * n);

double rl = 0.0f, im = 0.0f; int i = 0;

for (i = 0; i n; i++) {

rl = 0.0f; im = 0.0f;

if (inputReal) rl = inputReal[i];

if (inputImaginary) im = inputImaginary[i];

input[i] = CComplex(rl, im);

}//next i

int f = fft(N, input, output);

double factor = n;

//factor = sqrt(factor);

if (N 0)

factor = 1.0f;

else

factor = 1.0f / factor;

//end if

for (i = 0; i n; i++) {

if (AmplitudeFrequences) AmplitudeFrequences[i] = output[i].getReal() * factor;

if (PhaseFrequences) PhaseFrequences[i] = output[i].getImaginary() * factor;

}//next i

delete [] output;

delete [] input;

return ;

}//end FFT

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

{

fprintf(stderr, "%s usage:\n", argv[0]);

fprintf(stderr, "Public Declare Sub FFT Lib \"wfft.exe\" \

(ByVal N As Long, ByRef inputReal As Double, ByRef inputImaginary As Double, \

ByRef freqAmplitude As Double, ByRef freqPhase As Double)");

return 0;

}//end main

};//end extern "C"

二阶通用滤波器用C语言怎么编程

shorth[],shorty[]){inti,j,sum;for(j=0;j15;}}2voidfir(shortx[],shorth[],shorty[]){inti,j,sum0,sum1;shortx0,x1,h0,h1;for(j=0;j15;y[j+1]=sum115;}}3voidfir(shortx[],shorth[],shorty[]){inti,j,sum0,sum1;shortx0,x1,x2,x3,x4,x5,x6,x7,h0,h1,h2,h3,h4,h5,h6,h7;for(j=0;j15;y[j+1]=sum115;}}

如何用C语言来实现数字滤波器?

用C语言实现,希望圆滑能给出个完整的已调试好程拦让序,不甚感谢,给你20分问题补充:例子中9、2、14有误,简腔局应该是11、2、14

太麻烦了

我只编了一

如何用c语言实现截止频率为200hz的巴特沃斯低通滤波器

/* 6th Order Low Pass Butterworth */

/* Bilinear Transformation with Prewarping */

/* Sample Frequency = 100.0 Hz */好乱

/* Standard Form */禅闷

/* Arithmetic Precision = 4 Digits */

/* */

/* Pass Band Frequency = 35.00 Hz */

/* */

/******************************************************************************/

/* */

/* Input Variable Definitions: */

/* Inputs: */

/* invar float The input to the filter */

/* initvar float The initial value of the filter */

/* setic int 1 to initialize the filter to the value of initvar */友袭档

/* */

/* There is no requirement to ever initialize the filter. */

/* The default initialization is zero when the filter is first called */

float DigFil(invar, initval, setic)

float invar, initval; int setic;

{

float sumnum, sumden; int i;

static float delay[7] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0};

static float znum[7] = {

.1477,

.8864,

2.216,

2.955,

2.216,

.8864,

.1477

};

static float zden[6] = {

2.183e-02,

.2099,

.8779,

2.055,

2.91,

2.38

};

if (setic==1){

for (i=0;i=6;i++) delay[i] = .1058*initval;

return initval;

}

else{

sumden=0.0;

sumnum=0.0;

for (i=0;i=5;i++){

delay[i] = delay[i+1];

sumden += delay[i]*zden[i];

sumnum += delay[i]*znum[i];

}

delay[6] = invar-sumden;

sumnum += delay[6]*znum[6];

return sumnum;

}

}

如何用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=middle_value[j-1];

            middle_value[j-1]=middle_value[j]

            middle_value[j]=data;

        }

    }

    sample_value=middle_value(count-1)/2];

    return(sample_value);

}

用C语言(!!!不移位方式)实现FIR滤波器 程序尽量简单,还有正确性

short h[], short y[])

{

int i, j, sum; for (j = 0; j 100; j++) {

sum = 0;

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

sum += x[i+j] * h[i];

y[j] = sum 15;

}

}

2

void fir(short x[], short h[], short y[])

{

int i, j, sum0, sum1;

short x0,x1,h0,h1; for (j = 0; j 100; j+=2) {

sum0 = 0;

sum1 = 0;

x0 = x[j];

for (i = 0; i 姿兆 32; i+=2){

x1 = x[j+i+1];

h0 = h[i];

sum0 += x0 * h0;

sum1 += x1 * h0;

x0 = x[j+i+2];

h1 = h[i+1];

sum0 += x1 * h1;

sum1 += x0 * h1;

}

y[j] = sum0 15;

y[j+1] = sum1 携迟迹隐租 15;

}

}

3

void fir(short x[], short h[], short y[])

{

int i, j, sum0, sum1;

short x0,x1,x2,x3,x4,x5,x6,x7,h0,h1,h2,h3,h4,h5,h6,h7; for (j = 0; j 100; j+=2) {

sum0 = 0;

sum1 = 0;

x0 = x[j];

for (i = 0; i 32; i+=8){

x1 = x[j+i+1];

h0 = h[i];

sum0 += x0 * h0;

sum1 += x1 * h0;

x2 = x[j+i+2];

h1 = h[i+1];

sum0 += x1 * h1;

sum1 += x2 * h1;

x3 = x[j+i+3];

h2 = h[i+2];

sum0 += x2 * h2;

sum1 += x3 * h2;

x4 = x[j+i+4];

h3 = h[i+3];

sum0 += x3 * h3;

sum1 += x4 * h3;

x5 = x[j+i+5];

h4 = h[i+4];

sum0 += x4 * h4;

sum1 += x5 * h4;

x6 = x[j+i+6];

h5 = h[i+5];

sum0 += x5 * h5;

sum1 += x6 * h5;

x7 = x[j+i+7];

h6 = h[i+6];

sum0 += x6 * h6;

sum1 += x7 * h6;

x0 = x[j+i+8];

h7 = h[i+7];

sum0 += x7 * h7;

sum1 += x0 * h7;

}

y[j] = sum0 15;

y[j+1] = sum1 15;

}

}

关键词:滤波器程序 二阶滤波器 FIR滤波器 c语言滤波器 巴特沃斯低通滤波器 语言滤波器

相关新闻

一点销电子网

Yidianxiao Electronic Website Platform

Tel:0512-36851680
E-mail:King_Zhang@Lpmconn.com
我们欢迎任何人与我们取得联系!
请填写你的信息,我们的服务团队将在以您填写的信息与您取得联系。
*您的姓名
*电话
问题/建议
承诺收集您的这些信息仅用于与您取得联系,帮助您更好的了解我们。