This code snippet that demonstrates a simple target detection scenario using an active sonar system in MATLAB. This example uses a basic approach with pulse transmission, echo reception, and thresholding for detection.
t = 0:1/samplingFreq:pulseWidth;
pulse = cos(2*pi*transmitFreq*t);
propagationDelay = 2 * targetRange / soundSpeed;
receivedSignal = [zeros(1, round(samplingFreq * propagationDelay)), targetStrength * pulse];
correlation = conv(receivedSignal, fliplr(pulse));
threshold = 0.5 * max(correlation);
detections = find(correlation > threshold);
title('Transmitted Pulse');
timeAxis = (0:length(receivedSignal)-1) / samplingFreq;
plot(timeAxis, receivedSignal);
plot(timeAxis, correlation);
stem(detections / samplingFreq, correlation(detections), 'r', 'Marker', 'x');
legend('Received Signal', 'Correlation', 'Detections');
title('Received Signal and Correlation');
In this example, we define the parameters for the sonar system, including transmit frequency, pulse width, sampling frequency, and speed of sound in water. We then generate a pulse signal and simulate the signal propagation by adding a delay to the received signal. The received signal is processed using matched filtering, and a detection threshold is applied to identify potential target detections. Finally, the transmitted pulse and the received signal with correlation and detected targets are plotted using the subplot function.