Hi Muhammad,
To incorporate distance into signals, find their locations and plot the FFT magnitude, you can refer to the following steps and attached code snippets:
1. The phase shift due to distance was incorporated into the signals by multiplying by the term “exp (-j * 2 * pi * f * d / c)”. This term accounts for the phase delay introduced by the distance the signal travels.
x1 = exp(j * h1 * n) * exp(-j * 2 * pi * f1 * d1 / c);
x2 = exp(j * h2 * n) * exp(-j * 2 * pi * f2 * d2 / c);
2. The signal locations were determined by distances (d1) and (d2) and printed to the console to indicate positions of (x1) and (x2).
disp(['Location of x1: ', num2str(d1), ' meters']);
disp(['Location of x2: ', num2str(d2), ' meters']);
3. The FFT of the combined signal was computed, and its magnitude was plotted against a normalized frequency axis, providing a clear visualization of the signal's frequency components.
f = (0:255) * (Fs / 256);
title('Magnitude of FFT Spectrum of X(N)', 'FontSize', 12, 'Color', 'k');
xlabel('Frequency (Hz)', 'FontSize', 12);
ylabel('Magnitude', 'FontSize', 12);
You may refer to the output below for a clearer understanding:
For more information on “fft” and ”abs” function, kindly go through the documentation below:
Hope it helps!