-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_tm.m
30 lines (24 loc) · 1.14 KB
/
generate_tm.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function TM = generate_tm(M, N)
%generates a Transmission Matrix (TM) of a scattering medium
% M: height of the TM
% N: weight of the TM
% Adapted from https://github.com/comediaLKB/NMF_PR/blob/master/generate_tm.m
sz_grains = 4; %size of a single speckle grain
if mod(ceil(sqrt(M) / sz_grains), 2) == 0
n_grains = ceil(sqrt(M) / sz_grains); %number of speckle grains
else
n_grains = ceil(sqrt(M) / sz_grains)+1;
end
[Y, X] = meshgrid(1:n_grains, 1:n_grains);
pupil = (X-n_grains/2).^2 + (Y-n_grains/2).^2 < (n_grains/2)^2; %pupil definition
% A speckle is modeled by a random phase in the Fourier space
bruit = exp(2*1i*pi * rand(n_grains, n_grains, N, 'single'));
bruit = bruit .* single(pupil); %imaging system CTF/pupil func
% Fourier transform to go in the object space with zero padding
TM = zeros(M, N, 'single');
for j = 1:N
Temp = fft2(fftshift(padarray(bruit(:, :, j), ...
[sqrt(M)/2 - n_grains/2, sqrt(M)/2 - n_grains/2])));
TM(:, j) = 1/M * Temp(:);
end
end