- https://www.mathworks.com/help/matlab/ref/fft.html
- https://www.mathworks.com/help/matlab/ref/abs.html
How can I add distance to signals and how can I determine the locations of signals?
2 次查看(过去 30 天)
显示 更早的评论
please
I have two sources for sending signals, where x1 represents the signal from the first source and x2 represents the signal from the second source :
where :
w1: First Angular Frequncy (rad / sec) and frequncy 40 KHZ.
W2: Second Angular Frequncy (rad / sec) and frequncy 60 KHZ.
n: Number of samples
------------------------------------------------------------------------------------------------
I have this code, how can I add the following to it?
- How can I add the distance to x1 and x2 and find the distance between them ?
- How can I find location x1 and location x2 ?
- Plot Magnitude of FFT with frequencies ?
Please rewrite the code correctly to get the above results.
clear all
clc
close all
% Define all the parameters.
% Frequncy for wave one(KHZ).
f1 = 40e6 ;
% Frequncy for wave two(KHZ).
f2 = 60e6 ;
% The speed of light in vacuum (m/sec).
c = 3e8 ;
% Wavelength for wave one(m).
h1 = c / f1 ;
% Wavelength for wave two(m).
h2 = c / f2 ;
% Imaginary part.
j=sqrt(-1);
% Initialize the vector to store the values.
X = zeros(1, 20);
% Make for loop (where n: number of samples).
for n = 1:20;
x1=exp(j*h1*n);
x2=exp(j*h2*n);
X(n) = x1 + x2;
end
% Compute FFT.
Y = fft(X, 256);
% Compute Magnitude FFT
Y1 = abs(Y);
plot( Y1 );
grid on
title('Magnitude of FFT Spectrum of X(N)', 'FontSize',12,'Color','k');
0 个评论
回答(1 个)
Suraj Kumar
2024-8-8
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);
X(n) = x1 + x2;
2. The signal locations were determined by distances (d1) and (d2) and printed to the console to indicate positions of (x1) and (x2).
% Display locations
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.
% Compute FFT.
Y = fft(X, 256);
% Compute Magnitude FFT
Y1 = abs(Y);
% Frequency axis for plotting
Fs = 1;
f = (0:255) * (Fs / 256);
% Plot Magnitude of FFT with frequencies
figure;
plot(f, Y1);
grid on;
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Filter Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!