1. 是規(guī)定做中值濾波的點(diǎn)不含邊緣的點(diǎn)(取決于中值濾波窗口大小)。 2,對(duì)圖像邊緣部分的信息進(jìn)行鏡像處理。
“只有客戶發(fā)展了,才有我們的生存與發(fā)展!”這是成都創(chuàng)新互聯(lián)的服務(wù)宗旨!把網(wǎng)站當(dāng)作互聯(lián)網(wǎng)產(chǎn)品,產(chǎn)品思維更注重全局思維、需求分析和迭代思維,在網(wǎng)站建設(shè)中就是為了建設(shè)一個(gè)不僅審美在線,而且實(shí)用性極高的網(wǎng)站。創(chuàng)新互聯(lián)對(duì)做網(wǎng)站、網(wǎng)站制作、網(wǎng)站制作、網(wǎng)站開發(fā)、網(wǎng)頁設(shè)計(jì)、網(wǎng)站優(yōu)化、網(wǎng)絡(luò)推廣、探索永無止境。
這個(gè)問題比較復(fù)雜,最近本人也在研究數(shù)字濾波,
結(jié)合圖片說一下
第一個(gè)圖是fir的流程圖,其中Z-1是延遲,是單個(gè)采樣時(shí)間1/fs
n階的fir濾波器就是選取最近的n+1個(gè)樣本,然后使他們各自乘以自己的濾波器系數(shù)即圖中的F(n),[一般其他書的表示是h(n)]
然后相加得到輸出的y(n)就是一個(gè)輸出點(diǎn)
,其中F(n)的得出需要根據(jù)采樣頻率和濾波器的通帶和阻帶來決定
其中為了改善旁瓣的幅值,一般在采樣后給樣本或者h(yuǎn)(n)加窗,當(dāng)然可以用“最佳方法”來做
得出h(n)大致方法是先將矩形窗進(jìn)行DFT,得出h(n),然后對(duì)h(n)進(jìn)行加窗得出h(k),然后將∑h(k)×x(n)=y(n),假如階數(shù)較多可以用傅里葉變換使時(shí)域變頻域后再將卷積相加,可以利用FFT來改進(jìn)實(shí)時(shí)性,提升速度
上面就是fir濾波器的簡述
第二個(gè)圖片上傳不了,直接給鏈接
;amp;z=0tn=baiduimagedetailword=%D2%BB%BD%D7iir%C2%CB%B2%A8%C6%F7in=12708cl=2cm=1sc=0lm=-1pn=0rn=1di=2607528304ln=1054fr=
圖中的Z-1是延時(shí),iir濾波器也叫無限沖擊響應(yīng)濾波器,是有反饋的,
圖中的是一階的,相對(duì)fir濾波器來說,iir濾波器可以用較低的階數(shù)來獲得較好的濾波特效。但是其相位特性較差。
鑒于實(shí)用性,還是建議樓主去圖書館借書看,百度不可能得到確實(shí)的方案,
樓主可以去借“數(shù)字信號(hào)處理”的書,國外的中譯本就有詳細(xì)介紹fir和iir以及fft還有其他變換,國內(nèi)的dsp大都幾乎是dsp用戶手冊的中譯本,對(duì)上述問題都是很簡陋地帶過,不予置評(píng)。
本人推薦一本書在上面的dsp專欄有下載,40多M,叫DSP算法、應(yīng)用和設(shè)計(jì),本人有這本實(shí)體書,寫的較好
#include stdio.h
#ifdef WIN32
#include conio.h
#endif
#define SAMPLE double /* define the type used for data samples */
void clear(int ntaps, SAMPLE z[])
{
int ii;
for (ii = 0; ii ntaps; 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; ii ntaps; ii++) {
accum += h[ii] * z[ii];
}
/* shift delay line */
for (ii = ntaps - 2; ii = 0; ii--) {
z[ii + 1] = 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[ii + 1] = 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 = z + state;
*p_z = input;
end_ntaps = ntaps - state;
for (ii = 0; ii end_ntaps; ii++) {
accum += *p_h++ * *p_z++;
}
/* calculate the beginning part */
p_z = z;
for (ii = 0; ii state; ii++) {
accum += *p_h++ * *p_z++;
}
/* decrement the state, wrapping if below zero */
if (--state 0) {
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[state + ntaps] = input;
/* calculate the filter */
p_h = h;
p_z = z + state;
accum = 0;
for (ii = 0; ii ntaps; ii++) {
accum += *p_h++ * *p_z++;
}
/* decrement state, wrapping if below zero */
if (--state 0) {
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 = h + ntaps - state;
p_z = z;
accum = 0;
for (ii = 0; ii ntaps; ii++) {
accum += *p_h++ * *p_z++;
}
/* decrement state, wrapping if below zero */
if (--state 0) {
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; ii NTAPS; ii++) {
h2[ii] = h2[ii + NTAPS] = h[ii];
}
/* test FIR algorithms */
printf("Testing fir_basic:\n ");
clear(NTAPS, z);
for (ii = 0; ii IMP_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; ii IMP_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; ii IMP_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; ii IMP_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; ii IMP_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; ii IMP_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: 實(shí)現(xiàn)基本的FIR濾波器
2. fir_circular: 說明環(huán)行buffer是如何實(shí)現(xiàn)FIR的。
3. fir_shuffle: 一些TI的處理器上使用的shuffle down技巧
4. fir_split: 把FIR濾波器展開為兩塊,避免使用環(huán)行緩存。
5. fir_double_z: 使用雙精度的延遲線,使可以使用一個(gè)flat buffer。
6. fir_double_h: 使用雙精度的系數(shù),使可以使用一個(gè)flat buffer。
#includestdio.h
#include math.h
class complex //定義一個(gè)類,實(shí)現(xiàn)復(fù)數(shù)的所有操作
{
double Real,Image; //實(shí)部與虛部
public:
complex(double r="0",double i="0"){Real=r;Image=i;}
double GetR(){return Real;} //取出實(shí)部
double GetI(){return Image;} //取出虛部
complex operator + (complex ); //復(fù)數(shù)加法
complex operator - (complex ); //復(fù)數(shù)減法
complex operator * (complex ); //復(fù)數(shù)乘法
void operator =(complex ); //復(fù)數(shù) 賦值
};
complex complex::operator + (complex c) //復(fù)數(shù)加法
{
complex t;
t.Real=Real+c.Real;
t.Image=Image+c.Image;
return t;
}
complex complex::operator - (complex c) //復(fù)數(shù)減法
{
complex t;
t.Real=Real-c.Real;
t.Image=Image-c.Image;
return t;
}
complex complex::operator * (complex c) //復(fù)數(shù)乘法
{
complex t;
t.Real=Real*c.Real-Image*c.Image;
t.Image=Real*c.Image+Image*c.Real;
return t;
}
void complex::operator = (complex c) //復(fù)數(shù) 賦值
{
Real=c.Real;
Image=c.Image;
}
void fft(complex a[],int length,int jishu) //實(shí)現(xiàn)fft的函數(shù)
{
const double PI="3".141592653589793;
complex u,Wn,t;
int i,j,k,m,kind,distance,other;
double tmp;
for(i=0;ilength;i++) //實(shí)現(xiàn)倒敘排列
{
k="i";
j=0;
for(m=0;mjishu;m++)
{
j="j"*2+k%2;
k/=2;
}
if(ij)
{
t="a";
a=a[j];
a[j]=t;
}
}
for(m=1;m=jishu;m++) //第m級(jí)蝶形運(yùn)算,總級(jí)數(shù)為jishu
{
kind = (int)pow(2,m-1); //第m級(jí)有2^(m-1)種蝶形運(yùn)算
distance = 2*kind; //同種蝶形結(jié)相鄰距離為2^m
u=complex(1,0); //旋轉(zhuǎn)因子初始值為 1
tmp=PI/kind;
Wn=complex(cos(tmp),-sin(tmp));//旋轉(zhuǎn)因子Wn
for(j=0;jkind;j++) //每種蝶形運(yùn)算的起始點(diǎn)為j,共有kind種
{
for(i=j;ilength;i+=distance) //同種蝶形運(yùn)算
{
other=i+kind;//蝶形運(yùn)算的兩個(gè)因子對(duì)應(yīng)單元下標(biāo)的距離為2^(m-1)
t=a[other]*u; // 蝶形運(yùn)算的乘積項(xiàng)
a[other]=a-t; //蝶形運(yùn)算
a=a+t; //蝶形運(yùn)算
}
u="u"*Wn; //修改旋轉(zhuǎn)因子,多乘一個(gè)基本DFT因子WN
}
}
}
void main(void)
{
double a,b;
complex x[8]; //此程序以8點(diǎn)序列測試
printf("8點(diǎn)序列:\n");
for(int i="0";i8;i++) //初始化并輸出原始序列
{
x=complex(i,i+1);
printf("x(%d) = %lf + %lf i\n",i+1,x.GetR(),x.GetI());
}
fft(x,8,3); //調(diào)用fft函數(shù)
printf("fft變換的結(jié)果為:\n");
for(i=0;i8;i++) //輸出結(jié)果
printf("X(%d)= %lf + %lf i\n",i+1,x.GetR(),x.GetI());
}
這是我寫的1024點(diǎn)的快速傅里葉變換程序,下面有驗(yàn)證,你把數(shù)組
double
A[2049]={0};
double
B[1100]={0};
double
powerA[1025]={0};
改成
A[256]={0};
B[130]={0};
power[129]={0};就行了,
void
FFT(double
data[],
int
nn,
int
isign)
的程序可以針對(duì)任何點(diǎn)數(shù),只要是2的n次方
具體程序如下:
#include
iostream.h
#include
"math.h"
#includestdio.h
#includestring.h
#include
stdlib.h
#include
fstream.h
#include
afx.h
void
FFT(double
data[],
int
nn,
int
isign)
{
//復(fù)數(shù)的快速傅里葉變換
int
n,j,i,m,mmax,istep;
double
tempr,tempi,theta,wpr,wpi,wr,wi,wtemp;
n
=
2
*
nn;
j
=
1;
for
(i
=
1;
i=n
;
i=i+2)
//這個(gè)循環(huán)進(jìn)行的是碼位倒置。
{
if(
j
i)
{
tempr
=
data[j];
tempi
=
data[j
+
1];
data[j]
=
data[i];
data[j
+
1]
=
data[i
+
1];
data[i]
=
tempr;
data[i
+
1]
=
tempi;
}
m
=
n
/
2;
while
(m
=
2
j
m)
{
j
=
j
-
m;
m
=
m
/
2;
}
j
=
j
+
m;
}
mmax
=
2;
while(
n
mmax
)
{
istep
=
2
*
mmax;
//這里表示一次的數(shù)字的變化。也體現(xiàn)了級(jí)數(shù),若第一級(jí)時(shí),也就是書是的第0級(jí),其為兩個(gè)虛數(shù),所以對(duì)應(yīng)數(shù)組應(yīng)該增加4,這樣就可以進(jìn)入下一組運(yùn)算
theta
=
-6.28318530717959
/
(isign
*
mmax);
wpr
=
-2.0
*
sin(0.5
*
theta)*sin(0.5
*
theta);
wpi
=
sin(theta);
wr
=
1.0;
wi
=
0.0;
for(
m
=
1;
m=mmax;
m=m+2)
{
for
(i
=
m;
i=n;
i=i+istep)
{
j
=
i
+
mmax;
tempr=double(wr)*data[j]-double(wi)*data[j+1];//這兩句表示蝶形因子的下一個(gè)數(shù)乘以W因子所得的實(shí)部和虛部。
tempi=double(wr)*data[j+1]+double(wi)*data[j];
data[j]
=
data[i]
-
tempr;
//蝶形單元計(jì)算后下面單元的實(shí)部,下面為虛部,注意其變換之后的數(shù)組序號(hào)與書上蝶形單元是一致的
data[j
+
1]
=
data[i
+
1]
-
tempi;
data[i]
=
data[i]
+
tempr;
data[i
+
1]
=
data[i
+
1]
+
tempi;
}
wtemp
=
wr;
wr
=
wr
*
wpr
-
wi
*
wpi
+
wr;
wi
=
wi
*
wpr
+
wtemp
*
wpi
+
wi;
}
mmax
=
istep;
}
}
void
main()
{
//本程序已經(jīng)和MATLAB運(yùn)算結(jié)果對(duì)比,準(zhǔn)確無誤,需要注意的的是,計(jì)算中數(shù)組都是從1開始取得,丟棄了A[0]等數(shù)據(jù)
double
A[2049]={0};
double
B[1100]={0};
double
powerA[1025]={0};
char
line[50];
char
dataA[20],
dataB[20];
int
ij;
char
ch1[3]="\t";
char
ch2[3]="\n";
int
strl1,strl2;
CString
str1,str2;
ij=1;
//********************************讀入文件data1024.txt中的數(shù)據(jù),
其中的數(shù)據(jù)格式見該文件
FILE
*fp
=
fopen("data1024.txt","r");
if(!fp)
{
cout"Open
file
is
failing!"endl;
return;
}
while(!feof(fp))
//feof(fp)有兩個(gè)返回值:如果遇到文件結(jié)束,函數(shù)feof(fp)的值為1,否則為0。
{
memset(line,0,50);
//清空為0
memset(dataA,0,20);
memset(dataB,0,20);
fgets(line,50,fp);
//函數(shù)的功能是從fp所指文件中讀入n-1個(gè)字符放入line為起始地址的空間內(nèi)
sscanf(line,
"%s%s",
dataA,
dataB);
//我同時(shí)讀入了兩列值,但你要求1024個(gè),那么我就只用了第一列的1024個(gè)值
//dataA讀入第一列,dataB讀入第二列
B[ij]=atof(dataA);
//將字符型的dataA值轉(zhuǎn)化為float型
ij++;
}
for
(int
mm=1;mm1025;mm++)//A[2*mm-1]是實(shí)部,A[2*mm]是虛部,當(dāng)只要輸入實(shí)數(shù)時(shí),那么保證虛部A[mm*2]為零即可
{
A[2*mm-1]=B[mm];
A[2*mm]=0;
}
//*******************************************正式計(jì)算FFT
FFT(A,1024,1);
//********************************************寫入數(shù)據(jù)到workout.txt文件中
for
(int
k=1;k2049;k=k+2)
{
powerA[(k+1)/2]=sqrt(pow(A[k],2.0)+pow(A[k+1],2.0));//求功率譜
FILE
*pFile=fopen("workout.txt","a+");
//?a+只能在文件最后補(bǔ)充,光標(biāo)在結(jié)尾。沒有則創(chuàng)建
memset(ch1,0,15);
str1.Format("%.4f",powerA[(k+1)/2]);
if
(A[k+1]=0)
str2.Format("%d\t%6.4f%s%6.4f
%s",(k+1)/2,A[k],"+",A[k+1],"i");//保存fft計(jì)算的頻譜,是復(fù)數(shù)頻譜
else
str2.Format("%d\t%6.4f%6.4f
%s",(k+1)/2,A[k],A[k+1],"i");
strl1=strlen(str1);
strl2=strlen(str2);
//
用
法:fwrite(buffer,size,count,fp);
//
buffer:是一個(gè)指針,對(duì)fwrite來說,是要輸出數(shù)據(jù)的地址。
//
size:要寫入的字節(jié)數(shù);
//
count:要進(jìn)行寫入size字節(jié)的數(shù)據(jù)項(xiàng)的個(gè)數(shù);
//
fp:目標(biāo)文件指針。
fwrite(str2,1,strl2,pFile);
fwrite(ch1,1,3,pFile);
fwrite(ch1,1,3,pFile);
fwrite(str1,1,strl1,pFile);
fwrite(ch2,1,3,pFile);
fclose(pFile);
}
cout"計(jì)算完畢,到fft_test\workout.txt查看結(jié)果"endl;
}
網(wǎng)站題目:c語言傅里葉函數(shù)濾波 波函數(shù)的傅里葉變換
URL鏈接:http://jinyejixie.com/article34/hehese.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣、域名注冊、網(wǎng)站內(nèi)鏈、商城網(wǎng)站、小程序開發(fā)、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)