clear
clc
close all
BitStreamLength = 10^6;
BitStream = rand(1, BitStreamLength) > 0.5;
%将bit流分成两串
[BitStreamOne, BitStreamTwo ] = SerialToParallel( BitStream);
%QPSK映射编码
[I_SymbolsTx, Q_SymbolsTx] = QPSKEncoder(BitStreamOne, BitStreamTwo);
%得到QPSK信号
QPSKsig = I_SymbolsTx+1i*Q_SymbolsTx;
%能量进行归一化
QPSKsig = QPSKsig./sqrt(2);
%通过AWGN信道
ReceivedQPSKsig = awgn(QPSKsig,20);
% 4QAM
figure(1)
plot(ReceivedQPSKsig,'.');
xlabel('In-Phase');ylabel('Quadrature');
axis([-1 1 -1 1]);
%% QDB
QDBBitStreamOne = QDBEncoder(BitStreamOne);
QDBBitStreamTwo = QDBEncoder(BitStreamTwo);
QDBBitStream = ParallelToStream(QDBBitStreamOne,QDBBitStreamTwo);
%得到9QAM信号
QAM9sig = QDBBitStreamOne+1i*QDBBitStreamTwo;
%能量进行归一化
QAM9sig = QAM9sig./sqrt(8);
%通过AWGN信道
ReceivedQAM9sig = awgn(QAM9sig,20);
%9QAM
figure(2)
plot(ReceivedQAM9sig,'.','Color','r');
xlabel('In-Phase');ylabel('Quadrature');
axis([-1 1 -1 1]);
RealRecoveredSig= real(ReceivedQAM9sig);
ImagRecoveredSig = imag(ReceivedQAM9sig);
[RealRxQDB,ImagRxQDB,] = QAM9Decoder(RealRecoveredSig,ImagRecoveredSig);
RXQDB = ParallelToStream(RealRxQDB,ImagRxQDB);
% QDB译码
RecoveryBits = QDBDecoder(RXQDB);
ErrorNum = size(find(BitStream-RecoveryBits),2);
BER = ErrorNum/length(RecoveryBits);
% %% 频谱图
% F_QAM9sig = fftshift(fft(QAM9sig./length(QAM9sig)));
% FSingle_QAM9sig = F_QAM9sig(1:length(QAM9sig)/2);
% figure(3)
% plot(1:length(F_QAM9sig), 20*log10(abs(F_QAM9sig)),'Color','r');grid on;
%% CAP信号的频谱图
F_QAM9sig = fft(QAM9sig./length(QAM9sig));
FSingle_QAM9sig = F_QAM9sig(1:length(QAM9sig)/2);
Tsamping = 1/100; %微秒
SamplingNum = length(F_QAM9sig);
for i = 1:length(FSingle_QAM9sig)
F_xlabel(i) = (i-1)/(SamplingNum*Tsamping);
end
figure(5)
plot(F_xlabel, 20*log10(abs(FSingle_QAM9sig)),'r');grid on;
% title('The spectra of CAP-4 signal');
% xlim([0 50]);ylim([-53 -50]);
xlabel('Frequency(MHz)');ylabel('Amplitude(dB)');
% F_QPSKsig = fft(QPSKsig./length(QPSKsig));
% FSingle_QPSKsig = F_QPSKsig(1:length(F_QPSKsig)/2);
% figure(4)
% plot(1:length(FSingle_QPSKsig), 20*log10(abs(FSingle_QPSKsig)));grid on;