2

点源ジオメトリの空間で異なる振幅を持つ 2 つの波の重ね合わせを視覚化するための簡単なコードをいくつか書きました。これは khanacademy CS プラットフォームで動作します。http://www.khanacademy.org/cs/superposition/1245709541しかし、matlab で正確な現象を再現することはできません。私が得るのは騒々しいイメージだけです。これは乱数生成の違いと関係があるのでしょうか? random(0,1)(JS) と rand(matlab) の違いがわかりません。

ここにmatlabコードがあります

像面上の点 x,y に対する波動重ね合わせ関数

function S = Super(refamp,objamp,x,y,a,lambda)
    r1 = sqrt(a*a+x*x+y*y); %a is in z-axis
    S = refamp+(objamp*cos(2*pi*r1/(lambda/(10^6))));

テストスクリプト

close all;
clear all;
clc;

a=10;       %distance from source to image plane

width = 1024;
height =1024;

im = zeros(width); % the image
x=1;
y=1;
A0 = 3; % amplitude of reference wave
A1 = 1; % amplitude of object wave  A0>>A1: A0/A1>=3
lambda = 632; % wavelength in nanometers
% generate the superposition in space width*height at a along z-axis
for y=1:height
    for x=1:width
        s = Super(A0,A1,x-(width/2),y-(height/2),a, lambda);
        r=rand;
        if(r<(s/(A0+A1)))
            im(x,y) = 1;
    end
end

%display the image
figure
imshow(im,[])
title('test image')
4

2 に答える 2

2

主な問題は、スケールがずれているため、干渉パターンが見えないことです。すべての大きさ/距離をいじってみると、うまくいき、パターンを見ることができます。

2 番目の問題は、コードがベクトル化の恩恵を受けることです。これを以下に示しました。このようにすると、実行が劇的に高速化されます。

function Interference
a=1000 * 10^-9;       #% distance from source to image plane
width = 10000 * 10^-9;
height= 10000 * 10^-9;
size = 700;
A0 = 3; %# amplitude of reference wave
A1 = 1; %# amplitude of object wave  A0>>A1: A0/A1>=3
lambda = 632 * 10^-9; #% wavelength in nanometers

x=linspace(0,width,size); #% vector from 0 to width
y=linspace(0,height,size); #% vector from 0 to height
[X,Y]=meshgrid(x,y); #% matrices of x and y values at each position

s=Super(A0, A1, X-(width/2), Y-(height/2), a, lambda); #% size-by-size (700x700) 
r=rand(size); #% 700x700 matrix of random values on [0 1]

im = zeros(size);
im(r<(s/(A0+A1))) = 1; %# do this all at once instead of pixel-by-pixel

#% display the image
figure
imshow(im,[])
title('test image')
end #% end of function Interference


#% Super is now vectorized, so you can give it a matrix of values for x and y
function S = Super(refamp,objamp,x,y,a,lambda)
    r1 = sqrt(a.*a+x.*x+y.*y); #% dot notation: multiply element-wise
    S = refamp+(objamp*cos(2*pi*r1/(lambda)));
end #% end of function Super
于 2012-12-25T14:56:05.760 に答える
0
function i = Interference(width, height, sizeh,sizev,z)
% parameters explained
% width: is the horizontal pixel pitch in microns
% height: is the vertical pixel pitch in microns
% size is the width=height of the CCD in number of pixels
% z is distance from source to image plane
A0 = 3; %# amplitude of reference wave
A1 = 1; %# amplitude of object wave  A0>>A1: A0/A1>=3
lambda = 635 * 10^-9; % wavelength in nanometers

%the linspace was wrong
x=linspace(0,width*sizeh,sizeh); % vector from 0 to width of size 'size'
y=linspace(0,height*sizev,sizev); % vector from 0 to height of size 'size'
[X,Y]=meshgrid(x,y); % matrices of x and y values at each position

s=Super(A0, A1, X-((width*sizeh)/2), Y-((height*sizev)/2), z, lambda); % size-by-size (1024x1024) 
r=rand(size); % 1024x1024 matrix of random values on [0 1]
%i=s;
im = zeros(size);
im(r<(s/(A0+A1))) = 1; %# do this all at once instead of pixel-by-pixel
i=im;
end % end of function Interference


% Super is now vectorized, so you can give it a matrix of values for x and y
function S = Super(refamp,objamp,x,y,a,lambda)
    r1 = sqrt(a.*a+x.*x+y.*y); % dot notation: multiply element-wise
    S = refamp+(objamp*cos(2*pi*r1/(lambda)));
end % end of function Super

関数の使い方

width = 2.8 * 10^-6;
height= 2.8 * 10^-6; %pixel size
%  sizeh = 16; %image size in pixels
%  sizev = 16;
 sizeh = 1600; %image size in pixels
 sizev = 1200;
  int_z = 100*10^-3; % z dist in m
%  xes1 = 100;
 %xes2 = ;
 int_im = Interference(width,height,sizeh, sizev,int_z);
 int_im = int_im/max(max(int_im)); % normalize
 int_im = (int_im-0.5)*2; % enhance visualy

% display the image
figure
imshow(int_im,[])
于 2013-01-10T01:07:46.523 に答える