To estimate the delay ( k ) in a received signal that is a noisy, attenuated, and delayed version of a damped sine wave, we can  generate the emitted signal, which is a damped sine wave and define the signal as follows:
A = 1;  
f = 5;  
t = 0:0.001:1;  
x = A * exp(-t) .* sin(2 * pi * f * t);  
Next, we'll simulate the received signal. This signal will be an attenuated and delayed version of the emitted signal, with added noise. We can vary the noise level according to the Signal-to-Noise Ratio (SNR):
a = 0.8;  
k = 50;  
SNR_values = 0:5:30;  
Now, for each SNR value, we can add noise to the received signal and calculate the cross-correlation between the emitted and received signals. This will help us estimate the delay:
estimated_delays = zeros(size(SNR_values));  
for idx = 1:length(SNR_values)
    SNR = SNR_values(idx);
    noise_power = var(x) / (10^(SNR/10));
    noise = sqrt(noise_power) * randn(size(x));
    y = [zeros(1, k), a*x(1:end-k)] + noise; 
    [xc, lags] = xcorr(y, x); 
    [~, I] = max(xc);
    estimated_delays(idx) = lags(I); 
end
Finally, we can plot the estimated delay against the SNR to visualize how noise impacts delay estimation. 
figure;
plot(SNR_values, estimated_delays, '-o');
xlabel('SNR (dB)');
ylabel('Estimated Delay (samples)');
title('Estimated Delay vs. SNR');
grid on;
Hope this resolves your query !



