RRMF

PHOTO EMBED

Mon Nov 18 2024 18:49:50 GMT+0000 (Coordinated Universal Time)

Saved by @lord

clc; 
clear all; 
close all;

Fs = 1e6;  % Sampling frequency
fd = 100;  % Doppler frequency

% Custom Rayleigh fading implementation
n = 1000; % Number of samples
pathDelays = [0 1e-5 2e-5];
pathGains_dB = [0 -3 -6];
pathGains = 10.^(pathGains_dB/10); % Convert to linear scale

% Generate Rayleigh fading samples
t = (0:n-1)/Fs; % Time vector
rayleigh_fading = zeros(n, length(pathDelays));
for i = 1:length(pathDelays)
    doppler_phase = 2 * pi * fd * t; % Doppler effect
    rayleigh_fading(:, i) = sqrt(pathGains(i)) * ...
        abs(1/sqrt(2) * (randn(1, n) + 1j * randn(1, n))) .* exp(1j * doppler_phase);
end

% Custom Rician fading implementation
k = 10; % Rician K-factor
rician_fading = sqrt(k/(k+1)) + sqrt(1/(k+1)) * rayleigh_fading;

% Generate random input signal
x = randn(n, 1);

% Pass the signal through the custom Rayleigh and Rician channels
y_rayleigh = sum(rayleigh_fading, 2) .* x;
y_rician = sum(rician_fading, 2) .* x;

% Extract impulse responses
impulse_response_rayleigh = rayleigh_fading;
impulse_response_rician = rician_fading;

% Plot Rayleigh channel impulse response
figure;
subplot(2, 1, 1);
plot(abs(impulse_response_rayleigh));
title('Rayleigh Fading Channel Impulse Response');
xlabel('Sample Number');
ylabel('Amplitude');

% Plot Rician channel impulse response
subplot(2, 1, 2);
plot(abs(impulse_response_rician));
title('Rician Fading Channel Impulse Response');
xlabel('Sample Number');
ylabel('Amplitude');

% Calculate and plot Rician channel power delay profile
Pd_rician = mean(abs(impulse_response_rician).^2, 1); % Average power per path
figure;
stem(10*log10(Pd_rician), 'filled'); % Power in dB
title('Rician Fading Channel Power Delay Profile');
xlabel('Path Index');
ylabel('Power (dB)');

% Compute FFT of the Rayleigh and Rician faded signals
fft_rayleigh = fft(y_rayleigh);
fft_rician = fft(y_rician);

% Plot frequency spectrum
figure;
subplot(2, 1, 1);
plot(abs(fft_rayleigh));
title('Frequency Spectrum of Rayleigh Fading Signal');
xlabel('Frequency Index');
ylabel('Amplitude');

subplot(2, 1, 2);
plot(abs(fft_rician));
title('Frequency Spectrum of Rician Fading Signal');
xlabel('Frequency Index');
ylabel('Amplitude');
content_copyCOPY