Giáo trình xử lý ảnh y tế Tập 1a P19 - Pdf 17

147

3. Để bộ lọc có bậc N

N, N lẻ, hệ số bộ lọc (giá trị của h(m,n)) chứa trong
một cửa sổ kéo dài từ










2
1
2
,
2
)1(
2
NMNM
đến









  














 







  






l¹i. cßn hîp trêng c¸ccho
víi
c
1
8,0 0
),(
2
2
2
1
21
srad
H



Những dao động trong giải thông rất đáng được chú ý. Các dao động do sự
hội tụ chậm của các hệ số trong chuỗi Fourier cho sự chuyển đổi đột ngột về
đặc tính tần số -biên độ. Nhắc lại rằng đáp ứng tần số được coi như tuần hoàn
và IFFT về cơ bản cùng dẫn đến hệ số Fourier của hàm tuần hoàn. Đây cũng là
đáp ứng xung hay hệ số của bộ lọc FIR.
8.3 Hàm cửa sổ
Các hàm cửa sổ để làm giảm bớt các dao động Gibbs được rút ra từ thiết kế
của bộ lọc FIR 1-D. Các hàm cửa sổ hay được được sử dụng nhất sẽ không liệt
kê theo bảng dưới đây cùng sự mở rộng của chúng sang trường hợp 2-D.

¦Cửa sổ Hann và Hamming. Cửa sổ Hann và Hamming cho bởi
148

Có hai lựa chọn khác nhau của . Trong cửa sổ Hann  = 0.5 và trong cửa
sổ Hamming  = 0. 54. Bậc của bộ lọc được cho là N.

¦Cửa sổ Blackmann. Cửa sổ Blackmann cho bởi :

1
4
cos08,0
0
1
2
cos5,042,0)(











N
n
N
n
nW

Hình 8.1 Đáp ứng tần số của bộ lọc FIR với 
c
= 0.8.
ở đây  là tham số độc lập và

 
 







1
2
1
2
n
N

với |n| 

N 1
2

với các trường hợp còn
l
ại
















Hàm cửa sổ 2-D cơ bản dựa trên các hàm cửa sổ 1-D cung cấp ở trên. Sự
mở rộng của bất kỳ hàm cửa sổ 1-D nào ở trên sang 2-D được tiến hành bằng
cách thay thế n bằng

n n
1
2
2
2
2


(8.5)
Chia cho
2
để đảm bảo rằng giá trị của n không vượt quá (N - 1)/2, giá trị

Chương trình 8.1 "FIRD.C" Thiết kế các bộ lọc dùng FFT và các hàm
cửa sổ.

/* Program for designing FIR filter using FFT on
prescribed frequency specifications.Option for
selecting a Window function is provided.
For the magnitude-frequency specifications you can
either supply your own data or select from a menu of
standard functions.
If you supply your own data the first two values
should be the dimensions of the 2-D array e.g. 32
32.
These dimensions should be equal to some power of
2. The data that follows is the magnitude
specifications in "%f " format stored in a row by
row fashion with no return code after every row.*/

#define pi 3.141592654

150

#include <stdio.h>
#include <math.h>
#include <alloc.h>
#include <stdlib.h>
#include <io.h>
#include <conio.h>
#include <ctype.h>
#include <conio.h>
#include <string.h>

printf(" reply to the following question is
negative.\n");
printf("Is freq. response provided in a file? (y or
n) >");
while(((ch1=getch())!='y')&&(ch1!='n'));
151

putch(ch1);
switch(ch1)
{
case 'n':
printf("\n Enter # of points to be generated
(e.g. 32x32) >");
scanf("%dx%d",&M1,&M1);
break ;
case 'y':
printf("\nEnter name of file storing magnitude
response >");
scanf("%s",file_name1);
fptr=fopen(file_name1,"r");
fscanf(fptr,"%d %d 11,01,&Mi");
}
M=M1>>1 ;
yt=wherey();
again1 :
gotoxy(1,yt);
printf( "
");
gotoxy(1,yt);
printf("Enter file name for storing impulse

case 'n' :
gotoxy(1,yt+1);
printf("
");
gotoxy(1,yt);
printf("Enter file name >");
scanf("file_name");
ind=access(file_name,0);
}
}

fptri=fopen("FFT.DAT","wb+");
fptro=fopen("IFFT.DAT","wb+");
buffi=(float *)malloc((M1<<1)*sizeof(float));
switch(ch1)
{
case 'n': /*Generating data for IFFT.*/
printf("\nEnter choice (1,2 etc.):\n");
printf(" 1. Low-pass.\n");
printf(" 2. High-pass.\n");
printf(" 3. Band-pass.\n");
printf(" 4. Band-reject >");

while(((ch=getche())!='1')&&(ch!='2')&&(ch!='3')&&(c
h!='4'));
switch(ch)
{
case '1' :
case '2' :
printf("\nEnter cut-off freq. in

{
ii=(i-M)*(i-M);
for(j=0;j<M1;j++)
{
R2=(float)((j-M)*(j-M)+ii);
switch(ch)
{
case '1': /* low-pass. */
if(choice=='1')
{
if(R2<Do) H=(float)1.0;
else H=(float)0.0;
}
if(choice=='2')
H=0.414*Do/(R2+0.414*Do);
break;

case '2': /* high-pass. */
if(choice=='1')
{
if(R2<Do) H=(float)0.0;
else H=(float)1.0;
}
154

if(choice=='2')
H=R2/(R2+0.414*Do);
break;

case '3': /* Band-pass. */

}
fclose(fptr);
}
rewind(fptri);
m=(int)(log10((double)M1)/log10((double)2));

/* Allocating memory for bit reversal LUT. */
L=(unsigned int *)malloc(M1*sizeof(unsigned
int));
155 /* Generate Look-up table for bit reversal. */
bit_reversal(L,m,M1);

/* Allocating memory for twiddle factors. */
n2=M1-1;
wr=(float *)malloc(n2*sizeof(float));
wi=(float *)malloc(n2*sizeof(float));

/* Generating twiddle factor.*/
WTS(wr,wi,M1,1);
clrscr();
FFT2D(fptri,fptro,wr,wi,L,M1,m,1);
clrscr();
fptri=fopen("IFFT.DAT","rb");
fptro=fopen("temp.dat","wb+");
nsq=(float)(M1*M1);
buffo=(float *)malloc(M1*sizeof(float));
for(i=0;i<M1;i++)

for(j=M2;j<=M3;j++)
h[(i-M2)][j-M2]=buffo[j];
}

/* Selection of Window functions. */
printf("\nEnter selection of window function:");
printf("\n 1.Rectangular.");
printf("\n 2.Hann.");
printf("\n 3.Hamming,");
printf("\n 4.Blackmann.");
printf("\n 5.Kaiser.");
printf("\nEnter (1,2 etc.) >");
while(((ch=getche())!='1')&&(ch!='2')
&&(ch!='3')&&(ch!='4')&&(ch!='5'));
yt=wherey();

/* Storing impulse response of FIR filter.*/
again :
gotoxy(1,yt+2);
printf("
");
gotoxy(1,yt+2);
printf("\nEnter file name to store FIR filter
coefficients >");
scanf("%s",file_name);
if(((stricmp("FFT.DAT",file_name))==0)||
((stricmp("temp.DAT",file_name))==0)||
((stricmp("IFFT.DAT",file_name))==0))
{
printf("This is a reserved file name. Use some


Nhờ tải bản gốc
Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status