16qam调制解调matlab代码
时间: 2023-06-01 17:02:36 浏览: 170
以下是16QAM调制解调matlab代码示例:
% 16QAM调制
clear all;
clc;
M = 16; %调制阶数
k = log2(M); %比特数
EbNo = 10; %信噪比
EsNo = EbNo + 10*log10(k); %符号噪比
SNR = EsNo - 10*log10(2); %信噪比
numBits = 10000; %发送位数
data = randi([0 1],numBits,1); %随机生成发送数据比特
% 映射
dataInMatrix = reshape(data,length(data)/k,k);
dataSymbolsIn = bi2de(dataInMatrix);
dataMod = qammod(dataSymbolsIn,M);
% 加噪声
receivedSignal = awgn(dataMod,SNR,'measured');
% 解调
dataSymbolsOut = qamdemod(receivedSignal,M);
dataOutMatrix = de2bi(dataSymbolsOut,k);
dataOut = dataOutMatrix(:);
% 统计误差
[numErrors,ber] = biterr(data,dataOut);
fprintf('\n错误位数 = %d\n比特误码率 = %5.2e\n',numErrors,ber);
% 绘图
scatterplot(dataMod);
title('16QAM调制');
xlabel('实部');
ylabel('虚部');
% 16QAM解调
clear all;
clc;
M = 16; %调制阶数
k = log2(M); %比特数
EbNo = 10; %信噪比
EsNo = EbNo + 10*log10(k); %符号噪比
SNR = EsNo - 10*log10(2); %信噪比
numBits = 10000; %发送位数
data = randi([0 1],numBits,1); %随机生成发送数据比特
% 映射
dataInMatrix = reshape(data,length(data)/k,k);
dataSymbolsIn = bi2de(dataInMatrix);
dataMod = qammod(dataSymbolsIn,M);
% 加噪声
receivedSignal = awgn(dataMod,SNR,'measured');
% 解调
dataSymbolsOut = qamdemod(receivedSignal,M);
dataOutMatrix = de2bi(dataSymbolsOut,k);
dataOut = dataOutMatrix(:);
% 统计误差
[numErrors,ber] = biterr(data,dataOut);
fprintf('\n错误位数 = %d\n比特误码率 = %5.2e\n',numErrors,ber);
% 绘图
scatterplot(dataMod);
title('16QAM调制');
xlabel('实部');
ylabel('虚部');
阅读全文