-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbpsk_random_orthogonal_H.m
51 lines (39 loc) · 1.03 KB
/
bpsk_random_orthogonal_H.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
clear
N = 10^6; % number of bits or symbols
rand('seed',1); % initializing the rand() function so that random bits produced are same in every simulation
randn('seed',1);
% Transmitter
ip1 = rand(1,N/2)>0.5; % generating 0,1 with equal probability
ip2 = rand(1,N/2)>0.5;
ip=[ip1;ip2];
% BPSK modulation
m1 = 2*ip1-1; % 0 -> -1; 1 -> 1
m2 = 2*ip2-1;
msg=[m1;m2];
SNR = -3:10 ; % in dB
nErr=zeros(length(SNR),1); %initializing error with 0.
h1 = 1/sqrt(2)*(randn(1,1) + 1i*randn(1,1));
h2 = 1/sqrt(2)*(randn(1,1) + 1i*randn(1,1));
h=[h1,h2;-conj(h2),conj(h1)];
hin=pinv(h);
s = h * msg;
for ii = 1:length(SNR)
%Addition Of Noise
y = awgn(s,SNR(ii));
% receiver - zero forcing decoding
xg = hin * y;
sr = real(xg) > 0;
% counting the errors
nErr(ii) = size(find(ip - sr),1);
end
simBer = nErr/N; % simulated ber
% plot
close all
figure
semilogy(SNR,simBer,'b.-');
axis([-3 10 10^-5 0.7])
grid on
legend( 'simulation');
xlabel('SNR, dB');
ylabel('Bit Error Rate');
title('Bit error probability curve for BPSK modulation');