% 扩频因子不同的情况下,BER与SNR的关系
clear,clc;
N = [1, 3, 5, 7]; % 用户数
n = [3, 5, 7]; % 阶数
M = 2.^n; % 扩频因子
EbN0 = 0:30; % 信噪比[dB]
L = 1e6; % 用户发送数据大小
b = sign(2*rand(max(N), L) - 1);
y0 = 2*rand() - 1;
for i = 1:length(M)
x = chaos(M(i), y0); % 混沌序列
h = walsh(n(i)); % Hadamard矩阵
figure('name', ['扩频因子 M = ', num2str(M(i)), ' 时, 不同用户数下误码率随信噪比的变化曲线']);
for j = 1:length(N)
Eb = (M(i)*(N(j) + 1) / N(j)) * mean(x.^2);
% 选择每个用户的walsh码
w = zeros(N(j), M(i));
index = randperm(M(i));
for m = 1:N(j)
w(m, :) = h(index(m), :);
end
b0 = b(1:N(j), :); % 用户发送的数据
s = modulation(x, b0, w);
BER = zeros(size(EbN0));
for k = 1:length(EbN0)
SNR_liner = 10^(EbN0(k) / 10);
sigma_noise = sqrt(Eb / (2*SNR_liner));
noise = normrnd(0, sigma_noise, size(s));
r = s + noise;
b1 = demodulation(r, w);
[row, col] = size(b0);
BER(k) = sum(sum(abs(b1 - b0))) / (row * col);
end
semilogy(EbN0, BER);
hold on;
end
grid on;
axis([0 20 1e-5 1e0]);
xlabel('Eb/N_0[dB]');
ylabel('BER');
legend('用户数为1', '用户数为3', '用户数为5', '用户数为7', 'location', 'southwest');
hold off;
end
评论0
最新资源