<matalb> CDMA信道仿真-AWGN多径衰落信道
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% 该函数仿真CDMA系统的信道,在输入所需用户序列和其他干扰用户序列后 %
% 在信号上叠加高斯白噪声,干扰用户多径干扰和所需用户的多径干扰和衰落。 %
% 并根据输入延时曲线产生信道延时,输出mul_fad_sequence为信道信号输出 %
% max_delay为信道最大延迟,fade_sign为瑞利信道中最大幅度分量的衰落量 %
% mpath_amp为信道多径的幅度因子 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [mul_fad_sequence,max_delay,fade_sign,rake_rev_sequence,mpath_amp] = cdma_channel_simulation(...
sequence,sf,mpath_delay,eb_no,k_factor)
% sequence 发射机的输出序列
% sf 扩频因子
% mpath_delay 多径传输延时
% snr 信道信噪比
% k_factor 莱斯k因子
mpath_delay = sort(mpath_delay); % 保证多径延时按照升序排列
eb_no_linear = 10^(eb_no/10); % 转换信号噪声比
[signal_row,signal_len] = size(sequence);
if signal_row == 1 % 初始化干扰用户数目
interfering_num = 0;
else
interfering_num = signal_row - 1;
end
%%
mpath_len = length(mpath_delay); % 多径成分,得到多径延迟曲线的长度
mpath_amp(2:mpath_len) = rand(1,mpath_len-1); % 随机生成多径成分幅度
scatter_power = mpath_amp*mpath_amp'; % 多径成分离散功率
mpath_amp(1) = sqrt(scatter_power*k_factor); % 视距成分的幅度(LOS)
[max_mpath_amp,max_index] = max(mpath_amp); % 得到多径分量的最大幅度
mpath_amp = mpath_amp/max_mpath_amp; % 归一化多径衰落幅度,最大幅度因子为1
% 设计衰落信号的IIR滤波器
FilterOrder = 4; Ripple = 0.5; BW = 0.01; % 滤波器阶数为4,通带衰减为0.5,带宽0.01
[b,a] = cheby1(FilterOrder,Ripple,BW); % 得到切比雪夫1型滤波器的参数
%%
%生成信道噪声
noise_amplitude = sqrt(sf/(2*eb_no_linear));
% 计算噪声的强度,如果扩频因子越大,信号对扩频序列的影响也越大
% 信道噪声与信噪比成反比,信噪比越大,噪声幅度越小
max_delay = max(mpath_delay); % 得到最大延时
len = signal_len;
desired_noise = noise_amplitude*randn(1,len+max_delay);
% 所需的噪声序列,长度要比信源序列的长度长最大延时单位
rake_desired_noise = desired_noise(1:len);
%%
mpath_len = length(mpath_delay); % 多径成分的向量长度
interfering_sequence = sequence(2:(interfering_num+1),:);
if interfering_num > 0 % 如果存在干扰器
interfering_signal = zeros(interfering_num,len+max_delay); % 初始化干扰器的信号
rake_interfering_signal = zeros(mpath_len,len);
for k = 1:mpath_len % 利用多径延时曲线成员的数量开始循环
rake_interfering_signal(k,:) = sum(mpath_amp(k)*...
interfering_sequence,1); % 多径叠加,但消除延迟
index = 1+mpath_delay(k):len+mpath_delay(k); % 设置索引号
interfering_signal(:,index) = ... % 多径干扰信号采用加性叠加的方式
interfering_signal(:,index) + ...
mpath_amp(k)*interfering_sequence; % mpath_amp相当于干扰码序列的权重因子
end
end
%%
zf = zeros(FilterOrder,mpath_len);
desired_sequence = sequence(1,:);
desired_mpath_signal = zeros(1,len+max_delay); % 初始化所需的多径信号
rake_mpath_signal = zeros(mpath_len,len);
for k = 1:mpath_len
if k == 1
fading = ones(1,len);
else
fading = randn(1,len/(2^sf-1)) + k*randn(1,len/(2^sf-1));
% 信道模型,瑞利随机过程发生器
[fading zf(:,k)] = filter(b,a,fading,zf(:,k));
fading = interp(fading,(2^sf-1));
fading = abs(fading/sqrt(mean(fading.*conj(fading))));
end
if k == max_index
fade_sign = sign(fading);
end
rake_mpath_signal(k,:) = (mpath_amp(k)*fading).*desired_sequence;
% rake不含延时的所需用户的多径衰落分量
index = 1+mpath_delay(k):len+mpath_delay(k);
desired_mpath_signal(index) = ...
% 利用瑞利随机过程发生器生成的随机衰落序列
desired_mpath_signal(index)+... % 产生衰减的效果
(mpath_amp(k)*fading).*desired_sequence;
end
%%
if interfering_num > 0
% 合并用户多径信号,干扰用户多径信号和信道高斯白噪声
mul_fad_sequence = desired_mpath_signal + ...
sum(interfering_signal,1) + desired_noise;
for k = 1:mpath_len
rake_rev_sequence(k,:) = rake_mpath_signal(k,:) + ...
rake_interfering_signal(k,:) + rake_desired_noise;
end
else
mul_fad_sequence = desired_mpath_signal + desired_noise;
for k = 1:mpath_len
rake_rev_sequence(k,:) = rake_mpath_signal(k,:) + rake_desired_noise;
end
end