# cdf rayleigh comparison code error

2 visualizzazioni (ultimi 30 giorni)
Jose Iglesias il 12 Mar 2023
Commentato: Walter Roberson il 12 Mar 2023
The Matlab code shown below was created to plot the amplitude of h0 versus time (sampling the time interval every 1ms, starting from time 0s to time 1s) in reference to the RX that is moving at 72km/h away from the TX, along the horizontal line winding up 20m further away from the TX using the discrete baseband channel model h0 equation. I am supposed to plot the cumulative distribution function (CDF) of the squared amplitude and phase of h0, shown in the Matlab code below, from the samples collected,1001 samples in total (two distinct figures) and compare the resulting CDFs with the Rayleigh fading case. I had to tweak my original code but when I tried to run it in Matlab, I get an error in line 41 that states the following message:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in cdf_rayleigh_comparison (line 41)
h0_squared_abs_samples(i) = abs(h0).^2;
I am uncertain on how to resolve this. I think the issue is that the index i is linked to 10000 samples and (h0) is linked to the time vector t_new = linspace(0,1,1001); unless this is a wrong assumption. Can someone here please see how I may resolve this issue for I am not really Matlab savvy. There may be another error past line 41 which I cannot see yet. Also, if the original problem statement called for 1001 samples, should not the number of samples variable num_samples = 10000; be 1001 as well? The problem statement, along with the physical model of the distance between the transmitter and receiver are shown below. The discrete baseband channel model complex channel filter tap at time m equation is also shown below. Thank you in advance.   % Physical parameters
c = 3e8; % speed of light
d = 20; % distance between transmitter and receiver in meters
v = 72*1000/3600; % velocity of receiver in m/s
fc = 100e3;
W = 200E3;
% Time vector
t_new = linspace(0,1,1001);
% Baseband channel model parameters
tau = [0.2387 4E-6 3.40E-6 3.667E-6 3.59E-6];
% Number of samples
num_samples = 1001;
% Initialize vectors to store samples
h0_squared_abs_samples = zeros(1, num_samples);
h0_phase_samples = zeros(1, num_samples);
for i = 1:num_samples
% Discrete channel filter tap at time m
h0 = zeros(1,length(t_new));
% Calculate the distance traveled by the RX at time m
dist = v * rand() * max(t_new);
% Calculate the delays of the multipath components
tau_rand = tau + dist/c;
% Calculate the complex gains of the multipath components
a = randn(1, length(tau_rand)) + 1j*randn(1, length(tau_rand));
a = a/sqrt(2);
% Apply the channel filter
for m = 1:length(t_new)
h0(m) = sum(a.*sinc(-t_new(m)*tau_rand*W));
end
% Store the squared absolute value and phase samples
h0_squared_abs_samples(i) = abs(h0).^2;
h0_phase_samples(i) = angle(h0);
end
Unable to perform assignment because the left and right sides have a different number of elements.
% Plot the CDF of squared absolute value
figure;
[f, x] = ecdf(h0_squared_abs_samples);
plot(x, f);
xlabel('|h_0|^2');
ylabel('CDF');
title('CDF of |h_0|^2');
% Plot the CDF of phase
figure;
[f, x] = ecdf(h0_phase_samples);
plot(x, f);
xlabel('Phase(h_0)');
ylabel('CDF');
title('CDF of Phase(h_0)');
##### 1 CommentoMostra NessunoNascondi Nessuno
Walter Roberson il 12 Mar 2023
h0(m) = sum(a.*sinc(-t_new(m)*tau_rand*W));
h0 is going to be a vector.
h0_squared_abs_samples(i) = abs(h0).^2;
WIth h0 being a vector, abs(h0).^2 is going to be a vector, but the left hand side designates a scalar location.
The next line has the same problem.

Accedi per commentare.

### Categorie

Scopri di più su Propagation and Channel Models in Help Center e File Exchange

R2020a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!