-
Notifications
You must be signed in to change notification settings - Fork 2
/
calc_fwd_1d.m
79 lines (63 loc) · 2.07 KB
/
calc_fwd_1d.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function [fwd]=calc_fwd_1d(model_depth,model_res,freq_array,err)
%
% Function which calculates the 1D MT data from a given 1D model using
% Waits recursion. The model should be in the following format:
%
% Depth (m) Resistivity (Ohm m)
% depth 1 resistivity 1
% depth 2 resistivity 2
% ... ...
%
% Depth is defined as the depth to the top of the layer!
%
% Usage: [fwd] = calc_fwd_1d(model_depth,model_res,freq_array,err)
%
% Inputs:
%
% model_depth: vector of depths (to top of layer)
% model_res: vector of resistivities of each layer
% freq_array: vector of frequencies
% err: Error level (adds % Gaussian noise)
%
% Outputs:
%
% fwd: A structure containing the apparent resistivity, phase, impedance
% and admittance for the 1D model.
%Set up constants given a frequency array
mu=4*pi*10^-7;
w=(2*pi).*freq_array;
sigma=1./model_res;
num=length(model_res);
nf = length(freq_array);
%Calculate the values for the halfspace
k(num,:)=sqrt(-1i.*mu.*w.*sigma(num));
C(num,:)=1./k(num,:);
%Recursion relation to calculate each layer
for n=(num-1):-1:1;
k(n,:)=sqrt(-1i.*w.*mu.*sigma(n));
C(n,:)=(1./k(n,:)).*(C(n+1,:).*k(n,:)+tanh(k(n,:).*(model_depth(n+1)-model_depth(n))))./ ...
(C(n+1,:).*k(n,:).*tanh(k(n,:).*(model_depth(n+1)-model_depth(n)))+1);
end
%Impedance, apparent resistivity and phase
Zxy=w.*mu.*-conj(C(1,:))*exp(1i*-pi/2);
C = conj(C(1,:));
% error_level={'0.05'};
% err=char(inputdlg({'Enter error level'},'Error',1,error_level));
% Zerror = str2num(err); if isempty(Zerror)==1; Zerror = 0; end
% Zer = real(Zxy).*randn(1,nf).*err;
% Zei = imag(Zxy).*randn(1,nf).*err;
if isnan(err)
a = 4-2*log(0.19);
err = exp(0.5*(log10(1./freq_array)-a))+0.01;
end
Zer = abs(Zxy).*randn(1,nf).*err;
Zei = abs(Zxy).*randn(1,nf).*err;
rZ = real(Zxy)+Zer;
iZ = imag(Zxy)+Zei;
Zxy = rZ + 1i.*iZ;
fwd.rho=(1./(w.*mu)).*(abs(Zxy)).^2;
fwd.phi=(180./pi).*atan2(imag(Zxy),real(Zxy));
fwd.Z = Zxy;
fwd.Zerr = abs(Zxy).*err;
fwd.C = C;
end