📄 rayleigh_fading.m
字号:
function [zz, z,z_dB] = rayleigh_fading(f_D, t, f_s)
% function [Ts, z_dB] = rayleigh_fading(f_D, t, f_s)
% generates a Rayleigh fading signal for given Doppler frequency f_D
% during the time period [0,t], with sampling frequency f_s >= 1000Hz.
%
% Input(s)
% -- f_D : [Hz] [1x1 double] Doppler frequency
% -- t : simulation time interval length, time interval [0,t]
% -- f_s : [Hz] sampling frequency, set to 1000 if smaller.
% Output(s)
% -- Ts : [Sec][1xN double] time instances for the Rayleigh signal
% -- z_dB : [dB] [1xN double] Rayleigh fading signal
% Required parameters
if f_s < 1000;
f_s=1000; % [Hz] Minimum required sampling rate
end;
N = ceil(t*f_s); % Number of samples
% Ts contains the time instances at which z_dB is specified
Ts = linspace(0,t,N);
if mod(N,2)==1
N=N+1; % Use even number of samples in calculation
end
f = linspace(-f_s, f_s, N); % [Hz] Frequency samples used in calculation
% Generate complex Gaussian samples with line spectra in frequency domain
% Inphase :
Gfi_p = randn(2,N/2);
CGfi_p = Gfi_p(1,:)+i*Gfi_p(2,:);
CGfi = [conj(fliplr(CGfi_p)) CGfi_p ];
% Quadrature :
Gfq_p = randn(2,N/2);
CGfq_p = Gfq_p(1,:)+i*Gfq_p(2,:);
CGfq = [conj(fliplr(CGfq_p)) CGfq_p ];
% Generate fading spectrum, this is used to shape the Gaussian line spectra
omega_p = 1; % This makes sure that the average received envelop can be 0dB
S_r = omega_p/4/pi./(f_D*sqrt(1-(f/f_D).^2));
% Take care of samples outside the Doppler frequency range, let them be 0
idx1 = find(f>f_D);
idx2 = find(f<-f_D);
S_r(idx1)=0;
S_r(idx2)=0;
% Generate r_I(t) and r_Q(t) using inverse FFT:
r_I = N*ifft(CGfi.*sqrt(S_r));
r_Q = -i*N*ifft(CGfq.*sqrt(S_r));
% Finally, generate the Rayleigh distributed signal envelope
zz=r_I+r_Q;
z = sqrt(abs(r_I).^2+abs(r_Q).^2);
z_dB = 20*log10(z);
% Return correct number of points
z_dB = z_dB(1:length(Ts));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -