├── BackModelingFunction.m ├── FwdModelingFunction.m ├── LICENCE ├── README.md ├── RTM.m ├── surec.mat └── velocityModel.mat /BackModelingFunction.m: -------------------------------------------------------------------------------- 1 | function [model, BckwdSnapshot] = BackModelingFunction(V,data,nz,nx,dx,nt,dt,M,am,N) 2 | 3 | %%Copyright 2020 Emiro Chica Quiñones - echica@terralica.com 4 | % 5 | %Licensed under the Apache License, Version 2.0 (the "License"); 6 | %you may not use this file except in compliance with the License. 7 | %You may obtain a copy of the License at 8 | % 9 | % http://www.apache.org/licenses/LICENSE-2.0 10 | % 11 | %Unless required by applicable law or agreed to in writing, software 12 | %distributed under the License is distributed on an "AS IS" BASIS, 13 | %WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | %See the License for the specific language governing permissions and 15 | %limitations under the License. 16 | 17 | %% Definition of imput variables 18 | % rw(nt) Ricker wavelet 19 | % v(nz,nx) velocity model 20 | % nx number of horizontal samples 21 | % nz number of depth samples 22 | % nt numer of time samples 23 | % dx horizontal distance per sample in meters (horizontal grid interval) 24 | % dz depth distance per sample in meters (vertical grid interval) 25 | % dt time difference per sample in miliseconds 26 | % ixs x shot position 27 | % izs z shot position 28 | % M order of space derivative 29 | % am SDF coefficients 30 | % N grids number in transition area 31 | % r 'r=v/t' 32 | 33 | % Initialization of data storage arrays 34 | [nzz,nxx] = size(V); 35 | 36 | fdm = zeros(nzz,nxx,3); % this matrix stores the values of the wave field 37 | fdmII = zeros(nzz,nxx,3); % this matrix stores the values of the wave field y zone II 38 | BckwdSnapshot = zeros(nzz,nxx,nt); % 'snapshot' matrix stores the values of the wave field para 39 | % for each time increment 40 | 41 | %% Wave modeling in time direction 42 | 43 | fdm(2*M+N+1,2*M+N+1:end-(2*M+N),1) = data(:,nt); 44 | fdm(2*M+N+1,2*M+N+1:end-(2*M+N),2) = data(:,nt-1); 45 | fdm(2*M+N+1,2*M+N+1:end-(2*M+N),3) = data(:,nt-2); 46 | 47 | %% ========== matrix indices ========== 48 | 49 | % Zone I & II for the calculation of Finite Difference with higher order 50 | % wave equation 2M 51 | 52 | iz = 2*M+1:nzz - (2*M); 53 | ix = 2*M+1:nxx - (2*M); 54 | 55 | %% Finite Difference Wave Field Calculation with Higher Order Wave Equation 2M 56 | % Taken from: Yan, Liu y Zhang. "Prestack reverse-time migration with a time space 57 | % domain adaptive high-order staggered-grid finite difference method" 58 | % Exploration Geophysics, 2013, 44. 59 | % DOI: https://doi.org/10.1071/EG12047 60 | 61 | % coefficient of the wave equation 62 | load('velocityModel') 63 | aa = (V*dt/dx).^2; 64 | rr=V*dt/dx; 65 | 66 | for it = (nt-1):-1:1 % time iteration cycle 67 | 68 | % Finite differences in zones I and II 69 | % Wave field calculation by Finite Difference 70 | % with second order wave equation in one direction 71 | % (Clayton and Engquist, 1977) 72 | % Taken from: Liu, Ding y Sen, 73 | % "Comparisions between the hybrid ABC and the PML method" 74 | % SEG Annual Meeting, 2011 | https://doi.org/10.1190/1.3627807 75 | % Equation (4), pag 78 Emiro Chica RTM thesis 76 | 77 | fdm_a = zeros(nzz,nxx); 78 | fdm_b = zeros(nzz,nxx); 79 | fdm_c = zeros(nzz,nxx); 80 | p1 = zeros(nzz,nxx); 81 | p2 = zeros(nzz,nxx); 82 | 83 | fdm_a(iz,ix)=2*fdm(iz,ix,2)-fdm(iz,ix,1); 84 | 85 | for i=1:M % index in the 'x' direction 86 | for j=1:M % index in the 'z' direction 87 | p1(iz,ix)=(fdm(iz+i+j-1,ix,2)-fdm(iz+i-j,ix,2))-(fdm(iz-i+j,ix,2)-fdm(iz-i-j+1,ix,2)); 88 | fdm_b(iz,ix)=fdm_b(iz,ix)+am(i)*am(j)*p1(iz,ix); 89 | end 90 | end 91 | 92 | for i=1:M % index in the 'x' direction 93 | for j=1:M % index in the 'z' direction 94 | p2(iz,ix)=(fdm(iz,ix+i+j-1,2)-fdm(iz,ix+i-j,2))-(fdm(iz,ix-i+j,2)-fdm(iz,ix-i-j+1,2)); 95 | fdm_c(iz,ix)=fdm_c(iz,ix)+am(i)*am(j)*p2(iz,ix); 96 | end 97 | end 98 | 99 | fdm(iz,ix,3) = fdm_a(iz,ix)+aa(iz,ix).*fdm_b(iz,ix)+aa(iz,ix).*fdm_c(iz,ix); 100 | 101 | % Finite differences in zones II and III 102 | % Wave field calculation by Finite Difference 103 | % with second order wave equation in one direction 104 | % (Clayton and Engquist, 1977) 105 | % Taken from: Liu, Ding y Sen, 106 | % "Comparisions between the hybrid ABC and the PML method" 107 | % SEG Annual Meeting, 2011 | https://doi.org/10.1190/1.3627807 108 | % Equation (2) and (4), pag 78 Emiro Chica RTM thesis 109 | 110 | fdmII(2*M+N+1:2*M+N+nz,2*M+N+1:2*M+N+nx,3) = fdm(2*M+N+1:2*M+N+nz,2*M+N+1:2*M+N+nx,3); 111 | 112 | % Zone II 113 | 114 | % left strip 115 | 116 | for i = 2*M+N:-1:2*M+2 % x 117 | 118 | for j = 2*M+N+1:2*M+N+nz % z 119 | 120 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*(fdmII(j,i+1,3) - (fdmII(j,i+1,1) - fdmII(j,i,1))) - ... 121 | ((fdmII(j,i+1,1)+fdmII(j,i+1,3)-2*fdmII(j,i+1,2))+(fdmII(j,i,1)-2*fdmII(j,i,2))) + ... 122 | (0.5*rr(j,i)^2)*((fdmII(j+1,i+1,2)+fdmII(j-1,i+1,2)-2*fdmII(j,i+1,2)) + ... 123 | (fdmII(j+1,i,2)+fdmII(j-1,i,2)-2*fdmII(j,i,2)))); 124 | 125 | end 126 | 127 | end 128 | 129 | % right strip 130 | for i = 2*M+N+nx+1:2*M+N+nx+N-1 % x 131 | 132 | for j = 2*M+N+1:2*M+N+nz % z 133 | 134 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*(fdmII(j,i-1,3) - (fdmII(j,i-1,1) - fdmII(j,i,1))) - ... 135 | ((fdmII(j,i-1,1)+fdmII(j,i-1,3)-2*fdmII(j,i-1,2))+(fdmII(j,i,1)-2*fdmII(j,i,2))) + ... 136 | (0.5*rr(j,i)^2)*((fdmII(j+1,i-1,2)+fdmII(j-1,i-1,2)-2*fdmII(j,i-1,2)) + ... 137 | (fdmII(j+1,i,2)+fdmII(j-1,i,2)-2*fdmII(j,i,2)))); 138 | 139 | end 140 | 141 | end 142 | 143 | % top strip 144 | 145 | for j = 2*M+N:-1:2*M+2 % z |for j = nzz - (2*M+N-1):nzz-(2*M+1) % z | for j = nzz - (2*M+N-1):nzz-(2*M+1) 146 | 147 | for i = 2*M+1:2*M+N+nx+N %2*M+N+1-f:2*M+N+nx+f % x | for i = 2*M+2:nxx - (2*M+1) % x 1 for i = 2*M+N+1:nxx - (2*M+N) 148 | 149 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*(fdmII(j+1,i,3) - (fdmII(j+1,i,1) - fdmII(j,i,1))) - ... 150 | ((fdmII(j+1,i,1)+fdmII(j+1,i,3)-2*fdmII(j+1,i,2))+(fdmII(j,i,1)-2*fdmII(j,i,2))) + ... 151 | (0.5*rr(j,i)^2)*((fdmII(j+1,i-1,2)+fdmII(j+1,i+1,2)-2*fdmII(j+1,i,2)) + ... 152 | (fdmII(j,i-1,2)+fdmII(j,i+1,2)-2*fdmII(j,i,2)))); 153 | 154 | end 155 | 156 | end 157 | 158 | % bottom strip 159 | 160 | for j = 2*M+N+nz+1:2*M+N+nz+N-1 % z |for j = nzz - (2*M+N-1):nzz-(2*M+1) % z | for j = nzz - (2*M+N-1):nzz-(2*M+1) 161 | 162 | for i = 2*M+1:2*M+N+nx+N %2*M+N+1-f:2*M+N+nx+f % x | for i = 2*M+2:nxx - (2*M+1) % x 1 for i = 2*M+N+1:nxx - (2*M+N) 163 | 164 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*(fdmII(j-1,i,3) - (fdmII(j-1,i,1) - fdmII(j,i,1))) - ... 165 | ((fdmII(j-1,i,1)+fdmII(j-1,i,3)-2*fdmII(j-1,i,2))+(fdmII(j,i,1)-2*fdmII(j,i,2))) + ... 166 | (0.5*rr(j,i)^2)*((fdmII(j-1,i+1,2)+fdmII(j-1,i-1,2)-2*fdmII(j-1,i,2)) + ... 167 | (fdmII(j,i+1,2)+fdmII(j,i-1,2)-2*fdmII(j,i,2)))); 168 | 169 | end 170 | 171 | end 172 | 173 | % Lower left corner 174 | 175 | for i = 2*M+N:-1:2*M+2 % x 176 | 177 | for j = nzz-(2*M+N-1):(nzz -(2*M+1)); % z 178 | 179 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*((fdmII(j-1,i+1,3) + fdmII(j-1,i-1,2)) - fdmII(j,i,2)) + ... 180 | (fdmII(j-1,i+1,2)+fdmII(j,i,2)-fdmII(j-1,i+1,3))); 181 | 182 | 183 | end 184 | end 185 | 186 | % Upper left corner 187 | 188 | for i = 2*M+N:-1:2*M+2 % x 189 | 190 | for j = 2*M+N:-1:2*M+2; % z 191 | 192 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*((fdmII(j+1,i+1,3) + fdmII(j+1,i-1,2)) - fdmII(j,i,2)) + ... 193 | (fdmII(j+1,i+1,2)+fdmII(j,i,2)-fdmII(j+1,i+1,3))); 194 | end 195 | end 196 | 197 | % Lower right corner 198 | 199 | for i = 2*M+N+nx+1:2*M+N+nx+N-1 % x 200 | 201 | for j = nzz-(2*M+N-1):(nzz -(2*M+1)); % z 202 | 203 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*((fdmII(j-1,i-1,3) + fdmII(j-1,i+1,2)) - fdmII(j,i,2)) + ... 204 | (fdmII(j-1,i-1,2)+fdmII(j,i,2)-fdmII(j-1,i-1,3))); 205 | 206 | end 207 | end 208 | 209 | % Rigth upper corner 210 | 211 | for i = nxx - (2*M+N-1):nxx - (2*M+1) % x 212 | 213 | for j = 2*M+N:-1:2*M+2; % z 214 | 215 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*((fdmII(j+1,i-1,3) + fdmII(j+1,i+1,2)) - fdmII(j,i,2)) + ... 216 | (fdmII(j+1,i-1,2)+fdmII(j,i,2)-fdmII(j+1,i-1,3))); 217 | 218 | end 219 | end 220 | 221 | % Zone III 222 | 223 | % Left contour 224 | 225 | i = 2*M+1;% x 226 | 227 | for j = 2*M+1:2*M+N+nz+N; % z 228 | 229 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*(fdmII(j,i+1,3) + fdmII(j,i+1,2) - fdmII(j,i,2)) + ... 230 | (fdmII(j,i+1,2)+fdmII(j,i,2)-fdmII(j,i+1,3))); 231 | 232 | end 233 | 234 | % Right contour 235 | 236 | i = 2*M+N+nx+N; % x 237 | 238 | for j = 2*M+1:2*M+N+nz+N; % z 239 | 240 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*(fdmII(j,i-1,3) + fdmII(j,i-1,2) - fdmII(j,i,2)) + ... 241 | (fdmII(j,i-1,2)+fdmII(j,i,2)-fdmII(j,i-1,3))); 242 | 243 | end 244 | 245 | % Bottom contour 246 | 247 | j = 2*M+N+nz+N; % z 248 | 249 | for i = 2*M+2:2*M+N+nx+N-1 % x 250 | 251 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*(fdmII(j-1,i,3) + fdmII(j-1,i,2) - fdmII(j,i,2)) + ... 252 | (fdmII(j-1,i,2)+fdmII(j,i,2)-fdmII(j-1,i,3))); 253 | 254 | end 255 | 256 | % Top contour 257 | 258 | j = 2*M+1; % z 259 | 260 | for i = 2*M+2:2*M+N+nx+N-1 % x 261 | 262 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*(fdmII(j+1,i,3) + fdmII(j+1,i,2) - fdmII(j,i,2)) + ... 263 | (fdmII(j+1,i,2)+fdmII(j,i,2)-fdmII(j+1,i,3))); 264 | 265 | end 266 | 267 | w = zeros(N,1); % w(i) son pesos que varian de 0 a 1 268 | 269 | w(N) = 0; 270 | 271 | for i=N-1:-1:1 272 | w(i) = w(i+1)+1/(N-1); 273 | end 274 | 275 | % Left strip 276 | 277 | for i=N:-1:1 278 | for j=2*M+1:2*M+N+nz+N 279 | fdm(j,2*M+i,3)=(1-w(i))*fdm(j,2*M+i,3)+w(i)*fdmII(j,2*M+i,3); 280 | end 281 | end 282 | 283 | % Right strip 284 | 285 | for i=N:-1:1 286 | for j=2*M+1:2*M+N+nz+N 287 | fdm(j,2*M+N+nx+i,3)=(1-w(i))*fdm(j,2*M+N+nx+i,3)+w(i)*fdmII(j,2*M+N+nx+i,3); 288 | end 289 | end 290 | 291 | % Bottom strip 292 | 293 | for i=N:-1:1 294 | for j=2*M+N+1:2*M+N+nx 295 | fdm(2*M+N+nz+i,j,3)=(1-w(i))*fdm(2*M+N+nz+i,j,3)+w(i)*fdmII(2*M+N+nz+i,j,3); 296 | end 297 | end 298 | 299 | % Top strip 300 | 301 | for i=N:-1:1 302 | for j=2*M+N+1:2*M+N+nx 303 | fdm(2*M+i,j,3)=(1-w(i))*fdm(2*M+i,j,3)+w(i)*fdmII(2*M+i,j,3); 304 | end 305 | end 306 | 307 | % update fdm (wave field) for the next iteration in time 308 | 309 | fdm(:,:,1) = fdm(:,:,2); 310 | fdm(:,:,2) = fdm(:,:,3); 311 | fdmII(:,:,1) = fdmII(:,:,2); 312 | fdmII(:,:,2) = fdmII(:,:,3); 313 | fdm(2*M+N+1,2*M+N+1:end-(2*M+N),2) = data(:,it); % insert surface boundary wavefield 314 | 315 | % update data 316 | 317 | BckwdSnapshot(:,:,it) = fdm(:,:,2); 318 | model = fdm(:,:,1); 319 | end 320 | 321 | 322 | 323 | end % ends time loop 324 | -------------------------------------------------------------------------------- /FwdModelingFunction.m: -------------------------------------------------------------------------------- 1 | function [data, FwdSnapshot] = FwdModelingFunction(V,rw,nz,~,nx,dx,nt,dt,ixs,izs,M,am,N) 2 | 3 | %%Copyright 2020 Emiro Chica Quiñones - echica@terralica.com 4 | % 5 | %Licensed under the Apache License, Version 2.0 (the "License"); 6 | %you may not use this file except in compliance with the License. 7 | %You may obtain a copy of the License at 8 | % 9 | % http://www.apache.org/licenses/LICENSE-2.0 10 | % 11 | %Unless required by applicable law or agreed to in writing, software 12 | %distributed under the License is distributed on an "AS IS" BASIS, 13 | %WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | %See the License for the specific language governing permissions and 15 | %limitations under the License. 16 | 17 | 18 | %% Definition of imput variables 19 | % rw(nt) Source wavelet 20 | % v(nz,nx) velocity model 21 | % nx number of horizontal samples 22 | % nz number of depth samples 23 | % nt numer of time samples 24 | % dx horizontal distance per sample 25 | % dz depth distance per sample 26 | % dt time difference per sample 27 | % ixs x shot position 28 | % izs z shot position 29 | % M order of space derivative 30 | % am SDF coefficients 31 | % N grids number in transition area 32 | 33 | % Initialization of data storage arrays 34 | [nzz,nxx] = size(V); 35 | % this matrix stores the values of the wave field in surface 36 | data = zeros(nxx,nt); 37 | % this matrix stores the values of the wave field 38 | fdm = zeros(nzz,nxx,3); 39 | % this matrix stores the values of the wave field y zone II 40 | fdmII = zeros(nzz,nxx,3); 41 | 42 | %% Wave modeling in time direction 43 | 44 | % Inclusion of the source function 'rw (t)' in the wavefield 45 | fdm(izs+2*M+N,ixs+2*M+N,2) = rw(1); 46 | 47 | for g = 1:nx 48 | % The array 'data' stores the values to form the surface records 49 | data(g+2*M+N,1) = fdm(2*M+N+surec(g),2*M+N+g,2); 50 | end 51 | 52 | FwdSnapshot = zeros(nzz,nxx,nt); % 'FwdSnapshot' matrix stores the values of 53 | % the wave field para for each time increment 54 | 55 | %% ========== matrix indices ========== 56 | 57 | % Zone I & II for the calculation of Finite Difference with higher order 58 | % wave equation 2M 59 | 60 | iz = 2*M+1:nzz - (2*M); 61 | ix = 2*M+1:nxx - (2*M); 62 | 63 | %% Finite Difference Wave Field Calculation with Higher Order Wave Equation 2M 64 | % Taken from: Yan, Liu y Zhang. "Prestack reverse-time migration with a time space 65 | % domain adaptive high-order staggered-grid finite difference method" 66 | % Exploration Geophysics, 2013, 44. 67 | % DOI: https://doi.org/10.1071/EG12047 68 | 69 | % coefficient of the wave equation 70 | load('velocityModel') 71 | aa = (V*dt/dx).^2; 72 | rr=V*dt/dx; 73 | 74 | for it = 2:nt % % time iteration cycle 75 | 76 | % Finite differences in zones I and II 77 | % Wave field calculation by Finite Difference 78 | % with second order wave equation in one direction 79 | % (Clayton and Engquist, 1977) 80 | % Taken from: Liu, Ding y Sen, 81 | % "Comparisions between the hybrid ABC and the PML method" 82 | % SEG Annual Meeting, 2011 | https://doi.org/10.1190/1.3627807 83 | % Equation (4), pag 78 Emiro Chica RTM thesis 84 | 85 | fdm_a = zeros(nzz,nxx); 86 | fdm_b = zeros(nzz,nxx); 87 | fdm_c = zeros(nzz,nxx); 88 | p1 = zeros(nzz,nxx); 89 | p2 = zeros(nzz,nxx); 90 | 91 | fdm_a(iz,ix)=2*fdm(iz,ix,2)-fdm(iz,ix,1); 92 | 93 | for i=1:M % indice en la direccion 'x' 94 | for j=1:M % indice en la direccion 'z' 95 | p1(iz,ix)=(fdm(iz+i+j-1,ix,2)-fdm(iz+i-j,ix,2))-(fdm(iz-i+j,ix,2)-fdm(iz-i-j+1,ix,2)); 96 | fdm_b(iz,ix)=fdm_b(iz,ix)+am(i)*am(j)*p1(iz,ix); 97 | end 98 | end 99 | 100 | for i=1:M % indice en la direccion 'x' 101 | for j=1:M % indice en la direccion 'z' 102 | p2(iz,ix)=(fdm(iz,ix+i+j-1,2)-fdm(iz,ix+i-j,2))-(fdm(iz,ix-i+j,2)-fdm(iz,ix-i-j+1,2)); 103 | fdm_c(iz,ix)=fdm_c(iz,ix)+am(i)*am(j)*p2(iz,ix); 104 | end 105 | end 106 | 107 | fdm(iz,ix,3) = fdm_a(iz,ix)+aa(iz,ix).*fdm_b(iz,ix)+aa(iz,ix).*fdm_c(iz,ix); 108 | 109 | % Finite differences in zones II and III 110 | % Wave field calculation by Finite Difference 111 | % with second order wave equation in one direction 112 | % (Clayton and Engquist, 1977) 113 | % Taken from: Liu, Ding y Sen, 114 | % "Comparisions between the hybrid ABC and the PML method" 115 | % SEG Annual Meeting, 2011 | https://doi.org/10.1190/1.3627807 116 | % Equation (2) and (4), pag 78 Emiro Chica RTM thesis 117 | 118 | fdmII(2*M+N+1:2*M+N+nz,2*M+N+1:2*M+N+nx,3) = fdm(2*M+N+1:2*M+N+nz,2*M+N+1:2*M+N+nx,3); 119 | 120 | % Zone II 121 | 122 | % left strip 123 | 124 | for i = 2*M+N:-1:2*M+2 % x 125 | 126 | for j = 2*M+N+1:2*M+N+nz % z 127 | 128 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*(fdmII(j,i+1,3) - (fdmII(j,i+1,1) - fdmII(j,i,1))) - ... 129 | ((fdmII(j,i+1,1)+fdmII(j,i+1,3)-2*fdmII(j,i+1,2))+(fdmII(j,i,1)-2*fdmII(j,i,2))) + ... 130 | (0.5*rr(j,i)^2)*((fdmII(j+1,i+1,2)+fdmII(j-1,i+1,2)-2*fdmII(j,i+1,2)) + ... 131 | (fdmII(j+1,i,2)+fdmII(j-1,i,2)-2*fdmII(j,i,2)))); 132 | 133 | end 134 | 135 | end 136 | 137 | % right strip 138 | for i = 2*M+N+nx+1:2*M+N+nx+N-1 % x 139 | 140 | for j = 2*M+N+1:2*M+N+nz % z 141 | 142 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*(fdmII(j,i-1,3) - (fdmII(j,i-1,1) - fdmII(j,i,1))) - ... 143 | ((fdmII(j,i-1,1)+fdmII(j,i-1,3)-2*fdmII(j,i-1,2))+(fdmII(j,i,1)-2*fdmII(j,i,2))) + ... 144 | (0.5*rr(j,i)^2)*((fdmII(j+1,i-1,2)+fdmII(j-1,i-1,2)-2*fdmII(j,i-1,2)) + ... 145 | (fdmII(j+1,i,2)+fdmII(j-1,i,2)-2*fdmII(j,i,2)))); 146 | 147 | end 148 | 149 | end 150 | 151 | % top strip 152 | 153 | for j = 2*M+N:-1:2*M+2 % z |for j = nzz - (2*M+N-1):nzz-(2*M+1) % z | for j = nzz - (2*M+N-1):nzz-(2*M+1) 154 | 155 | for i = 2*M+1:2*M+N+nx+N %2*M+N+1-f:2*M+N+nx+f % x | for i = 2*M+2:nxx - (2*M+1) % x 1 for i = 2*M+N+1:nxx - (2*M+N) 156 | 157 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*(fdmII(j+1,i,3) - (fdmII(j+1,i,1) - fdmII(j,i,1))) - ... 158 | ((fdmII(j+1,i,1)+fdmII(j+1,i,3)-2*fdmII(j+1,i,2))+(fdmII(j,i,1)-2*fdmII(j,i,2))) + ... 159 | (0.5*rr(j,i)^2)*((fdmII(j+1,i-1,2)+fdmII(j+1,i+1,2)-2*fdmII(j+1,i,2)) + ... 160 | (fdmII(j,i-1,2)+fdmII(j,i+1,2)-2*fdmII(j,i,2)))); 161 | 162 | end 163 | 164 | end 165 | 166 | % bottom strip 167 | 168 | for j = 2*M+N+nz+1:2*M+N+nz+N-1 % z |for j = nzz - (2*M+N-1):nzz-(2*M+1) % z | for j = nzz - (2*M+N-1):nzz-(2*M+1) 169 | 170 | for i = 2*M+1:2*M+N+nx+N %2*M+N+1-f:2*M+N+nx+f % x | for i = 2*M+2:nxx - (2*M+1) % x 1 for i = 2*M+N+1:nxx - (2*M+N) 171 | 172 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*(fdmII(j-1,i,3) - (fdmII(j-1,i,1) - fdmII(j,i,1))) - ... 173 | ((fdmII(j-1,i,1)+fdmII(j-1,i,3)-2*fdmII(j-1,i,2))+(fdmII(j,i,1)-2*fdmII(j,i,2))) + ... 174 | (0.5*rr(j,i)^2)*((fdmII(j-1,i+1,2)+fdmII(j-1,i-1,2)-2*fdmII(j-1,i,2)) + ... 175 | (fdmII(j,i+1,2)+fdmII(j,i-1,2)-2*fdmII(j,i,2)))); 176 | 177 | end 178 | 179 | end 180 | 181 | % Lower left corner 182 | 183 | for i = 2*M+N:-1:2*M+2 % x 184 | 185 | for j = nzz-(2*M+N-1):(nzz -(2*M+1)); % z 186 | 187 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*((fdmII(j-1,i+1,3) + fdmII(j-1,i-1,2)) - fdmII(j,i,2)) + ... 188 | (fdmII(j-1,i+1,2)+fdmII(j,i,2)-fdmII(j-1,i+1,3))); 189 | 190 | 191 | end 192 | end 193 | 194 | % Upper left corner 195 | 196 | for i = 2*M+N:-1:2*M+2 % x 197 | 198 | for j = 2*M+N:-1:2*M+2; % z 199 | 200 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*((fdmII(j+1,i+1,3) + fdmII(j+1,i-1,2)) - fdmII(j,i,2)) + ... 201 | (fdmII(j+1,i+1,2)+fdmII(j,i,2)-fdmII(j+1,i+1,3))); 202 | end 203 | end 204 | 205 | % Lower right corner 206 | 207 | for i = 2*M+N+nx+1:2*M+N+nx+N-1 % x 208 | 209 | for j = nzz-(2*M+N-1):(nzz -(2*M+1)); % z 210 | 211 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*((fdmII(j-1,i-1,3) + fdmII(j-1,i+1,2)) - fdmII(j,i,2)) + ... 212 | (fdmII(j-1,i-1,2)+fdmII(j,i,2)-fdmII(j-1,i-1,3))); 213 | 214 | end 215 | end 216 | 217 | % Rigth upper corner 218 | 219 | for i = nxx - (2*M+N-1):nxx - (2*M+1) % x 220 | 221 | for j = 2*M+N:-1:2*M+2; % z 222 | 223 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*((fdmII(j+1,i-1,3) + fdmII(j+1,i+1,2)) - fdmII(j,i,2)) + ... 224 | (fdmII(j+1,i-1,2)+fdmII(j,i,2)-fdmII(j+1,i-1,3))); 225 | 226 | end 227 | end 228 | 229 | % Zone III 230 | 231 | % Left contour 232 | 233 | i = 2*M+1;% x 234 | 235 | for j = 2*M+1:2*M+N+nz+N; % z 236 | 237 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*(fdmII(j,i+1,3) + fdmII(j,i+1,2) - fdmII(j,i,2)) + ... 238 | (fdmII(j,i+1,2)+fdmII(j,i,2)-fdmII(j,i+1,3))); 239 | 240 | end 241 | 242 | % Right contour 243 | 244 | i = 2*M+N+nx+N; % x 245 | 246 | for j = 2*M+1:2*M+N+nz+N; % z 247 | 248 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*(fdmII(j,i-1,3) + fdmII(j,i-1,2) - fdmII(j,i,2)) + ... 249 | (fdmII(j,i-1,2)+fdmII(j,i,2)-fdmII(j,i-1,3))); 250 | 251 | end 252 | 253 | % Bottom contour 254 | 255 | j = 2*M+N+nz+N; % z 256 | 257 | for i = 2*M+2:2*M+N+nx+N-1 % x 258 | 259 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*(fdmII(j-1,i,3) + fdmII(j-1,i,2) - fdmII(j,i,2)) + ... 260 | (fdmII(j-1,i,2)+fdmII(j,i,2)-fdmII(j-1,i,3))); 261 | 262 | end 263 | 264 | % Top contour 265 | 266 | j = 2*M+1; % z 267 | 268 | for i = 2*M+2:2*M+N+nx+N-1 % x 269 | 270 | fdmII(j,i,3) = 1/(1 + rr(j,i))*(rr(j,i)*(fdmII(j+1,i,3) + fdmII(j+1,i,2) - fdmII(j,i,2)) + ... 271 | (fdmII(j+1,i,2)+fdmII(j,i,2)-fdmII(j+1,i,3))); 272 | 273 | end 274 | 275 | w = zeros(N,1); % w(i) son pesos que varian de 0 a 1 276 | 277 | w(N) = 0; 278 | 279 | for i=N-1:-1:1 280 | w(i) = w(i+1)+1/(N-1); 281 | end 282 | 283 | % Left strip 284 | 285 | for i=N:-1:1 286 | for j=2*M+1:2*M+N+nz+N 287 | fdm(j,2*M+i,3)=(1-w(i))*fdm(j,2*M+i,3)+w(i)*fdmII(j,2*M+i,3); 288 | end 289 | end 290 | 291 | % Right strip 292 | 293 | for i=N:-1:1 294 | for j=2*M+1:2*M+N+nz+N 295 | fdm(j,2*M+N+nx+i,3)=(1-w(i))*fdm(j,2*M+N+nx+i,3)+w(i)*fdmII(j,2*M+N+nx+i,3); 296 | end 297 | end 298 | 299 | % Bottom strip 300 | 301 | for i=N:-1:1 302 | for j=2*M+N+1:2*M+N+nx 303 | fdm(2*M+N+nz+i,j,3)=(1-w(i))*fdm(2*M+N+nz+i,j,3)+w(i)*fdmII(2*M+N+nz+i,j,3); 304 | end 305 | end 306 | 307 | % Top strip 308 | 309 | for i=N:-1:1 310 | for j=2*M+N+1:2*M+N+nx 311 | fdm(2*M+i,j,3)=(1-w(i))*fdm(2*M+i,j,3)+w(i)*fdmII(2*M+i,j,3); 312 | end 313 | end 314 | 315 | % update fdm (wave field) for the next iteration in time 316 | 317 | fdm(:,:,1) = fdm(:,:,2); 318 | fdm(:,:,2) = fdm(:,:,3); 319 | fdmII(:,:,1) = fdmII(:,:,2); 320 | fdmII(:,:,2) = fdmII(:,:,3); 321 | update the source function 'rw (it)' 322 | fdm(izs+2*M+N,ixs+2*M+N,2) = fdm(izs+2*M+N,ixs+2*M+N,2)+rw(it); 323 | fdm(izs+2*M+N,ixs+2*M+N+1,2) = fdm(izs+2*M+N,ixs+2*M+N+1,2)+rw(it); 324 | 325 | % update data 326 | for g = 1:nx 327 | data(g+2*M+N,it) = fdm(2*M+N+surec(g),2*M+N+g,2); 328 | end 329 | FwdSnapshot(:,:,it) = fdm(:,:,2); 330 | 331 | end % ends time loop 332 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | Copyright 2020 Emiro Chica Quiñones - echica@terralica.com 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | 15 | Apache License 16 | Version 2.0, January 2004 17 | http://www.apache.org/licenses/ 18 | 19 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 20 | 21 | 1. Definitions. 22 | 23 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 24 | 25 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 26 | 27 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 28 | 29 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 30 | 31 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 32 | 33 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 36 | 37 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 38 | 39 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 40 | 41 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 42 | 43 | 2. Grant of Copyright License. 44 | 45 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 46 | 47 | 3. Grant of Patent License. 48 | 49 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 50 | 51 | 4. Redistribution. 52 | 53 | You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 54 | 55 | You must give any other recipients of the Work or Derivative Works a copy of this License; and 56 | You must cause any modified files to carry prominent notices stating that You changed the files; and 57 | You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and 58 | If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. 59 | You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 60 | 61 | 5. Submission of Contributions. 62 | 63 | Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 64 | 65 | 6. Trademarks. 66 | 67 | This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 68 | 69 | 7. Disclaimer of Warranty. 70 | 71 | Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 72 | 73 | 8. Limitation of Liability. 74 | 75 | In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 76 | 77 | 9. Accepting Warranty or Additional Liability. 78 | 79 | While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 80 | 81 | END OF TERMS AND CONDITIONS 82 | 83 | APPENDIX: How to apply the Apache License to your work 84 | 85 | To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. 86 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Reverse Time Migration (RTM) MatLab Code** 2 | 5 | 6 | [![license](https://img.shields.io/github/license/gimli-org/gimli.svg?style=flat-square)](http://www.apache.org/licenses/LICENSE-2.0) 7 | [![release](https://img.shields.io/github/release/gimli-org/gimli.svg?style=flat-square)](https://github.com/ejchicaq-unal/RTM-MatLab-Code/releases/latest) 8 | [![Github commits (since latest release)](https://img.shields.io/github/commits-since/ejchicaq-unal/RTM-MatLab-Code/latest.svg?style=flat-square)](https://github.com/ejchicaq-unal/RTM-MatLab-Code) 9 | 10 | Abstract 11 | RTM is a depth migration method that implements a solution of the full wave equation. In this work, a methodology for the application of RTM to synthetic and real data is developed. We discuss the components of RTM: Acoustic wave modeling, boundary conditions and imaging condition. A Finite Difference Method (FDM) based on a staggered grid scheme was implemented for the wave modeling. A Hibryd ABC method that combines two of the most common solutions to the problem of boundary conditions: predictive boundary condition and absorbing boundary condition. RTM images were obtained using a Cross-correlation Imaging Condition with Wavefield Decomposition. The algorithm was applied to synthetic data obtained by modeling a complex geological structure, with a known velocity model. On real data, an image of the complex structure was obtained, which allowed us to know the real location of the reflection events. The obtained seismic image better resolved the seismic events compared with conventional methods of migration. 12 | Keywords: Migration, Imaging, RTM, Finite Difference Method, Full Wave Equation, Boundary Condition, Imaging Condition. 13 | 14 | ##### License 15 | 16 | is distributed under the terms of the **Apache 2.0** license. 17 | 18 | Copyright 2020 Emiro Chica Quiñones - echica@terralica.com 19 | 20 | RTM MatLab Code is distributed under the Apache License, Version 2.0 (the "License"); 21 | you may not use this file except in compliance with the License. 22 | 23 | You may obtain a copy of the License at 24 | 25 | http://www.apache.org/licenses/LICENSE-2.0 26 | 27 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 28 | -------------------------------------------------------------------------------- /RTM.m: -------------------------------------------------------------------------------- 1 | %% Forward modeling high order SG FDM 2 | % 3 | % By Emiro Chica 4 | % 20.02.2014 5 | % 6 | 7 | %%Copyright 2020 Emiro Chica Quiñones - echica@terralica.com 8 | % 9 | %Licensed under the Apache License, Version 2.0 (the "License"); 10 | %you may not use this file except in compliance with the License. 11 | %You may obtain a copy of the License at 12 | % 13 | % http://www.apache.org/licenses/LICENSE-2.0 14 | % 15 | %Unless required by applicable law or agreed to in writing, software 16 | %distributed under the License is distributed on an "AS IS" BASIS, 17 | %WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | %See the License for the specific language governing permissions and 19 | %limitations under the License. 20 | % 21 | 22 | %% Load velocity model 23 | 24 | load 'velocityModel' 25 | 26 | [nz,nx] = size(velocityModel); 27 | 28 | %% Defines the grid size 29 | 30 | dx = 10; % grid size in surface direction 31 | dz = 10; % grid size in depth direction 32 | 33 | x = (1:nx)*dx; % offset vector 34 | z = (1:nz)*dz; % depth vectors 35 | 36 | %% Depth of source point in meters 37 | 38 | prof=10; 39 | 40 | izs=prof/dz; 41 | 42 | %% Create shot gathers 43 | % Use the velocity model to simulate a seismic survey. The wave equations 44 | % is solved using finite differences for a defined initial wavefield. 45 | 46 | % Time sampling interval in miliseconds 47 | 48 | dt=0.001; 49 | 50 | nt=21; % 51 | 52 | t = (0:nt-1).*dt; 53 | 54 | M=3; %(2M)th order SDF 55 | 56 | N=10; % Transition area width 57 | 58 | % Add region around velocity model for applying absorbing 59 | % boundary conditions (2*M nodes wide) 60 | 61 | velocityModel_2=zeros(nz+2*M+N,nx); 62 | 63 | for x1=1:nx 64 | for z1=1:nz+2*M+N 65 | velocityModel_2(z1,x1)=0; % velocityModel_2(z1,x1)=300; 66 | end 67 | end 68 | 69 | for x1=1:nx 70 | for z1=1:nz 71 | velocityModel_2(z1+2*M+N,x1)=velocityModel(z1,x1); 72 | end 73 | end 74 | 75 | 76 | V = [repmat(velocityModel_2(:,1),1,2*M+N) velocityModel_2 repmat(velocityModel_2(:,end),1,2*M+N)]; 77 | V(end+1:end+2*M+N,:) = repmat(V(end,:),2*M+N,1); 78 | 79 | %% Definition of the source waveleth 80 | 81 | %% uncomment this function to use a Ricker waveleth 82 | % Ricker waveleth 83 | f = 60; 84 | t0=1/f; 85 | T = dt*(nt-1); 86 | tt = 0:dt:T; 87 | tau = tt-t0; 88 | rw = (1-tau.*tau*f^2*pi^2).*exp(-tau.^2*pi^2*f^2); 89 | 90 | %% uncomment this function to use a sinusoidal pulse as waveleth 91 | % sinusoidal pulse 92 | %f = 20; % frequency 93 | %t0=1/f; % period 94 | %T = dt*(nt-1); 95 | %rw=zeros(nt); 96 | %for i=0:t0/dt 97 | % rw(i+1)=sin(2*pi*f*i*dt); 98 | %end 99 | 100 | % Algorithm to solve the equations to find the coefficients of the time-space 101 | % domain for SDF based on the paper: 102 | % Prestack RTM with a time-space domain adaptive high-order staggered-grid 103 | % Finite Difference Method 104 | % Yan et all, Exploration Geophysics, 2013, 44, 77-86 105 | % http://dx.doi.org/10.1071/EG12047 106 | 107 | vmin = min(velocityModel(:)); 108 | r=vmin*dt/dx; 109 | 110 | % Plane wave propagation direction angle is posible to use teta=pi/8 too 111 | teta=pi/16; 112 | 113 | K=zeros(M,M); 114 | 115 | for i=1:M 116 | for j=1:M 117 | K(j,i)=(2*i-1)^(2*j-2); 118 | end 119 | end 120 | 121 | xx=K(2,:); 122 | 123 | bb=zeros(1,M); 124 | bn=zeros(1,M); 125 | beta=zeros(1,M); 126 | c=zeros(1,M); 127 | d=zeros(1,M); 128 | a=zeros(1,M); 129 | 130 | for n=1:M 131 | beta(n)=((-1)^(n-1))/(factorial(2*n-1)); 132 | c(n)=((cos(teta))^(2*n-1))*beta(n); 133 | d(n)=(sin(teta)^(2*n-1))*beta(n); 134 | end 135 | 136 | bn(1)=1; % Ecuacion 7a 137 | 138 | for n=2:M 139 | b1=0; 140 | for j=1:n 141 | b1=beta(j)*beta(n+1-j)+b1; 142 | end 143 | b2=0; 144 | for j=2:n-1 145 | b2=(bb(j)*bb(n+1-j))*(c(j)*c(n+1-j)+d(j)*d(n+1-j))+b2; 146 | end 147 | bn(n)=(b1*r^(2*n-2)-b2)/(2*(c(1)*c(n)+d(1)*d(n))); % Ecuacion 7b 148 | end 149 | 150 | % The matrix 'bb' is an almost singular matrix, therefore it is not possible to 151 | % solve equation (6) by inverting the matrix. 152 | % 'bb' is a Vandermonde matriz 153 | 154 | for i=1:M 155 | a(i)=2*i-1; 156 | end 157 | 158 | bb=bn; 159 | 160 | n=length(bb); 161 | 162 | % Vandermonde matrix solution based on the paper: 163 | % Solution of Vandermonde Systems of Equations 164 | % Bjorck et al 165 | % Mathematics of Computation (1970) 166 | % Volume 24, number 112 167 | 168 | % Appendix 169 | for k=1:n-1 170 | for i=n:-1:k+1 171 | bb(i)=bb(i)-xx(k)*bb(i-1); 172 | end 173 | end 174 | for k=n-1:-1:1 175 | for i=k+1:n 176 | bb(i)=bb(i)/(xx(i)-xx(i-k)); 177 | end 178 | for i=k:n-1 179 | bb(i)=bb(i)-bb(i+1); 180 | end 181 | end 182 | 183 | am=bb./a; 184 | 185 | %% Wavefield modeling 186 | 187 | data = zeros(size(nt,nx)); 188 | figure(gcf) 189 | 190 | shot_1 = 339; % Number of the first record - this can be changed 191 | shot_2 = 339; % Number of the last record - this can be changed 192 | is = 5; % Source interval 193 | I = zeros(nz,nx); 194 | 195 | 196 | for ixs = shot_1:is:shot_2 % Records loop 197 | 198 | % Wavefield modeling in the direction of time (Forward Modeling) 199 | 200 | texto = ['Record No.: ',num2str(ixs)]; 201 | disp(' ') 202 | disp('===============================================================') 203 | disp(texto) 204 | 205 | disp('Calculating wavefield modeling in the direction of time (Forward Modeling)') 206 | 207 | tic 208 | 209 | [data, FwdSnapshot] = FwdModelingFunction(V,rw,nz,dz,nx,dx,nt,dt,ixs,izs,M,am,N); 210 | 211 | FwdSnapshot = FwdSnapshot(2*M+N+1:end-(2*M+N),2*M+N+1:end-(2*M+N),:); 212 | 213 | % save(['/out/Fwd/FwdSnapshot',num2str(ixs-(2*M+N)),'.mat'],'FwdSnapshot','-v7.3'); 214 | % save(['/out/Fwd/FwdSnapshot',num2str(ixs),'.mat'],'FwdSnapshot','-v7.3'); 215 | 216 | data = data(2*M+N+1:end-(2*M+N),:); 217 | 218 | %save(['/out/shot/shot',num2str(ixs-(2*M+N)),'.mat'],'data') 219 | %save(['/out/shot/shot',num2str(ixs),'.mat'],'data','-v7.3') 220 | 221 | toc 222 | 223 | % Modelamiento del campo de ondas en la direccion contraria del tiempo 224 | % (Backward % Modeling) 225 | 226 | disp('Calculating modeling in the opposite direction of time (Backward Modeling') 227 | 228 | tic 229 | 230 | [~, BckwdSnapshot] = BackModelingFunction(V,data,nz,nx,dx,nt,dt,M,am,N); 231 | 232 | BckwdSnapshot = BckwdSnapshot(2*M+N+1:end-(2*M+N),2*M+N+1:end-(2*M+N),:); 233 | 234 | %save(['/out/Bkwd/BckwdSnapshot',num2str(ixs),'.mat'],'BckwdSnapshot','-v7.3'); 235 | %save(['/out/Bkwd/BckwdSnapshot',num2str(ixs),'.mat'],'BckwdSnapshot','-v7.3'); 236 | 237 | toc 238 | 239 | %% Image condition with decomposition of fields in the z direction 240 | Imz = zeros(nz,nx); 241 | Imx = zeros(nz,nx); 242 | SFTz = zeros(nz,1); %Fourier transform of the source 243 | RFTz = zeros(nz,1); %Fourier transform of receivers 244 | SFTx = zeros(nx,1); %Fourier transform of the source 245 | RFTx = zeros(nx,1); %Fourier transform of receivers 246 | 247 | disp('Calculating image condition in z direction') 248 | 249 | tic 250 | 251 | for xx = 1:nx 252 | Iz = 0; 253 | for tt = 1:nt 254 | 255 | for zz = 1:nz 256 | SFTz(zz) = FwdSnapshot(zz,xx,tt); 257 | RFTz(zz) = BckwdSnapshot(zz,xx,tt); 258 | end 259 | 260 | Sz = fft(SFTz); 261 | Rz = fft(RFTz); 262 | 263 | for zz = 1:round((nz+1)/2) 264 | 265 | Sz(zz) = 0; 266 | Rz(zz) = 0; 267 | end 268 | 269 | sz = ifft(Sz); 270 | rz= ifft(Rz); 271 | 272 | Iz = sz.*rz+Iz; 273 | 274 | end 275 | 276 | for zz = 1:nz 277 | 278 | Imz(zz,xx) = 2*real(Iz(zz)); 279 | 280 | end 281 | 282 | %save(['/out/ImaCond/Imz',num2str(ixs),'.mat'],'Imz'); 283 | %save(['/out/ImaCond/Imz',num2str(ixs),'.mat'],'Imz'); 284 | %save(['/out/ImaCond/Imz',num2str(ixs),'.mat'],'Imz'); 285 | 286 | end 287 | 288 | toc 289 | 290 | %% Image condition with decomposition of fields in the x direction 291 | 292 | disp('Calculating image condition in z direction') 293 | 294 | tic 295 | 296 | for zz = 1:nz 297 | Ix = 0; 298 | for tt = 1:nt 299 | 300 | for xx = 1:nx 301 | SFTx(xx) = FwdSnapshot(zz,xx,tt); 302 | RFTx(xx) = BckwdSnapshot(zz,xx,tt); 303 | end 304 | 305 | Sx = fft(SFTx); 306 | Rx = fft(RFTx); 307 | 308 | for xx = 1:round((nx+1)/2) 309 | 310 | Sx(xx) = 0; 311 | Rx(xx) = 0; 312 | end 313 | 314 | sx = ifft(Sx); 315 | rx = ifft(Rx); 316 | 317 | Ix = sx.*rx+Ix; 318 | 319 | end 320 | 321 | for xx = 1:nx 322 | 323 | Imx(zz,xx) = 2*real(Ix(xx)); 324 | 325 | end 326 | %save(['/out/ImaCond/Imx',num2str(ixs),'.mat'],'Imx'); 327 | %save(['/out/ImaCond/Imx',num2str(ixs),'.mat'],'Imx'); 328 | %save(['/out/ImaCond/Imx',num2str(ixs),'.mat'],'Imx'); 329 | 330 | end 331 | 332 | toc 333 | 334 | disp('===============================================================') 335 | 336 | I = Imx+Imz+I; 337 | 338 | subplot(2,1,1) 339 | imagesc(x,z,Imx(:,:)+Imz(:,:)) 340 | xlabel('Distance (m)'); ylabel('Depth (m)'); 341 | title(['Current record migrated ',num2str(ixs)]); 342 | colormap(gray) 343 | caxis ([-5 5]) 344 | 345 | subplot(2,1,2) 346 | imagesc(x,z,I(:,:)) 347 | xlabel('Distance (m)'); ylabel('Depth (m)'); 348 | title(['Accumulated migrated image until registration ',num2str(ixs)]); 349 | colormap(gray) 350 | caxis ([-350 350]) 351 | 352 | drawnow; 353 | 354 | end 355 | 356 | %save(('/out/ImaCond/I.mat'),'I'); 357 | %save(('/out/ImaCond/I.mat'),'I'); 358 | %save(('/out/ImaCond/I.mat'),'I'); 359 | -------------------------------------------------------------------------------- /surec.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ejchicaq-unal/RTM-MatLab-Code/949b4539b8e4cb661b7127b6e243240f48aab738/surec.mat -------------------------------------------------------------------------------- /velocityModel.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ejchicaq-unal/RTM-MatLab-Code/949b4539b8e4cb661b7127b6e243240f48aab738/velocityModel.mat --------------------------------------------------------------------------------