1 function RRC_PSK_BER_SNR(rolloff, M, numSymbs)
2 %% Set defaults for inputs
14 pkg load communications
17 %% https://www.mathworks.com/help/signal/ref/rcosdesign.html
18 %% https://www.mathworks.com/help/comm/ug/pulse-shaping-using-a-raised-cosine-filter.html
19 span = 6; % filter span
22 rrcFilter = rcosdesign(rolloff, span, sps, 'sqrt');
25 EbN0 = 10 .^ (EbN0_db ./ 10);
31 EsN0 = EbN0 .* log2(M);
32 EsN0_db = 10 .* log10(EsN0);
34 plotlen = length(EbN0);
36 ber = zeros(1, plotlen);
38 data = randi([0 M - 1], numSymbs, 1);
39 modData = pskmod(data, M, 0, 'gray');
41 txSig = upfirdn(modData, rrcFilter, sps);
44 snr = EbN0_db(i) + 10 * log10(log2(M));% - 10 * log10(sps); % why sps?
45 rxSig = awgn(txSig, snr);
47 rxFilt = upfirdn(rxSig, rrcFilter, 1, sps);
48 rxFilt = rxFilt(span + 1 : end - span); % remove filter delay
50 demodData = pskdemod(rxFilt, M, 0, 'gray');
52 [bitErrors, ber(i)] = biterr(data, demodData);
58 %% Plot simulated results
59 semilogy(EbN0_db, ber, 'r', 'LineWidth', 2);
62 %% Plot theoretical curve
63 %% BPSK: bit error when noise Nr > sqrt(Eb)
65 %% = Pr(Z > sqrt(Eb) / sqrt(N0/2))
67 %% QPSK = 2 BPSKs, one real and one imaginary, each with one bit
68 %% so BER is the same as BPSK (assuming Gray code)
70 ber_th = qfunc(sqrt(2 * EbN0));
71 semilogy(EbN0_db, ber_th, 'b', 'LineWidth', 1);
72 legend('Simulated RRC', 'Discrete');
74 %% Approximation: J.G. Proakis and M. Salehi, 2000, Contemporary
75 %% Communication Systems using MATLAB (Equations
76 %% 7.3.18 and 7.3.19), Brooks/Cole.
77 ber_ap = 2 * qfunc(sqrt(EbN0 * log2(M) * 2) * sin(pi / M)) / log2(M);
78 semilogy(EbN0_db, ber_ap, 'b', 'LineWidth', 1);
79 legend('Simulated RRC', 'Discrete');
82 title(strcat(num2str(M), '-PSK RRC with Gray code'));
84 xlabel('$E_b/N_0$ (dB)');
88 %saveas(gcf, strcat('BER_SNR_', num2str(M), 'PSK_', num2str(numSymbs), ...
92 %eyediagram(rxFilt, sps);