实验流程就是按照上面的过程做的,还包含眼图、矢量图、星座图、误码率分析。所有代码全部手敲,注释是用英文写的,给大家分享一下,希望能够对大家有所帮助。
clc
clear all
close all
% Author: Mussy Max
%% Initializtion
symbol =1000; % numbers of symbols
bit = randi([0,1],1,2*symbol); % random bit
fc = 4e3; % carrier freq which determines how many carriers to represent
fs = 100e3; % sampling numbers of each pulse
sps = fs/(2*symbol); %samples of each pulse
T = 1; % time for each bit
figure(1);
subplot(2,1,1)
plot(bit);
title('raw bit');
time_delay = 0; % wether consodering the time delay of filter
%% GrayCode Pre-coding
Gray = [0,0;0,1;1,1;1,0];
bit_gray = [];
for i = 1:symbol
dec = bit(2*i-1)*2+bit(2*i)+1;
bit_gray(2*i-1) = Gray(dec,1);
bit_gray(2*i) = Gray(dec,2);
end
bit_gray = 2*bit_gray-1; % turn to NBRZ
subplot(2,1,2)
plot(bit_gray);
title('gray bit');
%% IQ separation
I_raw = [];Q_raw = [];
for i = 1:symbol
I_raw(i) = bit_gray(2*i-1);
Q_raw(i) = bit_gray(2*i);
end
figure(4); % draw constellation chart
subplot(1,2,1)
plot(I_raw,Q_raw,'*');xlabel('I');ylabel('Q')
axis([-2,2,-2,2]);
title('constellation chart of the transmitter')
figure(11); % draw constellation chart
subplot(1,2,1)
plot(I_raw,Q_raw);xlabel('I');ylabel('Q')
axis([-2,2,-2,2]);
title('vector chart of the transmitter')
%% design a pulse form filter
roff = 0.5;
cutoff_symbols = 6;
fir_rcos = rcosdesign(roff, cutoff_symbols, sps, "sqrt"); % defin