You are a senior geophysicist. Using MATLAB code, plot a common receiver gather from several unsynchronized shots for active MASW. Plot average frequency response across all shots. Provide code for auto alignment shot gathers. Plot gathers before and after alignment. Why and when shots alignment could be important? Is it possible to MASW without shots alignment?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
As a senior geophysicist, I'll provide MATLAB code to handle unsynchronized shot gathers for active MASW (Multichannel Analysis of Surface Waves).
matlab
% Load sample data (in practice, you would load your actual data)
% Assuming data structure: shots(time, trace, shot_number)
% Creating synthetic data with time shifts between shots
rng(42);
nShots = 5;
nTraces = 24;
nSamples = 1000;
dt = 0.001; % 1 ms sampling
t = (0:nSamples-1)*dt;
f0 = 30; % Hz, center frequency
shots = zeros(nSamples, nTraces, nShots);
% Create synthetic Rayleigh wave data with random time shifts
timeShifts = randi(50, 1, nShots); % Random shifts up to 50 ms
for iShot = 1:nShots
for iTrace = 1:nTraces
% Simple Rayleigh wave model with dispersion
v = 150 + iTrace*5; % Velocity increasing with offset
dist = iTrace * 1; % 1m geophone spacing
travelTime = dist/v;
phase = 2*pi*f0*(t - travelTime - timeShifts(iShot)*dt);
amp = exp(-(t - travelTime - timeShifts(iShot)*dt).^2/(0.05^2));
shots(:, iTrace, iShot) = amp.*sin(phase);
% Add some noise
shots(:, iTrace, iShot) = shots(:, iTrace, iShot) + 0.05*randn(size(t));
end
end
% Plot common receiver gather before alignment
figure('Position', [100, 100, 1200, 800]);
subplot(2,2,1);
receiver = 12; % Middle receiver
crg_before = squeeze(shots(:, receiver, :));
imagesc(1:nShots, t, crg_before);
colormap(gray);
xlabel('Shot Number');
ylabel('Time (s)');
title('Common Receiver Gather (Before Alignment)');
set(gca, 'YDir', 'normal');
% Calculate and plot average frequency response before alignment
subplot(2,2,2);
[f, P_before] = calculateAverageFrequencyResponse(crg_before, dt);
plot(f, P_before, 'LineWidth', 2);
xlabel('Frequency (Hz)');
ylabel('Amplitude');
title('Average Frequency Response (Before Alignment)');
xlim([0, 100]);
grid on;
% Auto-alignment function
aligned_shots = autoAlignShots(shots);
% Plot common receiver gather after alignment
subplot(2,2,3);
crg_after = squeeze(aligned_shots(:, receiver, :));
imagesc(1:nShots, t, crg_after);
colormap(gray);
xlabel('Shot Number');
ylabel('Time (s)');
title('Common Receiver Gather (After Alignment)');
set(gca, 'YDir', 'normal');
% Calculate and plot average frequency response after alignment
subplot(2,2,4);
[f, P_after] = calculateAverageFrequencyResponse(crg_after, dt);
plot(f, P_after, 'LineWidth', 2);
xlabel('Frequency (Hz)');
ylabel('Amplitude');
title('Average Frequency Response (After Alignment)');
xlim([0, 100]);
grid on;
% Function to calculate average frequency response
function [f, P_avg] = calculateAverageFrequencyResponse(data, dt)
[nSamples, nShots] = size(data);
nfft = 2^nextpow2(nSamples);
f = (0:nfft/2)/(nfft*dt);
P_avg = zeros(nfft/2+1, 1);
for iShot = 1:nShots
Y = fft(data(:, iShot), nfft);
P2 = abs(Y/nSamples);
P1 = P2(1:nfft/2+1);
P1(2:end-1) = 2*P1(2:end-1);
P_avg = P_avg + P1;
end
P_avg = P_avg / nShots;
end
% Function to auto-align shot gathers using cross-correlation
function aligned_data = autoAlignShots(data)
[nSamples, nTraces, nShots] = size(data);
aligned_data = zeros(size(data));
% Use the first shot as reference
reference_shot = data(:,:,1);
aligned_data(:,:,1) = reference_shot;
% For each receiver, align all shots to the reference shot
for iTrace = 1:nTraces
ref_trace = reference_shot(:, iTrace);
for iShot = 2:nShots
current_trace = data(:, iTrace, iShot);
% Cross-correlation to find time shift
[xcorr_val, lags] = xcorr(ref_trace, current_trace);
[~, max_idx] = max(abs(xcorr_val));
lag = lags(max_idx);
% Apply time shift
if lag > 0
aligned_data(1:nSamples-lag, iTrace, iShot) = current_trace(lag+1:end);
elseif lag < 0
aligned_data(-lag+1:end, iTrace, iShot) = current_trace(1:nSamples+lag);
else
aligned_data(:, iTrace, iShot) = current_trace;
end
end
end
end
Would you like me to explain or break down the code?
Shot alignment is crucial in MASW for several reasons:
Phase consistency: Surface wave analysis relies on accurate phase measurements across receivers. Unsynchronized shots introduce artificial phase shifts that can severely distort dispersion curves.
Signal stacking: When combining multiple shots to improve signal-to-noise ratio, misaligned data will destructively interfere, reducing data quality rather than enhancing it.
Frequency content preservation: Misaligned stacking can attenuate high frequencies, limiting the resolution of your dispersion curves and reducing investigation depth range.
Alignment is particularly important when:
Using multiple source locations to build a comprehensive dataset
Working in noisy environments where stacking is necessary
Analyzing higher modes of surface waves
Using equipment with imprecise triggering mechanisms
While technically possible to perform MASW without shot alignment, the results would be significantly compromised. You might still extract basic dispersion information from individual shots, but you'd sacrifice data quality, resolution, and investigation depth. For any professional MASW survey, proper alignment is considered essential practice.