Commit | Line | Data |
---|---|---|
8449f934 AIL |
1 | function passband(rolloff, M, numSymbs) |
2 | %% Set defaults for inputs | |
3 | if nargin < 3 | |
4 | numSymbs = 1000; | |
5 | end | |
6 | if nargin < 2 | |
7 | M = 2; | |
8 | end | |
9 | if nargin < 1 | |
10 | rolloff = 0.5; | |
11 | end | |
12 | ||
8449f934 | 13 | %% https://www.mathworks.com/help/comm/examples/passband-modulation-with-adjacent-channel-interference.html |
1eeb62fb | 14 | Rsym = 2.5e10; % symbol rate (sym/sec) |
8449f934 AIL |
15 | |
16 | span = 6; % filter span | |
17 | sps = 4; % samples per symbol | |
18 | ||
8449f934 AIL |
19 | fs = Rsym * sps; % sampling freq (Hz) |
20 | ||
21 | t = (0 : 1 / fs : numSymbs / Rsym + (1.5 * span * sps - 1) / fs)'; | |
22 | ||
23 | ||
8449f934 AIL |
24 | EbN0_db = 0:0.2:10; |
25 | EbN0 = 10 .^ (EbN0_db ./ 10); | |
26 | ||
27 | Es = 1; | |
28 | Eb = Es / log2(M); | |
29 | N0 = Eb ./ EbN0; | |
30 | ||
31 | EsN0 = EbN0 .* log2(M); | |
32 | EsN0_db = 10 .* log10(EsN0); | |
33 | ||
34 | plotlen = length(EbN0); | |
35 | ||
36 | ber = zeros(1, plotlen); | |
37 | ||
38 | ||
8449f934 AIL |
39 | data = randi([0 M - 1], numSymbs, 1); |
40 | modData = pskmod(data, M, 0, 'gray'); | |
41 | ||
1eeb62fb | 42 | xBaseband = txFilter(modData, rolloff, span, sps); |
a4b0109e | 43 | |
1eeb62fb AIL |
44 | fc = 1e12; % Carrier freq (Hz) |
45 | carrier = sqrt(2) * exp(j * 2 * pi * fc * t); | |
8449f934 | 46 | |
1eeb62fb | 47 | xPassband = xBaseband .* carrier(1:length(xBaseband)); |
8449f934 AIL |
48 | |
49 | for i = 1:plotlen | |
1eeb62fb | 50 | snr = EbN0_db(i) + 10 * log10(log2(M)) - 10 * log10(sps); |
8449f934 AIL |
51 | noiseEnergy = 10 ^ (-snr / 10); |
52 | ||
8449f934 | 53 | yPassband = awgn(xPassband, snr, 'measured'); |
1eeb62fb AIL |
54 | yLO = yPassband .* conj(carrier(1:length(yPassband))); |
55 | rBaseband = rxFilter(yLO, rolloff, span, sps); | |
8449f934 | 56 | |
8449f934 AIL |
57 | rSampled = rBaseband(sps*span/2+1:sps:(numSymbs + span/2) * sps); |
58 | ||
59 | demodData = pskdemod(rSampled, M, 0, 'gray'); | |
60 | [bitErrors, ber(i)] = biterr(data, demodData); | |
8449f934 AIL |
61 | end |
62 | ||
1eeb62fb | 63 | figure(1); |
8449f934 AIL |
64 | clf; |
65 | ||
66 | %% Plot simulated results | |
67 | semilogy(EbN0_db, ber, 'r', 'LineWidth', 2); | |
68 | hold on; | |
69 | ||
1eeb62fb AIL |
70 | theoreticalPSK(EbN0_db, M, 'b', 'LineWidth', 1); |
71 | legend('Simulated RRC', 'Discrete'); | |
8449f934 AIL |
72 | |
73 | title(strcat(num2str(M), '-PSK RRC with Gray code')); | |
74 | grid on; | |
75 | xlabel('$E_b/N_0$ (dB)'); | |
76 | ylabel('BER'); | |
77 | ||
78 | formatFigure; | |
8449f934 | 79 | end |