파일:Mehrfachspalt-Numerisch.png

문서 내용이 다른 언어로는 지원되지 않습니다.
위키백과, 우리 모두의 백과사전.

원본 파일(3,600 × 2,700 픽셀, 파일 크기: 278 KB, MIME 종류: image/png)

파일 설명

설명
Deutsch: Numerisch berechnete Intensitätsverteilung hinter einem Mehrfachspalt dargestellt als Hitzefeld. Nicht berücksichtigt wurde die Freiraumdämpfung. Deutlich zu erkennen die Hauptmaximas und dazu schwach die Nebenmaximas. Hier wurde zur weiteren Veranschaulichung kein endliches Gitter sondern eine Wellenfront mit begrenzter Weite eingezeichnet. In der Nähe des Gitter treten Alias-Effekte auf, die wegen der begrenzten Auflösung entstehen.
날짜
출처 자작
저자 Miessen
PNG 발전
InfoField
 
다이어그램MATLAB(으)로 제작되었습니다.
 config.ini 
;
; Some nice values
;

dim_x = 4000
dim_y = 2700
free_space_loss = 0
; gap width as factor to grating_distance
gap_width = 0.2
grating_count = 10
; grating_distance approx 2000 nm
; scaling_meter_per_px * 3/gap_width
grating_distance = 2250.e-9
offset_x = 600
; igonre...; 30 px per wave = 700.e-9 / 30px
; calculate near field / far field
scaling_meter_per_px = 150e-9
slit_width = 0
slit_iterations = 0
; 700 nm
wave_length = 700.e-9
소스 코드
InfoField

diffraction_grating.m code

#!/usr/bin/octave -qf
% \usr\bin\octave

%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Miessen 2014
%
%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  getParameters
%
%%%%%%%%%%%%%%%%%%%%%%%%%%

function setParameters(config)
  global parameters;
  
%  parameters.grating_distance = getConfigValue(config, "grating_width");
  parameters.dim_x = int32(getConfigValue(config, "dim_x"));
  parameters.dim_y = int32(getConfigValue(config, "dim_y"));
  parameters.free_space_loss = getConfigValue(config, "free_space_loss");
  parameters.gap_width = getConfigValue(config, "gap_width");
  parameters.grating_count = int32(getConfigValue(config, "grating_count"));
  parameters.grating_distance = getConfigValue(config, "grating_distance");
  parameters.offset_x = int32(getConfigValue(config, "offset_x"));
  parameters.scaling_meter_per_px = getConfigValue(config, "scaling_meter_per_px");
  parameters.wave_length = getConfigValue(config, "wave_length");
endfunction

%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  findGapPositions
%
%%%%%%%%%%%%%%%%%%%%%%%%%%

function gaps = findGapPositions(grating_distance, grating_count)
  if (grating_count < 2)
    error("grating_count too small");
  endif
  
  width = grating_distance * (double(grating_count)-1);
  gaps = [];
  for i = 0:(grating_count-1)
    gaps = [gaps (i*grating_distance-width/2)];
  endfor
endfunction

%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  gratingSignalStrength
%
%%%%%%%%%%%%%%%%%%%%%%%%%%

function amplitude = gratingSignalStrength(x, y, gaps, wave_length, free_space_loss)
% grating {gaps, sub_steps, gap_width }
% free_space_loss not implemented

  % calculate distances
  distances = [];
  for gap_pos = gaps
    distances = [ distances sqrt((y-gap_pos)^2 + x^2) ];
  endfor
  
  % calculate amplitudes
  c_amps = [];
  base_distance = sqrt(x^2 + y^2);
  
  for d = distances
%    delay = d - base_distance;
%    phase = 2. * pi * delay/wave_length;

    % amplitude phasor = c_amp
    residual = rem(d, wave_length);
    phase = 2. * pi * residual/wave_length;
    c_amp = complex(cos(phase), sin(phase));
    c_amp = c_amp / d; % free_space_loss ?? check - Integrate a slit!

    c_amps = [c_amps c_amp];
  endfor
  
  % calculate amplitude
  amplitude = abs(sum(c_amps))/length(gaps);

  % eliminate free_space_loss
  max_sum = sum(abs(c_amps))/length(gaps);
  amplitude = amplitude/max_sum;
  
endfunction

%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  slitSignalStrength
%
%%%%%%%%%%%%%%%%%%%%%%%%%%

function amplitude = slitSignalStrength(x, y, sub_steps, gap_width, wave_length, free_space_loss)

endfunction

%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  calculateDiffraction
%
%%%%%%%%%%%%%%%%%%%%%%%%%%

function amplitudes = calculateDiffraction(gaps )
  printf("Calculate Diffraction\n");


  global parameters;
  
  % Read globals
  dim_y = parameters.dim_y;
  dim_x = parameters.dim_x;
  scaling_meter_per_px = parameters.scaling_meter_per_px;
  offset_x = parameters.offset_x;
  wave_length = parameters.wave_length;
  free_space_loss = parameters.free_space_loss;

  % Calculate dimensions
  x_max = double(dim_x - offset_x - 1) * scaling_meter_per_px;
  y_width = double(dim_y - 1) * scaling_meter_per_px;
  y_max = y_width / 2.;
  y_min = -1. * y_max;
  
  % Initialize
  amplitudes = zeros(dim_y, dim_x - offset_x);
  
  
  for amp_pos_x = int32(1:(dim_x - offset_x))
    printf("%3d%%", 100 * amp_pos_x/(dim_x - offset_x));
    for amp_pos_y = int32(1:1:dim_y)
      x = double(amp_pos_x) * scaling_meter_per_px;
      y = y_min + double(amp_pos_y) * scaling_meter_per_px;
      
      amp = gratingSignalStrength(x, y, gaps, wave_length, free_space_loss );
      amplitudes(amp_pos_y, amp_pos_x) = amp; % row = y / column = x
    endfor
    printf("\b\b\b\b");
  endfor
  printf("Finished calculateDiffraction\n");
  
  

endfunction

%%%%%%%%%%%%%%%%%%%%
%
%  generateGrating
%
%%%%%%%%%%%%%%%%%%%%

function rgb = generateGrating(rgb)
  printf("Generate Grating\n");
  global parameters;
  
  dim_y = parameters.dim_y;
  grating_count = parameters.grating_count;
  grating_distance = parameters.grating_distance;
  gap_width = parameters.gap_width;
  offset_x = parameters.offset_x;
  scaling_meter_per_px = parameters.scaling_meter_per_px;

%//  gray = zeros(dim_y, offset_x);

  y_width = double(dim_y - 1) * scaling_meter_per_px;
  y_max = y_width / 2.;
  
  % even or odd 
  if ( round(rem(grating_count, 2)) != 1. )
    even_factor = 0.5; % grating_distance/2.;
  else
    even_factor = 0.;
  endif
  
  
  for y_px = int32(1:dim_y)
    y = double(y_px) * scaling_meter_per_px;
    stepper = y / grating_distance; % normalize
    sub_stepper = stepper + even_factor - round(stepper);
    % sub_stepper = rem(stepper,1);
    % stepper
    % odd: -0.5..+0.5
    % even: 0.0..1.0
    % Nachkommazahlen
  
  % sub_stepper +/- 0.5 * grating_distance around gap
    for x_px = offset_x-int32(double(offset_x)/40.):offset_x
      if(abs(sub_stepper) <= gap_width)
        rgb(y_px, x_px, :) = [0., 0., 0.];
      else
        rgb(y_px, x_px, :) = [0.8, 0.8, 0.8];
      endif
    endfor
  endfor
   
endfunction


%%%%%%%%%%%%%%%%%%%
%
%  generateLaser
%
%%%%%%%%%%%%%%%%%%%

function amplitudes = generateLaser()
  printf("Generate Laser\n");
  global parameters;

  dim_y = parameters.dim_y;
  grating_count = parameters.grating_count;
  grating_distance = parameters.grating_distance;
  offset_x = parameters.offset_x;
  scaling_meter_per_px = parameters.scaling_meter_per_px;
  
  y_width = double(dim_y - 1) * scaling_meter_per_px;
  y_min = -1. * y_width / 2.; 
  
  laser_width = grating_distance * double(grating_count)
  
  amplitudes = [];
 
  for y_px = int32(1:dim_y)
    y = y_min + double(y_px) * scaling_meter_per_px;
    
    if (abs(y) <= laser_width / 2.) 
      amplitudes = [amplitudes; ones(1,offset_x)];
    else
      amplitudes = [amplitudes; zeros(1,offset_x)];
    endif
  endfor
  
endfunction

%%%%%%%%%%%%%
%           %
%  M A I N  %
%           %
%%%%%%%%%%%%%

global parameters

begin_cputime = cputime();


printf("Including CSV library\n");
echo_csv_lib = 0;
source ("./lib/csv_lib.m");
printf("Including config library\n");
global echo_config_lib = 0;
source ("./lib/load_config_lib.m");

printf("Starting\n");


arg_list = argv ();

if (rows(arg_list) != 2);
  printf("wrong parameters, config file and output file needed.\n");
  exit();
endif

config_filename = arg_list{1};
output_filename = arg_list{2};

config = loadConfig(config_filename);

% config

setParameters(config);

gaps = findGapPositions(parameters.grating_distance, parameters.grating_count);

gaps

% dim
% step
% wavelength
%

printf("Dimensions:\n");

% Debug
%x_width = parameters.scaling_meter_per_px * double(parameters.dim_x)
%y_width = parameters.scaling_meter_per_px * double(parameters.dim_y)
%amp = gratingSignalStrength(x_width, 0, gaps, parameters.wave_length, parameters.free_space_loss );
%amp

diffractionMap = calculateDiffraction(gaps);
max(max(diffractionMap))
diffractionPowerMap = diffractionMap.^2;

laserMap = generateLaser();
laserPowerMap = laserMap.^2;


map = jet();

diffractionInd = gray2ind(diffractionPowerMap);
diffractionRgb = ind2rgb (diffractionInd, map);

laserInd = gray2ind(laserPowerMap);
laserRgb = ind2rgb (laserInd, map);



offsetRgb = generateGrating(laserRgb);

finalRgb = [offsetRgb diffractionRgb];
%finalRgb = [offsetRgb]; % debug



imwrite(finalRgb, output_filename, "png");


printf("Total cpu time: %f seconds\n", cputime()-begin_cputime);
printf("Finished\n");

Lib/csv_lib.m code

%
% GNU Octave library to write results to a csv file
%

1; % not a function file


%
% Add header to CSV file
%

function csvFile = addCsvFileHeader(csvFile, header)
  if (isfield(csvFile, "headerList") == true)
    csvFile.headerList = [csvFile.headerList; header];
  else
    csvFile.headerList = [header];
  endif
endfunction

%
% Add record to a structure CsvLine based on existing header
%

function csvLine = addCsvLineRecord(csvLine, header, value)

  csvLine.(header) = value; 

endfunction

%
% Close CSV file
%

function csvFile = closeCsvFile(csvFile)

  fclose(csvFile.fid);

  csvFile.isOpened = false;
endfunction

%
% Create a CSV line for this file
%

function csvLine = createCsvFileLine(csvFile)

  csvLine.headerList = csvFile.headerList;
  for header = csvLine.headerList'
    csvLine.(strtrim(header')) = "";
  endfor

endfunction

%
% Output values of a csv line
%

function csvLine = printCsvLine(csvLine)

  csvLine

endfunction

%
% Open CSV file
%

function csvFile = openCsvFile(filename)
  csvFile.filename = filename;
  
  % test if already exists
  
  csvFile.fid = fopen(csvFile.filename, "w");

  csvFile.isOpened = true;

endfunction

%
%
%

function csvLine = writeCsvFileHeader(csvFile)
  line = "";
  for header = csvFile.headerList'
    line = [line, strtrim(header')];
    line = [line, ","];
  endfor

  line = substr(line, 1, length(line)-1);
  fprintf(csvFile.fid, "%s\r\n", line);

endfunction

%
%
%

function csvLine = writeCsvLine(csvFile, csvLine)
  line = "";
  for header = csvLine.headerList'
    line = [line, csvLine.(strtrim(header'))];
    line = [line, ","];  
  endfor
  line = substr(line, 1, length(line)-1); % remove last comma
  fprintf(csvFile.fid, "%s\r\n", line);
endfunction

Lib/load_config_lib.m code

%
% GNU Octave library to load values from a config file
%

if(exist("echo_config_lib", "var") == 0)
  global echo_config_lib = 1;
endif



%
%
%

function value = getConfigValue(config, var_name)
  if (isfield(config, var_name) == false)
    printf("Error: \"%s\" missing in config file\n", var_name); 
    exit();
  endif
  [value, success] = str2num(config.(var_name));
  if(success != true)
    printf("Error: Converting \"%s\" failed!\n", var_name); 
    exit();
  endif
endfunction


%
%
%

function value = getConfigInt32(config, var_name)
  if (isfield(config, var_name) == false)
    printf("Error: \"%s\" missing in config file\n", var_name); 
    exit();
  endif
  [value, success] = str2double(config.(var_name));
  if(success != true)
    printf("Error: Converting \"%s\" failed!\n", var_name); 
    exit();
  endif
endfunction


%
%
%

function value = getConfigString(config, var_name)
  if (isfield(config, var_name) == false)
    printf("Error: \"%s\" missing in config file\n", var_name); 
    exit();
  endif
  value = config.(var_name);
endfunction


%
%
%

function arrayKeyValuePair = loadConfig(filename)
  % open file
  % while has next line
  % skip if blank
  % skip if comment
  % add key value pair to array
  
  global echo_config_lib;
  
  file = fopen (filename, "r");
  line = fgetl(file);
  lineNum = 1;
  while (ischar(line));
    if (echo_config_lib != 0)
      printf("Line %i: %s\n",lineNum, line);
    endif
    if (strcmp(line, "") == 0);
      if (strcmp(substr(line,1,1), ";") == 0);
        if(length(findstr(line, "="))== 0)
          printf("Error: Invalid line!\n");
          exit();
        endif
        key = substr(line, 1, findstr(line, "=")(1)-1);
        key = strtrim(key);
        value = substr(line
            , findstr(line, "=")(1)+1
            , length(line)-findstr(line, "=")(1) );
        value = strtrim(value);
        printf("key = %s\n", key);
        printf("value = %s\n", value);
        if(strcmp(key, "") != 0)
          printf("Error: Invalid key!\n");
          exit();
        endif
        if(isfield("arrayKeyValuePair", "key") != 0)
          printf("Error: Duplicate key!\n");
          exit();
        endif
      arrayKeyValuePair.(key) = value;
      else
        if (echo_config_lib != 0);
          printf("Comment\n");
        endif
      endif      
    else
      if (echo_config_lib != 0);
        printf("Blank line\n");
      endif
    endif
    line = fgetl(file);
    lineNum += 1;
  endwhile

  fclose(file);
endfunction



% INI format
% no white space at the beginning of a line
% empty lines allowed
% comment lines start with a semicolon
% key an value are seperated by a "="
% ascending white spaces are trimed from key
% prepending and ascending white spaces are trimed from values
% in case of duplicate values the first is valid
% crlf prefered, see RFC
%

라이선스

나는 아래 작품의 저작권자로서, 이 저작물을 다음과 같은 라이선스로 배포합니다:
Creative Commons CC-Zero 이 파일은 크리에이티브 커먼즈 CC0 1.0 보편적 퍼블릭 도메인 귀속에 따라 이용할 수 있습니다.
저작물에 본 권리증서를 첨부한 자는 법률에서 허용하는 범위 내에서 저작인접권 및 관련된 모든 권리들을 포함하여 저작권법에 따라 전 세계적으로 해당 저작물에 대해 자신이 갖는 일체의 권리를 포기함으로써 저작물을 퍼블릭 도메인으로 양도하였습니다. 저작권자의 허락을 구하지 않아도 이 저작물을 상업적인 목적을 포함하여 모든 목적으로 복제, 수정·변경, 배포, 공연·실연할 수 있습니다.

설명

이 파일이 나타내는 바에 대한 한 줄 설명을 추가합니다

이 파일에 묘사된 항목

다음을 묘사함

파일 역사

날짜/시간 링크를 클릭하면 해당 시간의 파일을 볼 수 있습니다.

날짜/시간섬네일크기사용자설명
현재2016년 9월 27일 (화) 04:452016년 9월 27일 (화) 04:45 판의 섬네일3,600 × 2,700 (278 KB)CmdrjamesonCompressed with pngout. Reduced by 100kB (26% decrease).
2014년 4월 19일 (토) 18:362014년 4월 19일 (토) 18:36 판의 섬네일3,600 × 2,700 (378 KB)Miessenfound a bug
2014년 4월 13일 (일) 23:582014년 4월 13일 (일) 23:58 판의 섬네일4,000 × 2,700 (393 KB)Miessensuper fine resolution to avoid aliasing
2014년 3월 28일 (금) 18:272014년 3월 28일 (금) 18:27 판의 섬네일1,100 × 900 (64 KB)Miessenfinal version
2014년 3월 16일 (일) 02:032014년 3월 16일 (일) 02:03 판의 섬네일450 × 450 (22 KB)MiessenUser created page with UploadWizard

다음 문서 1개가 이 파일을 사용하고 있습니다:

이 파일을 사용하고 있는 모든 위키의 문서 목록

다음 위키에서 이 파일을 사용하고 있습니다: