導航:首頁 > 編程語言 > 最小值濾波c代碼

最小值濾波c代碼

發布時間:2023-06-10 05:49:22

1. 求教用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);
}

2. FIR濾波器的C語言程序

length==256

3. 二階濾波器用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代碼相關的資料

熱點內容
dede工具 瀏覽:507
5g網盟app怎麼下載 瀏覽:486
微信備份老是連接中斷 瀏覽:886
出台多少份文件 瀏覽:380
鞋子怎麼搭配衣服的app 瀏覽:755
文件名使用的通配符的符號是什麼 瀏覽:916
lol分卷文件損壞怎麼辦 瀏覽:276
6分管車螺紋怎麼編程 瀏覽:732
海口農商銀行信用卡app是什麼 瀏覽:770
win10任務欄文件夾我的電腦 瀏覽:14
安卓nba2k18 瀏覽:776
文件夾密碼怎麼修改密碼 瀏覽:271
蘋果數據中心用什麼伺服器 瀏覽:769
省內圓通快遞寄文件夾需要多少錢 瀏覽:740
iphone程序加密 瀏覽:884
win10文件夾調整文件行高 瀏覽:681
創意手繪教程 瀏覽:754
微信刪除帳號信息 瀏覽:596
mysql操作類文件 瀏覽:649
繞過xp密碼 瀏覽:158

友情鏈接