代码解释clc; clear; close all; warning off; addpath(genpath(pwd)); LENS = 30000; SNRs1 = [0:2:18]; figure; %MRC mrcber = []; for snr=SNRs1 snr signal = round(rand(LENS, 1)); datqpsk = bi2de(reshape(signal, [], 2)); Vqpsk = qammod(datqpsk, 4)/sqrt(2); channel1 = ch_Rayleigh(zeros(length(Vqpsk), 1), 0); channel2 = ch_Rayleigh(zeros(length(Vqpsk), 1), 0); CHqpsk1 = channel1.*Vqpsk; CHqpsk2 = channel2.*Vqpsk; Nqpsk1 = ch_Rayleigh(CHqpsk1, snr); Nqpsk2 = ch_Rayleigh(CHqpsk2, snr); demod_symb = zeros(length(Vqpsk), 1); for i=1:length(Vqpsk) channel = [channel1(i) ; channel2(i)]; received_value = [Nqpsk1(i) ; Nqpsk2(i)]; ls_est_value = [channel'*received_value]/(channel'*channel); demod_symb(i) = OfdmSym(ls_est_value, @(x)(x)); end mrcber = [mrcber ; [1-(sum(demod_symb==datqpsk)/length(Vqpsk))]]; end semilogy(SNRs1, mrcber,'-bs',... 'LineWidth',1,... 'MarkerSize',6,... 'MarkerEdgeColor','k',... 'MarkerFaceColor',[0.9,0.0,0.0]); hold on; xlabel('SNR[db]'); ylabel('BER'); LENS = 30000; SNRs2 = [0:2:16]; %STC stcber = []; for snr=SNRs2 snr signal = round(rand(LENS, 1)); datqpsk = bi2de(reshape(signal, [], 2)); Vqpsk = qammod(datqpsk, 4)/sqrt(2); channel1 = ch_Rayleigh(zeros(length(Vqpsk), 1), 0); channel2 = ch_Rayleigh(zeros(length(Vqpsk), 1), 0); channel3 = ch_Rayleigh(zeros(length(Vqpsk), 1), 0); channel4 = ch_Rayleigh(zeros(length(Vqpsk), 1), 0); demod_symb = zeros(length(Vqpsk), 1); for i=1:2:length(Vqpsk)-1 H0 = [channel1(i), channel2(i); channel2(i)', -channel1(i)']./sqrt(2); H1 = [channel3(i), channel4(i); channel3(i)', -channel4(i)']./sqrt(2); H = [H0 ; H1]; signal = [Vqpsk(i) ; Vqpsk(i+1)]; qpsk_values_l = H*signal; R_symb = ch_Rayleigh(qpsk_values_l, snr); ls_est_values = (H'*H)^-1*(H'*R_symb); demod_symb(i) = OfdmSym(ls_est_values(1), @(x)(x)); demod_symb(i+1) = OfdmSym(ls_est_values(2), @(x)(x)); end stcber = [stcber ; [1-(sum(demod_symb==datqpsk)/length(Vqpsk))]]; end semilogy(SNRs2, stcber,'-mo',... 'LineWidth',1,... 'MarkerSize',6,... 'MarkerEdgeColor','k',... 'MarkerFaceColor',[0.5,0.9,0.0]); LENS = 20000; SNRs3 = [0:2:12];
时间: 2024-04-28 13:21:54 浏览: 189
SSA奇异谱分析做信号分解(MATLAB完整源码和数据)
5星 · 资源好评率100%
这段代码是一个用 MATLAB 编写的通信系统模拟程序,用于模拟两种不同的信道编码方案(MRC和STC)在不同信噪比(SNR)下的误码率(BER)性能。程序首先定义了一些参数,如信号长度(LENS)和不同的信噪比(SNRs1、SNRs2、SNRs3),然后通过循环计算不同 SNR 下的 BER,并将结果绘制成图像。其中 ch_Rayleigh 是一个自定义的 Rayleigh 信道函数,OfdmSym 是一个自定义的解调函数,qammod 是一个 QPSK 调制函数,semilogy 是一个绘制半对数坐标图的函数。
阅读全文