Digital Communication Projects -
MATLAB Code
1. Generation & Detection of Binary Digital Modulation using SDR
fs = 1e6; % Sample rate
fc = 100e3; % Carrier frequency
data = randi([0 1], 1, 1000);
bpskSig = 2*data - 1;
t = (0:length(bpskSig)-1)/fs;
carrier = cos(2*pi*fc*t);
tx = bpskSig .* carrier;
% Receiver side (coherent detection)
rx = tx .* carrier;
rxLPF = lowpass(rx, fc, fs);
received = rxLPF > 0;
2. Spread Spectrum Communication - Baseband DSSS
pn_seq = randi([0 1], 1, length(data)*10);
spread_data = repelem(data, 10) .* (2*pn_seq - 1);
3. MIMO Transceiver Design (2x2 System)
H = randn(2,2) + 1i*randn(2,2);
s = [1; -1]; % BPSK symbols
x = H*s;
r = H\x;
4. CDMA Performance Evaluation
users = 4;
chips = 8;
data = randi([0 1], users, 1);
walsh = hadamard(chips);
encoded = walsh(:,1:users) * (2*data - 1);
noise = randn(chips, 1);
rx = encoded + noise;
decoded = walsh(:,1:users)' * rx;
5. Channel Coder/Decoder - Convolutional Code
trellis = poly2trellis(7, [171 133]);
data = randi([0 1], 100, 1);
encoded = convenc(data, trellis);
noisy = awgn(double(encoded), 5, 'measured');
decoded = vitdec(noisy > 0.5, trellis, 34, 'trunc', 'hard');
6. OFDM Transceiver Design
N = 64;
data = randi([0 1], N, 1);
modData = pskmod(data, 2);
ofdmSignal = ifft(modData);
rx = fft(ofdmSignal);
demodData = pskdemod(rx, 2);
7. Channel Equalizer (LMS)
x = randn(1000,1);
d = filter([1 0.5], 1, x);
e = zeros(size(x));
mu = 0.01;
w = zeros(2,1);
for n = 2:length(x)
y = w'*x(n:-1:n-1);
e(n) = d(n) - y;
w = w + mu * x(n:-1:n-1) * e(n);
end
8. Spectrum Estimators (Bartlett, Welch)
x = randn(1024,1);
[pxx_b, f] = pwelch(x, 128, 64, 128, fs);
[pxx_w, f] = pwelch(x, [], [], [], fs);
9. BER Analysis of M-ary Modulation in AWGN
M = 4; % QPSK
data = randi([0 M-1], 1000, 1);
s = pskmod(data, M);
rx = awgn(s, 10, 'measured');
rxd = pskdemod(rx, M);
ber = sum(rxd ~= data)/length(data);
10. Lossless Coding - Huffman and LZ
symbols = unique(data);
prob = histcounts(data,length(symbols))/length(data);
dict = huffmandict(symbols, prob);
encoded = huffmanenco(data, dict);
decoded = huffmandeco(encoded, dict);
11. Noise / Echo Cancellation (LMS)
x = randn(1000,1);
d = filter([1 0.9], 1, x) + 0.1*randn(1000,1);
mu = 0.01;
w = zeros(2,1);
e = zeros(size(x));
for n = 2:length(x)
y = w'*x(n:-1:n-1);
e(n) = d(n) - y;
w = w + mu * x(n:-1:n-1) * e(n);
end
12. Synchronization (bit-level)
ref = [1 0 1 1 0 1];
seq = [zeros(1,5) ref zeros(1,5)];
[acor, lag] = xcorr(seq, ref);
[~, idx] = max(acor);
start = lag(idx);
13. Wireless Channel Characterization
fs = 1e6;
t = 0:1/fs:1-1/fs;
path_delays = [0 1e-6 3e-6];
path_gains = [0 -3 -6];
chan = rayleighchan(1/fs, 0, path_delays, path_gains);
x = randn(size(t));
y = filter(chan, x);