行业资讯
这个可比你想象的复杂多了,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"
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语言实现,希望圆滑能给出个完整的已调试好程拦让序,不甚感谢,给你20分问题补充:例子中9、2、14有误,简腔局应该是11、2、14
太麻烦了
我只编了一
/* 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;
}
}
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);
}
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;
}
}
低通滤波器的一阶二阶电路振幅特性曲线有区别吗2、滤波器一般用在哪里3、一阶滤波器和二阶滤波器的区别4、关于一阶低通滤波器和二阶低通滤波器5、PT1滤波和DT1滤...
滤波器的工作原理和作用是什么2、试分析比较模拟滤波器与数字滤波器的优缺点。3、容易设定增益的多重反馈低通滤波器滤波器的工作原理和作用是什么1、滤波器是一种选频装...
急!!!用窗函数法设计FIR滤波器的主要特点是什么?2、ad滤波器怎么找3、滑动窗平均滤波器的带宽如何计算?4、哪几种滤波器是平滑的急!!!用窗函数法设计FIR...
单极和双极滤波的区别2、滤波电路的种类3、什么是单相单极电源滤波器和单相双极电源滤波器单极和双极滤波的区别专业机器检测结果显示,单极射频可深入皮下10mm~20...
介绍点余弦调制滤波器组的技术吧2、滤波器翘起空焊怎么解决3、请问数字滤波的方法有那些?什么是“加窗”?4、《现代数字信号处理》和《数字信号处理》的区别?5、Ma...
二阶滤波电路原理是什么2、simulink二阶滤波器在哪3、一阶滤波器和二阶滤波器的区别4、二阶rc有源低通滤波器至少需要几个电阻和放大器二阶滤波电路原理是什么...
PIC18F2480的CAN总线中如何设置滤波器2、汽车can总线总电压小于大于3.5v的原因3、CAN通讯中单滤波和双滤波有什么区别?4、stm32f407的...
数字滤波器选择1至6阶滤波什么意思2、六阶高通滤波器怎么计算3、怎么样看出滤波器是几阶的呢数字滤波器选择1至6阶滤波什么意思滤波器的阶数,就是指过滤谐波的次数,...
要得到一个方便调节零极点的IIR滤波器应用什么结构2、滤波器的设计思路3、数字信号处理中z变换形式的滤波器零极点与其高通低通之间的关系以及归一...4、有谁能总...
MATLAB一阶低通滤波器的设计2、一阶高通滤波器表达式3、一阶滤波器和二阶滤波器的区别4、一阶rc低通滤波器公式是什么?MATLAB一阶低通滤波器的设计1、m...
一点销电子网
Yidianxiao Electronic Website Platform