clear
close all
M = 16; % Modulation order (alphabet size or number of points in signal constellation)
k = log2(M); % Number of bits per symbol
n = 30000; % Number of bits to process
sps = 1; % Number of samples per symbol (oversampling factor)
rng default;
dataIn = randi([0 1],n,1); % Generate vector of binary data
dataInMatrix = reshape(dataIn,length(dataIn)/k,k);
dataSymbolsIn = bi2de(dataInMatrix);
dataMod = qammod(dataSymbolsIn,M); % Gray coding with phase offset of zero
EbNo = 10;
snr = EbNo+10*log10(k)-10*log10(sps);
receivedSignal = awgn(dataMod,snr,'measured');
receivedSignal=receivedSignal.*exp(1j*pi*0.2);
colour=linspace(1,10,16);
C=colour(dataSymbolsIn+1);
figure
scatter(real(receivedSignal),imag(receivedSignal),2,C)
title('received symbol')
print(gcf,'-dpng','-r300','received symbol.png')
figure
scatter(real(dataMod),imag(dataMod),180,C,'filled')
title('transmitted symbol')
print(gcf,'-dpng','-r300','transmitted symbol.png')
python
import numpy as np
import matplotlib.pyplot as plt
from math import pi
k=2
M=2**k
symLen=2**13
np.random.seed(2)
txSymbols = np.random.randint(0,4,size=symLen)
#plt.scatter(txSymbols.real,txSymbols.imag,c=txSymbols,cmap=plt.cm.Set1)
rxSymbols=txSymbols*np.exp(1j*pi*0.15)
plt.scatter(rxSymbols.real,rxSymbols.imag,c=txSymbols,cmap=plt.cm.Set1)
原文链接:https://blog.csdn.net/Stephanie2014/article/details/108781004