This repository has been archived by the owner on May 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCOmig.m
192 lines (159 loc) · 8.8 KB
/
COmig.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
%{
Comig.m - Common offset Kirchhoff migration in time and depth.
Copyright (C) 2013 Jesper S Dramsch, Matthias Schneider, Dela Spickermann, Jan Walda
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
%}
clear all % Clear workspace
close all % Close figures
clc % Clear command line window
format long % Double precision
tStart = tic; % runtime measurement
dcmp = 20; % CMP-Distance [m]
dt = 2e-3; % Samplinginterval [s]
nt = 1001; % Number of samples
ns = 101; % Number of traces
nh = 5; % Number of offsets
Fs = 1/dt; % Frequency sampling [Hz]
hmax = 1000; % Maximum half-offset [m]
dh = 250; % half-offset increment [m]
vmin = 2754; % Minimum test velocity [m/s]
vmax = 2754; % Maximum test velocity [m/s]
vfinal = 2754; % Final migration velocity [m/s]
dv = 100; % Velocity increment [m/s]
aper = 400; % Aperturewidth [m]
dz = vfinal/1e3; % Depthsampling increment [m]
flag_interp = 0; % 1 = use interpolation, 0 = use rounding
kirch_time=0; % Time Migration switch
kirch_depth=1; % Depth Migration switch
%% Open file
% Original data
filename = 'data-6/SEIS-orig';
fid = fopen(filename,'r');
data = reshape(fread(fid, [nt nh*ns],'single'),nt,ns,nh);
fclose(fid);
% With sqrt{-i omega} filtered data
filenamefilt = 'data-6/SEIS-filt';
fidfilt = fopen(filenamefilt,'r');
filtdata = reshape(fread(fidfilt, [nt nh*ns],'single'),nt,ns,nh);
fclose(fidfilt);
%% Input Plots
% Compare max amplitudes of each CMP in original data
mig_graphs('OffsetLine',data,((1:ns)-1)*dcmp,'ampsorig')
% Compare max amplitudes of each CMP in original data
mig_graphs('OffsetLine',filtdata,((1:ns)-1)*dcmp,'ampsfilt')
% Input signal normalized
mig_graphs('CompLine','Filtered data',filtdata(:,51,1)/max(filtdata(:,51,1)),'Original data',data(:,51,1)/max(data(:,51,1)),((1:nt)-1)*dcmp,'Zeit [s]','Normalisierte Amplitude','waveletnorm')
% Input signal not normalized
mig_graphs('CompLine','Filtered data',filtdata(:,51,1),'Original data',data(:,51,1),((1:nt)-1)*dcmp,'Zeit [s]','Amplitude','waveletorig')
% Input signal original
mig_graphs('COG',data(:,:),((1:ns*nh)-1)*dcmp,(0:nt-1)','Time [s]','InputCOG')
% Input signal filtered
mig_graphs('COG',filtdata(:,:),((1:ns*nh)-1)*dcmp,(0:nt-1)','Time [s]','InputCOGfilt')
%% Frequency analysis
NFFT = 2^nextpow2(nt); % calculate next 2^n to prepare adta for FFT
fdata = fft(mean(data(:,:,1),2),NFFT)/nt; % FFT of extended dataset
faxis = Fs/2*linspace(0,1,NFFT/2+1); % Skaling of the x-axis
%% Frequency Plot
mig_graphs('SingleLine',abs(fdata(1:length(faxis)))/max(abs(fdata(1:length(faxis)))),faxis,'Frequencz [Hz]','Normalized Amplitude','freq')
%% Kirchhoff migration
%% Open arrays and variables
h=0:dh:hmax; % half offset
t_orig=0:dt:((nt-1)*dt);
i_v=0; % velocity iterator
aper_half = round(.5*aper/dcmp); % half aperture
% x-sampling = cmp-sampling
%% Loop over velocities
for v = vmin:dv:vmax;
i_v = i_v+1;
t_depth=t_orig*v*0.5; % TWT to depth conversion
zmax = max(t_depth); % Max depth [m]
z=0:dz:zmax; % Depthsampling
z_len = length(z);
Kirchhofftime(1:nt,1:ns,1:nh)=0; % (time, CMP, halfoffset)
%Kirchhoffdepth(1:z_len,1:ns,1:nh)=0; % (depth, CMP, halfoffset)
mig(1:z_len,1:ns)=0; % stack
filt_interp(1:z_len,1:ns,1:nh)=0;
%% loop over half offsets
for i_h = 1:nh
disp('half offset'); disp((i_h-1)*dh);
% Might take a long time so we give some output for responsiveness
% interpolation at zdiff
if kirch_time == 1
[Kirchhofftime(:,:,i_h), Skala(:,i_h)] = CO_kirch_time(filtdata(:,:,i_h), v, h(i_h), dt, dcmp, aper_half, flag_interp);
Kirchhoffdepth(:,:,i_h) = interp1(Skala(:,1),Kirchhofftime(:,:,i_h),Skala(:,i_h),'spline');
z = Skala(:,1);
z_len = length(z);
z_max=max(z);
COG = Kirchhoffdepth;
end
if kirch_depth == 1
[Kirchhoffdepth(:,:,i_h)] = CO_kirch_depth(filtdata(:,:,i_h), v, h(i_h), dt, dz, dcmp, aper_half, flag_interp);
COG = Kirchhoffdepth/(2*pi);
end
end
%% CO-Gather for each velocity
mig_graphs('COG',COG(:,:),((1:ns*nh)-1)*dcmp,z,'Depth [km]',sprintf('COGv%g',v))
% Compare max amplitude in each CMP in COG
mig_graphs('OffsetLine',COG,((1:ns)-1)*dcmp,sprintf('ampsv%g',v))
if v == vfinal
% if loop reaches the correct velocity
% (estimated with constant velocity scan)
mig(1:z_len,1:ns) = mean(COG,3); % summing CO-Gather
%% Plot of the migration result
mig_graphs('PolarPlot',mig(:,:),((1:ns)-1)*dcmp/1000,z,'CMP [km]','Depth [km]',sprintf('sum_vm%g',v))
% max amplitude of each CMP in migrated section
mig_graphs('SingleLine',max(abs(mig(:,:))),((1:ns)-1)*dcmp,'CMP','Maximum Amplitude','migamp')
%% Calculation of Signal-to-Noise-Ratio
SNRin = log(max(max(filtdata(:,:,1)))/mean(mean(abs(filtdata(100:200,:)))));
SNRorig = log(max(max(abs(data(:,:,1))))/mean(mean(abs(data(100:200,:)))));
SNRout = log(max(max(mig(:,:)))/mean(mean(abs(mig(100:200,:)))));
if kirch_time == 1
% Plot trace 51 normalized
mig_graphs('CompLine','SNR Input',filtdata(:,51,1)/max(filtdata(:,51,1)),'SNR Migriert',mig(:,51)/max(mig(:,51)),((1:nt)-1)*dt,'Zeit [s]','Normalized Amplitude','SNRnorm')
% Plot trace 51 not normalized
mig_graphs('CompLine','SNR Input',filtdata(:,51,1),'SNR Migriert',mig(:,51),((1:nt)-1)*dt,'Zeit [s]','Amplitude','SNRreal')
% Comparison results normalized
mig_graphs('CompLine','Original Data',data(:,51,1)/max(data(:,51,1)),'Migrated Data',mig(:,51,1)/max(mig(:,51,1)),((1:nt)-1)*dt,'Zeit [s]','Normalized Amplitude','waveletNorm')
% Comparison results not normalized
mig_graphs('CompLine','Original Data',data(:,51,1),'Migrated Data',mig(:,51,1),((1:nt)-1)*dt,'Zeit [s]','Amplitude','wavelet')
end
% Output SNR change to screen
fprintf('Signal-to-Noise ratio of %f2 (filtered) or %f2 (original) changed to %f2\n',SNRin,SNRorig,SNRout)
%% Plot results
% Input signal normalized
mig_graphs('CompLine','Original Data',data(:,51,1)/max(data(:,51,1)),'Filtered Data',filtdata(:,51,1)/max(filtdata(:,51,1)),((1:nt)-1)*dt,'Zeit [s]','Normalized Amplitude','inoutNorm')
% Input signal not normalized
mig_graphs('CompLine','Original Data',data(:,51,1),'Filtered Data',filtdata(:,51,1),((1:nt)-1)*dt,'Zeit [s]','Amplitude','inout')
%% Frequency analysis of migrated and summed data
%Use FFT and faxis vectors from above
migdata = fft(mean(mig,2),NFFT)/nt; % FFT of migrated dataset
%% Frequency Plot of migration
mig_graphs('SingleLine',abs(migdata(1:length(faxis)))/max(abs(migdata(1:length(faxis)))),faxis,'Frequencz [Hz]','Normalized Amplitude','freq_mig')
% Frequency Comparison
mig_graphs('CompLine','Original data',abs(fdata(1:length(faxis)))/max(abs(fdata(1:length(faxis)))),'Migrated data',abs(migdata(1:length(faxis)))/max(abs(migdata(1:length(faxis)))),faxis,'Frequency [Hz]','Normalized Amplitude','freq_comp')
% Frequency Comparison
mig_graphs('CompLine','Original data',abs(fdata(1:length(faxis))),'Migrated data',abs(migdata(1:length(faxis))),faxis,'Frequency [Hz]','Amplitude','freq_comp')
% Fileoutput of datamatrices
dlmwrite('output/mig.dat',mig)
dlmwrite('output/COGatherh0.dat',COG(:,:,1));
dlmwrite('output/COGatherh250.dat',COG(:,:,2));
dlmwrite('output/COGatherh500.dat',COG(:,:,3));
dlmwrite('output/COGatherh750.dat',COG(:,:,4));
dlmwrite('output/COGatherh1000.dat',COG(:,:,5));
%%% Für alte Amplitudenvergleiche müsste zurück interpoliert werden, da
%%% z_len != length(t) und z_len hängt von v ab, siehe
%%% t_depth=t_orig*v*0.5;
%%% zmax = max(t_depth); % zmax nimmt mit steigendem v zu, aber
%%% z=0:dz:zmax; % dz bleibt gleich !
end
end
tElapsed = toc(tStart); % Runtime