⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rayleigh_fading.m

📁 对无线通信信道中的瑞利衰落进行MATLAB仿真
💻 M
字号:
%
% filename: rayleigh_fading.m
% function: rayleigh fading 
% 
% input parameters:  multipath_ID      %(user, multipath)
% output parameters: envelope
% read files:        no
% generate files:    no
% call functions:    no
% called by:         wireless_UL, wireless_DL

% Execution Time: case 1: 29/100 Seconds(100 times called)(N=25)
%                 case 2: 4.4/100 Seconds(100 times called)(N=25)

% Sun Jianxun, Apr., 02, 2001


function envelope = rayleigh_fading(multipath_ID)

global system_clock 
global condition_basic
global condition_rayleigh
global rayleigh_parameter

frame = system_clock(2); ? % frame number
TS    = system_clock(3);?  % TS number
speed = condition_basic(3);  % speed, 0km/h, 3km/h, 3km/h, or 120km/h
k_user    = multipath_ID(1);  % user number
multipath = multipath_ID(2);  % multipath number
k1k2  = size(condition_rayleigh,2);
d_n1  = ceil(k1k2/2); ? % the default value: d_n1 = d_n2 + 1
d_n2  = floor(k1k2/2);?
f1    = rayleigh_parameter(1, 1:d_n1);
c1    = rayleigh_parameter(2, 1:d_n1);
f2    = rayleigh_parameter(3, 1:d_n2);
c2    = rayleigh_parameter(4, 1:d_n2);
cita1 = condition_rayleigh(multipath, 1:d_n1, k_user);
cita2 = condition_rayleigh(multipath, (d_n1+1):(d_n1+d_n2), k_user);

SamplingInterval = 1;  % case 1, SamplingInterval = (1/8)chip;
                       % case 2, 16 chips.
                       
if speed ~= 0
    switch SamplingInterval
    case 1  % sampling interval is 16 chips.
        if TS ~= 0
            TS_start = (frame-1)*400+(TS-1)*54-1; ? % the start when TS >= 1, relative to TS_clock = [1, 1];
                                                   % 1 frame = 400 (16 chips), 1 TS = 54(16 chips).
        else  % TS == 0
            TS_start = (frame-1)*400-54-22-1;      % the start when TS == 0, relative to TS_clock = [1, 1];
                                                   % 1 (DwPTS+G+UpPTS) = 22(16 chips).
        end                                             
        d_t = TS_start : TS_start + 56;  % length(d_t) = 57 is for interpolation

        M = length(d_t);
        temp1 = zeros(1, M);
        temp2 = zeros(1, M);
        temp = zeros(1, M);
        for loop = 1 : d_n1 
            temp1 = temp1 + c1(loop) * cos(f1(loop)*d_t+cita1(loop));
        end
        for loop = 1 : d_n2
            temp2 = temp2 + c2(loop) * cos(f2(loop)*d_t+cita2(loop));
        end
        temp = temp1 + j * temp2;
                        
        % interpolation: 57 points ==> 7168 points ==> 7040 points
        x  = 0 : M-1;
        xi = 0 : 0.0078125 : M-1;  % 0.0078125 = 1/128
        env = interp1(x, temp, xi, '*linear');  ?% '*linear' for linear interpolation, or '*cubic' for cubic interpolation
        envelope = env(65 : 7104);
        
    case 2  % sampling interval is (1/8)chip.  
        if TS ~= 0
            TS_start = (frame-1)*51200+(TS-1)*6912-64;  % the start when TS >= 1, relative to TS_clock = [1, 1];
                                                        % 1 frame = 51200 (1/8chips), 1 TS = 6912(1/8chips), filter extends 8 chips.
        else  % TS == 0
            TS_start = (frame-1)*51200-6912-2816-64;    % the start when TS == 0, relative to TS_clock = [1, 1];
                                                        % 1 (DwPTS+G+UpPTS) = 2816(1/8chips), filter extends 8 chips.
        end                                             
        d_t = TS_start : TS_start + 6912 - 1 + 16*8;  % filter extends 16 chips(two sides)

        M = length(d_t);
        temp1 = zeros(1, M);
        temp2 = zeros(1, M);
        envelope = zeros(1, M);
        for loop = 1 : d_n1
            temp1 = temp1 + c1(loop) * cos(f1(loop)*d_t+cita1(loop));
        end
        for loop = 1 : d_n2
            temp2 = temp2 + c2(loop) * cos(f2(loop)*d_t+cita2(loop));
        end
        envelope = temp1 + j * temp2;
    otherwise
        error('SamplingInterval must be 1 or 2');
    end
    
else  % speed ==0
    envelope = ones(1, 7040);
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -