0% found this document useful (0 votes)
5 views

Dcc

The document outlines various algorithms and techniques in signal processing and communication, including Gram-Schmidt orthogonalization, Bit Error Rate (BER) estimation for AWGN channels, QPSK modulation and demodulation, 16-QAM modulation, Huffman coding, CRC-CCIT, and convolution coding. Each section provides MATLAB code snippets for implementation, demonstrating the practical application of these concepts. The document serves as a comprehensive guide for understanding and applying these communication techniques.

Uploaded by

Ishwar Y.S
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Dcc

The document outlines various algorithms and techniques in signal processing and communication, including Gram-Schmidt orthogonalization, Bit Error Rate (BER) estimation for AWGN channels, QPSK modulation and demodulation, 16-QAM modulation, Huffman coding, CRC-CCIT, and convolution coding. Each section provides MATLAB code snippets for implementation, demonstrating the practical application of these concepts. The document serves as a comprehensive guide for understanding and applying these communication techniques.

Uploaded by

Ishwar Y.S
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

Gram Schmidt legend(arrayfun(@(i) ['v',


Orthogonalization num2str(i), ', u', num2str(i)], 1:n,
n = input('Enter the number of 'UniformOutput', false));
vectors: '); grid on;
d = input('Enter the dimension of axis equal;
vectors (e.g., 3 for 3D): '); title('Gram-Schmidt
V = zeros(d, n); Orthogonalization');
for i = 1:n hold off;
V(:, i) = input(['Enter vector ', disp('Original Vectors:');
num2str(i), ': ']); disp(V);
end disp('Orthonormal Vectors:');
U = zeros(d, n); disp(U);
for i = 1:n
U(:, i) = V(:, i); 2. Estimation of BER for AWGN
for j = 1:i-1 channel using Matched Filter
U(:, i) = U(:, i) - (dot(U(:, j), Receiver
V(:, i)) / dot(U(:, j), U(:, j))) * N = 1e5;
U(:, j); Eb_N0_dB = -10:2:10;
end Fs = 10;
U(:, i) = U(:, i) / norm(U(:, i)); pulse_duration = 1;
end data = randi([0 1], 1, N);
figure; pulse_shape = ones(1, Fs *
hold on; pulse_duration);
colors = 'rgbcm'; signal_tx = 2 * data - 1;
for i = 1:n signal_tx = upsample(signal_tx,
quiver3(0, 0, 0, V(1, i), V(2, i), Fs);
V(3, i), colors(i), 'LineWidth', 2, signal_tx = conv(signal_tx,
'MaxHeadSize', 0.5); pulse_shape, 'same');
quiver3(0, 0, 0, U(1, i), U(2, i), matched_filter = pulse_shape;
U(3, i), [colors(i), '--'], BER = zeros(1,
'LineWidth', 2, 'MaxHeadSize', length(Eb_N0_dB));
0.5); for i = 1:length(Eb_N0_dB)
end Eb_N0 = 10^(Eb_N0_dB(i) /
xlabel('X'); 10);
ylabel('Y'); noise_var = 1 / (2 * Eb_N0);
zlabel('Z'); noise = sqrt(noise_var) *
randn(1, length(signal_tx));
signal_rx = signal_tx + noise; t=[t1:(Tb/100):t2];
signal_rx_filtered = symbol =2*m(i)+m(i+1);
conv(signal_rx, matched_filter, switch symbol
'same'); case 0
signal_rx_sampled = m_s1=-
signal_rx_filtered(Fs/2:Fs:end); 1*ones(1,length(t));
data_rx = signal_rx_sampled > m_s2=-
0; 1*ones(1,length(t));
errors = sum(data ~= data_rx); case 1
BER(i) = errors / N; m_s1=-
fprintf('Eb/N0: %d dB, BER: 1*ones(1,length(t));
%f\n', Eb_N0_dB(i), BER(i)); m_s2=ones(1,length(t));
end case 2
figure; m_s1=ones(1,length(t));
semilogy(Eb_N0_dB, BER, 'bo-', m_s2=-
'LineWidth', 2); 1*ones(1,length(t));
xlabel('Eb/N0 (dB)'); case 3
ylabel('Bit Error Rate (BER)'); m_s1=ones(1,length(t));
title('BER for Rectangular Pulse m_s2=ones(1,length(t));
in AWGN Channel'); end
grid on; qpsk_signal((i-1)*length(t)
+1:i*length(t))=c1.*m_s1+c2.*m
3. QPSK Modulation and _s2;
Demodulation
Tb=1; symbols=[symbols;m_s1(1),m_s
t=0:(Tb/100):Tb; 2(1)];
fc=1; subplot(3,2,4);
c1=sqrt(2/Tb)*cos(2*pi*fc*t); plot(t,qpsk_signal((i-
c2=sqrt(2/Tb)*cos(2*pi*fc*t); 1)*length(t)+1:i*length(t)))
N=8; title('QPSK Signal')
m=randi([0 1],1,N); xlabel('t------>');
t1=0; ylabel('s(t)');
t2=Tb; grid on;
qpsk_signal=zeros(1,length(t)*N) hold on;
; t1=t1+(Tb+0.01);
symbols=[]; t2=t2+(Tb+0.01);
for i = 1:2:(N-1) end
hold off; elseif (x1<0 && x2>0)
subplot(3,2,1); demod(i)=1;
stem(m); demod(i+1)=1;
title('Binary Data Bits') end
xlabel('t------>'); t1=t1+(Tb+0.01);
ylabel('b(n)'); t2=t2+(Tb+0.01);
grid on; end
subplot(3,2,2); subplot(3,2,5);
plot(t,c1); stem(demod);
title('Carrier Signal 1') title('QPSK Demodulated Bits')
xlabel('t------>'); xlabel('n------>');
ylabel('c1(t)'); ylabel('b(n)');
grid on; grid on;
subplot(3,2,3); subplot(3,2,6);
plot(t,c2); scatter(symbols(:,i),symbols(:,2),'
title('Carrier Signal 2') filled');
xlabel('t------>'); axis equal;
ylabel('c2(t)'); title('QPSK Constellation
grid on; Diagram');
t1=0; xlabel('In-Phase (I)');
t2=Tb; ylabel('Quadrature (Q)');
demod=zeros(1,N); grid on;
for i=1:N-1 xlim([-2 2]);
t=[t1:(Tb/100):t2]; ylim([-2 2]);
x1=sum(c1.*qpsk_signal((i- grid on;
1)*length(t)+1:i*length(t))); hold on;
x2=sum(c2.*qpsk_signal((i-
1)*length(t)+1:i*length(t))); 4. 16-QAM Modulation
if (x1>0 && x2>0) N = 1000;
demod(i)=1; M = 16;
demod(i+1)=1; SNR = 30;
elseif (x1>0 && x2<0) bits = randi([0 1], N, 1);
demod(i)=1; symbols = reshape(bits, [],
demod(i+1)=1; log2(M));
elseif (x1<0 && x2<0) symbols_dec = bi2de(symbols);
demod(i)=1; qam_modulated =
demod(i+1)=1; qammod(symbols_dec, M);
received_signal = 6. Hamming Code
awgn(qam_modulated, SNR); n = 7;
scatterplot(received_signal); k = 4;
title('16-QAM Constellation with A = [1 1 1; 1 1 0; 1 0 1; 0 1 1];
AWGN'); G = [eye(k) A];
xlabel('I'); H = [A' eye(n-k)];
ylabel('Q'); msg = [1 1 1 1];
grid on; code = mod(msg * G, 2);
code(2) = ~code(2);
5. Huffman Code recd = code;
symbol = [1:5]; syndrome = mod(recd * H', 2);
p = [0.4 0.2 0.2 0.1 0.1]; find = 0;
[dict, avglen] = for ii = 1:n
huffmandict(symbol, p); if ~find
symbolcode = dict{5, 2}; errvect = zeros(1, n);
dict{1, :} errvect(ii) = 1;
dict{2, :} search = mod(errvect * H',
dict{3, :} 2);
dict{4, :} if search == syndrome
dict{5, :} find = 1;
hcode = huffmanenco(symbol, index = ii;
dict); end
dhsig = huffmandeco(hcode, end
dict); end
disp('encoded message:') disp(['Position of error in
disp(hcode) codeword=', num2str(index)]);
disp('decoded message:') correctedcode = recd;
disp(dhsig) correctedcode(index) =
code_length = length(hcode); mod(recd(index) + 1, 2);
sum = 0; msg_decoded = correctedcode;
for m = 1:5 msg_decoded =
H = sum + (p(m) * log2(1 / msg_decoded(1:4);
p(m))); disp('Decoded message:');
end disp(msg_decoded);
disp('H=')
disp(H)
Efficiency = (H / avglen) * 100;
7. CRC-CCIT 8. Convolution Code
function crc_check() msg = [1 1 0 0 1 0];
msg = input('Enter bit pattern: encoded = convenc(msg,
', 's'); poly2trellis(3, [7 5]));
gen_poly = disp('Encoded Data:');
'10001000000100001'; disp(encoded);
crc_code = [msg, decoded = vitdec(encoded,
crc_division([msg, repmat('0', 1, poly2trellis(3, [7 5]),
16)], gen_poly)]; length(msg), 'trunc', 'hard');
disp(['CRC: ', crc_code]); disp('Decoded Data:');
received_code = disp(decoded);
input('Received code: ', 's');
if
all(crc_division(received_code,
gen_poly) == '0')
disp('No error');
else
disp('Error detected');
end
end
function remainder =
crc_division(msg, gen_poly)
for i = 1:length(msg)-
length(gen_poly)+1
if msg(i) == '1'
msg(i:i+length(gen_poly)-1) =
xor(msg(i:i+length(gen_poly)-1)
== '1', gen_poly == '1') + '0';
end
end
remainder = msg(end-15:end);
end

You might also like