[求助]为什么这个Matlab程序运行后会出现错误??谢谢
这是在高斯加性白噪声的情况下MPAM调制信道容量的仿真程序。 % -------------------------------------------- begin-------------------------------------------------
snr_indB = -10:1:30;
snr = 10 .^ (0.1 * snr_indB);
EbN0 = [];
C_mpam = [];
logpy = [];
alphabet = [];
trials = 50000;
b = 3;
M = 2 ^ b;
for k = 1 : 1 : M;
alphabet(k) = 2*k - 1 - M;
end
average = sum(alphbet .^ 2) / M; % average energy Es
for i = 1 : 1 : length(snr_indB);
sigma2 = average / snr(i);
for j = 1 : 1 : trials;
x(j) = alphabet(floor(rand * M) + 1);
end
y = x + sqrt(sigma2) * randn(1, trials);
for j = 1 : 1 : trials;
pyx = 0; % compute p(y) from p(y|x)
for k = 1 : 1 : M;
pyx = pyx + exp(-(y(j) - alphabet(k)).^2 / (2*sigma2));
end
logpy(j) = log2(1/M / sqrt(2*pi*sigma2) * pyx(1));
end
C_mpam(i) = -mean(logpy) - 0.5*log2(2*pi * exp(1) * sigma2);
end
EbN0 = 10 * log10(snr ./ C_mpam / 2);
plot(snr_indB, C_mpam, 'k-');
%plot(EbN0, C_mpam, 'k-');
2-37
hold on;
C = []; % Shannon capacity
for i = 1 : 1 : length(snr_indB);
C(i) = 0.5 * log2(1 + snr(i));
EbN0(i) = 10 * log10(snr(i) / C(i) / 2);
end
plot(snr_indB, C, 'b-');
%plot(EbN0, C, ‘b-‘);
legend('M-PAM bound', 'Shannon bound');
xlabel('SNR (dB)');
%xlabel('Eb/N0 (dB)');
ylabel('Capacity (bits/symbol)');
grid on;
% ---------------------------------------- end -----------------------------------------------------
运行之后结果显示average = sum(alphbet .^ 2) / M; 出错,不知道怎么回事
而且老师要求重要的程序行后面要注释(就是解释一下这个句子是什么意思),哪位高手能帮我解决一下啊?后天要交论文,很着急,万分谢谢了!!!