X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=discretePSK_BER_SNR.m;h=cdff01ffef4ecffa2701edc171d4bd6bebfbd96c;hb=4fb42ae8b219be3b6644f829583584d249bf139d;hp=fd8849cf8acc1f66182a3f12ccb4e6af999bb0fe;hpb=4dd65313fe9d62a850be15de41afe4b3549723f2;p=4yp.git diff --git a/discretePSK_BER_SNR.m b/discretePSK_BER_SNR.m index fd8849c..cdff01f 100644 --- a/discretePSK_BER_SNR.m +++ b/discretePSK_BER_SNR.m @@ -1,16 +1,12 @@ -function discretePSK_BER_SNR(M, numBits) +function discretePSK_BER_SNR(M, numSymbs) %% Set defaults for inputs if nargin < 2 - numBits = 1000; + numSymbs = 1000; end if nargin < 1 M = 2; end - if isOctave() - pkg load communications - end - EbN0_db = 0:0.2:10; EbN0 = 10 .^ (EbN0_db ./ 10); @@ -25,7 +21,7 @@ function discretePSK_BER_SNR(M, numBits) ber = zeros(1, plotlen); - data = randi([0, M - 1], 1, numBits); + data = randi([0, M - 1], 1, numSymbs); txsig = pskmod(data, M, 0, 'gray'); for i = 1:plotlen @@ -35,35 +31,19 @@ function discretePSK_BER_SNR(M, numBits) [bitErrors, ber(i)] = biterr(data, demodData); end - fig1 = figure(1); + figure(1); clf; %% Plot simulated results semilogy(EbN0_db, ber, 'r', 'LineWidth', 2); hold on; - %% Plot theoretical curve - %% BPSK: bit error when noise Nr > sqrt(Eb) - %% Pr(Nr > sqrt(Eb)) - %% = Pr(Z > sqrt(Eb) / sqrt(N0/2)) - %% - %% QPSK = 2 BPSKs, one real and one imaginary, each with one bit - %% so BER is the same as BPSK (assuming Gray code) + theoreticalPSK(EbN0_db, M, 'b', 'LineWidth', 1); + if M == 2 || M == 4 - ber_th = qfunc(sqrt(2 * EbN0)); - semilogy(EbN0_db, ber_th, 'b', 'LineWidth', 1); legend('Simulated', 'Theoretical'); else - %% Upper bound: R. Venkataramanan, Lent 2018, 3F4 Examples Paper 2 - %% (Question 5), CUED. - %% Approximation: J.G. Proakis and M. Salehi, 2000, Contemporary - %% Communication Systems using MATLAB (Equations - %% 7.3.18 and 7.3.19), Brooks/Cole. - ber_ub = 2 * qfunc(sqrt(EbN0 * log2(M)) * sin(pi / M)); - ber_ap = 2 * qfunc(sqrt(EbN0 * log2(M) * 2) * sin(pi / M)) / log2(M); - semilogy(EbN0_db, ber_ub, 'b', 'LineWidth', 1); - semilogy(EbN0_db, ber_ap, 'g', 'LineWidth', 1); - legend('Simulated', 'Upper bound', 'Approximation'); + legend('Simulated', 'Approximation'); end title(strcat(num2str(M), '-PSK with Gray code')); @@ -72,6 +52,6 @@ function discretePSK_BER_SNR(M, numBits) ylabel('BER'); formatFigure; - saveas(gcf, strcat('BER_SNR_', num2str(M), 'PSK_', num2str(numBits), ... - '.svg')); + %saveas(gcf, strcat('BER_SNR_', num2str(M), 'PSK_', num2str(numSymbs), ... + % '.svg')); end