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语言实现低通滤波器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);
}
二阶滤波器用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 = count0? 1: -1;
for(n = 0; nN ; n){ // compute from line 0 to N-1
F = CComplex(0.0f, 0.0f); // clear a line
for(i = 0; iN; 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(outputn, 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 = count0? -1: 1;
if (N % 2 || N5) 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; iN2; i) {
iEven[i] = input[i * 2];
iOdd [i] = input[i * 21];
}//next i
fft(N2 * Inversing, iEven, oEven);
fft(N2 * Inversing, iOdd,oOdd );
for(i = 0; iN2; i) {
W = HarmonicPI2(Inversing * (- i), N);
output[i]= oEven[i]W * oOdd[i];
output[iN2] = oEven[i] - W * oOdd[i];
}//next i
return 0;
}//end FFT
void __stdcall FFT(
long N, // Serial Length, N0 for DFT, N0 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; in; 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 (N0)
factor = 1.0f;
else
factor = 1.0f / factor;
//end if
for (i = 0; in; 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语言中值滤波问题?1. 是规定做中值滤波c语言编写按键滤波函数的点不含边缘c语言编写按键滤波函数的点(取决于中值滤波窗口大小) 。2,对图像边缘部分c语言编写按键滤波函数的信息进行镜像处理 。
【c语言编写按键滤波函数 cic滤波器c语言】关于c语言编写按键滤波函数和cic滤波器c语言的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- 栅格导入gis,导入栅格数据
- 游戏玩家的路由器叫什么,游戏路由器是什么意思
- 包含ppt视频如何添加录音的词条
- 阿里云服务器无法解析,阿里云解析失败
- linuxwas命令行 linux wasm
- 海南三维gis应用领域,海南三维gis应用领域有哪些
- python函数预定义 python自定义函数
- 微信发送视频号会被发现吗,微信发送位置不显示自己店铺
- 下载猫跑酷,猫跑酷小游戏