├── ASM.m ├── ASMexample.m ├── ASMshift.m └── README.md /ASM.m: -------------------------------------------------------------------------------- 1 | %https://github.com/flyingwolfz/angular-spectrum-method 2 | %angular spectrum method of fast calculation of diffraction 角谱衍射计算 3 | %cut:output is set as the same size of input 要不要剪裁为原图大小 4 | %direction:direction of the propagation 传播方向 5 | %bandlimit:band-limit ASM 是否用带限角谱 6 | %quan:input of the complex wave field 输入复振幅 7 | %mu:zero padding size(How many times the size of the original complex wave 8 | % field) 填0为原图大小的几倍 9 | %z:distance 距离 10 | %pitch: pixel size 像素大小 11 | %lambda: wavelength 波长 12 | function[final] = ASM(cut,direction,bandlimit,quan,mu,z,pitch,lambda) 13 | 14 | [kuan,chang] = size(quan); 15 | a=mu*kuan; 16 | b=mu*chang; 17 | u0=1/b/pitch; 18 | v0=1/a/pitch; 19 | quan2=zeros(a,b); 20 | yy=-a/2+0.5:(a/2-1)+0.5; 21 | xx=-b/2+0.5:(b/2-1)+0.5; 22 | [x,y]=meshgrid(xx*u0,yy*v0); 23 | quan2(1+a/2-kuan/2:a/2+kuan/2,1+b/2-chang/2:b/2+chang/2)=quan; 24 | if(strcmp(direction,'forward')) 25 | trans=exp(1i*2*pi/lambda*z*sqrt(1-(lambda*x).^2-(lambda*y).^2)); 26 | else 27 | trans=exp(-1i*2*pi/lambda*z*sqrt(1-(lambda*x).^2-(lambda*y).^2)); 28 | end 29 | if(strcmp(bandlimit,'limit')) 30 | xlimit=1/sqrt((2*1/b/pitch*z)^2+1)/lambda; 31 | ylimit=1/sqrt((2*1/a/pitch*z)^2+1)/lambda; 32 | trans(abs(x)>xlimit)=0; 33 | trans(abs(y)>ylimit)=0; 34 | end 35 | 36 | final=fftshift(ifft2(fftshift(trans.*fftshift(fft2(fftshift(quan2)))))); 37 | 38 | if(strcmp(cut,'cut')) 39 | cutfinal=final(1+a/2-kuan/2:a/2+kuan/2,1+b/2-chang/2:b/2+chang/2); 40 | final=cutfinal; 41 | end 42 | 43 | end 44 | -------------------------------------------------------------------------------- /ASMexample.m: -------------------------------------------------------------------------------- 1 | %https://github.com/flyingwolfz/angular-spectrum-method 2 | clc; 3 | clear; 4 | p=zeros(1024,1024); 5 | p(256:768,256:768)=1; 6 | 7 | pitch=8*10^(-3); 8 | z=pitch*1024*200; 9 | pitch=8*10^(-3); 10 | lambda=638*10^(-6); 11 | 12 | final=ASM('cut','forward','nolimit',p,1,z,pitch,lambda); 13 | finallimit=ASM('cut','forward','limit',p,1,z,pitch,lambda); 14 | 15 | subplot(1,3,1) 16 | imshow(p); 17 | 18 | final=abs(final); 19 | final=final./max(max(final)); 20 | subplot(1,3,2) 21 | imshow(final); 22 | 23 | finallimit=abs(finallimit); 24 | finallimit=finallimit./max(max(finallimit)); 25 | subplot(1,3,3) 26 | imshow(finallimit); 27 | -------------------------------------------------------------------------------- /ASMshift.m: -------------------------------------------------------------------------------- 1 | %angular spectrum method of fast calculation of diffraction 角谱衍射计算 2 | %shift:fftshift 要不要加fftshift 3 | %cut:output is set as the same size of input 要不要剪裁为原图大小 4 | %direction:direction of the propagation 传播方向 5 | %bandlimit:band-limit ASM 是否用带限角谱 6 | %quan:input of the complex wave field 输入复振幅 7 | %mu:zero padding size(How many times the size of the original complex wave 8 | % field) 填0为原图大小的几倍 9 | %z:distance 距离 10 | %pitch: pixel size 像素大小 11 | %lambda: wavelength 波长 12 | %example:示例 quan=ASM(1,1,1,1,p,2,300,8*10^(-3),638*10^(-6)); 13 | function[final] = ASM(shift,cut,direction,bandlimit,quan,mu,z,pitch,lambda) 14 | 15 | [kuan,chang] = size(quan); 16 | % pitch=8*10^(-3); 17 | % lambda=638*10^(-6); 18 | a=mu*kuan; 19 | b=mu*chang; 20 | u0=1/b/pitch; 21 | v0=1/a/pitch; 22 | quan2=zeros(a,b); 23 | yy=-a/2+0.5:(a/2-1)+0.5; 24 | xx=-b/2+0.5:(b/2-1)+0.5; 25 | [x,y]=meshgrid(xx*u0,yy*v0); 26 | quan2(1+a/2-kuan/2:a/2+kuan/2,1+b/2-chang/2:b/2+chang/2)=quan; 27 | if(strcmp(direction,'forward')) 28 | trans=exp(1i*2*pi/lambda*z*sqrt(1-(lambda*x).^2-(lambda*y).^2)); 29 | else 30 | trans=exp(-1i*2*pi/lambda*z*sqrt(1-(lambda*x).^2-(lambda*y).^2)); 31 | end 32 | if(strcmp(bandlimit,'limit')) 33 | xlimit=1/sqrt((2*1/b/pitch*z)^2+1)/lambda; 34 | ylimit=1/sqrt((2*1/a/pitch*z)^2+1)/lambda; 35 | trans(abs(x)>xlimit)=0; 36 | trans(abs(y)>ylimit)=0; 37 | end 38 | if(strcmp(shift,'shift')) 39 | final=ifft2(trans.*fftshift(fft2(quan2))); 40 | else 41 | final=ifft2(trans.*(fft2(quan2))); 42 | end 43 | if(strcmp(cut,'cut')) 44 | cutfinal=final(1+a/2-kuan/2:a/2+kuan/2,1+b/2-chang/2:b/2+chang/2); 45 | final=cutfinal; 46 | end 47 | 48 | end 49 | 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # angular-spectrum-method 2 | simple matlab function of angular spectrum method of fast calculation of diffraction with band limitation setting, zero padding setting and so on. 3 | 4 | 简单的角谱衍射计算matlab函数,可以设置是否加入带限、是否填0等。 5 | 6 | function[final] = ASM(cut,direction,bandlimit,quan,mu,z,pitch,lambda) 7 | 8 | 9 | 10 | 11 | cut:output is set as the same size of input 要不要剪裁为原图大小 12 | 13 | direction:direction of the propagation 传播方向 14 | 15 | bandlimit:band-limited ASM 是否用带限角谱 16 | 17 | quan:input of the complex wave field 输入复振幅 18 | 19 | mu:zero padding size(How many times the size of the original complex wave field) 填0为原图大小的几倍 20 | 21 | z:distance 距离 22 | 23 | pitch: pixel size 像素大小 24 | 25 | lambda: wavelength 波长 26 | 27 | example,示例: 28 | 29 | finallimit=ASM('cut','forward','limit',p,1,z,pitch,lambda); 30 | 31 | finallimit=ASM('nocut','backward','nolimit',p,1,z,pitch,lambda); 32 | 33 | finallimit=ASMshift('shift','nocut','backward','nolimit',p,1,z,pitch,lambda); 34 | 35 | 36 | the band limitation method is from "Band-Limited Angular Spectrum Method for Numerical Simulation of Free-Space Propagation in Far and Near Fields" 37 | 38 | 带限角谱计算方法来自 "Band-Limited Angular Spectrum Method for Numerical Simulation of Free-Space Propagation in Far and Near Fields" 39 | --------------------------------------------------------------------------------