├── FIR Channel Blind Equalization.pdf ├── HMM non-linear channel ├── HMM_ENTRY.m ├── INPUT_TEXT.m ├── Lfunction_scaling1_L1.m ├── MESSAGE_RECEIVER.m ├── Make_plot_L1.m ├── Map_estimate_L1.m ├── backward_scaling1_L1.m ├── decoding_bin2text.m ├── encoding_text2bin.m ├── forward_L1.m ├── forward_scaling1_L1.m ├── hmmgen_L1.m ├── hmmparameter_scaling1_reestimate_L1.m ├── run_program1_original.m ├── run_program2_SNR_accuracy.m ├── run_program3_SNR_plot.m └── run_program4_ASCII_COMM.m ├── LICENSE ├── README.md └── hmm with channel memory=2 ├── HMM_ENTRY.m ├── INPUT_TEXT.m ├── Lfunction_scaling1_L1.m ├── MESSAGE_RECEIVER.m ├── Make_plot_L1.m ├── Map_estimate_L1.m ├── backward_scaling1_L1.m ├── decoding_bin2text.m ├── encoding_text2bin.m ├── forward_L1.m ├── forward_scaling1_L1.m ├── hmmgen_L1.m ├── hmmparameter_scaling1_reestimate_L1.m ├── run_program1_original.m ├── run_program2_SNR_accuracy.m ├── run_program3_SNR_plot.m └── run_program4_ASCII_COMM.m /FIR Channel Blind Equalization.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qchen7/FIR-Channel-Blind-Equalization-based-on-HMM-and-EM-Algorithm/156ec0936684b74260e6938d07c35b6b70241732/FIR Channel Blind Equalization.pdf -------------------------------------------------------------------------------- /HMM non-linear channel/HMM_ENTRY.m: -------------------------------------------------------------------------------- 1 | function [A, S, X, O] = HMM_ENTRY(T, h, Nvar, A_bin) 2 | 3 | %O is the observation sequence. T is the 4 | %length of the HMM. L is the length of the channel memory(L=1 in this case). H is the column vector 5 | %which has linear channel coefficients as its elements. Nvar is the noise variance 6 | %for Gaussian distribution. 7 | 8 | A = 2*(bin2dec(A_bin).')-1; %%%%S(1) is initilized 9 | S = zeros(T+1, 2); %%%%%specify S(2) to S(T+1) 10 | O = zeros(T, 1); 11 | for j = 1:2 12 | S(1,j) = 2 * randi([0 1],1,1) - 1; 13 | end 14 | 15 | for i = 2:T+1 16 | S(i,1) = A(i-1); 17 | S(i,2) = S(i-1,1); 18 | end 19 | 20 | X = zeros(T, 3); 21 | for i = 1:T %%%%%specify transition branch 22 | X(i,1) = A(i); 23 | X(i,2:3) = S(i,:); 24 | end 25 | 26 | for i = 1:T %output received by the receiver 27 | index = (X(i,1)+1)/2*4 + (X(i,2)+1)/2*2 + (X(i,3)+1)/2 + 1; 28 | O(i) = normrnd(h(index),Nvar); 29 | end -------------------------------------------------------------------------------- /HMM non-linear channel/INPUT_TEXT.m: -------------------------------------------------------------------------------- 1 | function str = INPUT_TEXT 2 | prompt = 'What is the original text? '; 3 | str = input(prompt, 's'); 4 | -------------------------------------------------------------------------------- /HMM non-linear channel/Lfunction_scaling1_L1.m: -------------------------------------------------------------------------------- 1 | function [L_funct_s, L_Y] = Lfunction_scaling1_L1(O, h_est, Nvar_est, tr, T) 2 | 3 | %choose tr(n) in tr matrix will be in column order. Since we number all 4 | %possible transtion branches in a left-msb based method. tr(n) will 5 | %exactly represent the nth transition brach probability. e.g we number xt = 6 | %[st+1,st] = [0,1] as 2. 7 | %from 1->0 we should take tr(1,0) = tr(2).(Assume that tr(i,j) represents the transition probability Si -> Sj in state space) 8 | 9 | 10 | 11 | %t = 1:T and k = 1:4 12 | %i = mod (k-1,2) + 1 13 | %j = floor((k-1)/2) + 1 14 | 15 | [alpha_s, ~] = forward_scaling1_L1(O, h_est, Nvar_est, tr, T); 16 | beta_s = backward_scaling1_L1(O, h_est, Nvar_est, tr, T); 17 | 18 | L_funct_s = zeros(T,8); 19 | overflow = log(1.79769313486231570E+308); 20 | underflow = log(4.94065645841246544E-324); 21 | 22 | for t = 1:T 23 | for k = 1:8 24 | i = mod (k-1,4) + 1; 25 | j = floor((k-1)/2) + 1; 26 | L_funct_s(t,k) = -log(sqrt(2*pi*Nvar_est))-(O(t)-h_est(k))^2/(2*Nvar_est)+log(tr(j,i))+log(alpha_s(t,i))+log(beta_s(t+1,j)); 27 | if L_funct_s(t,k) < underflow 28 | L_funct_s(t,k) = underflow; 29 | elseif L_funct_s(t,k) > overflow 30 | L_funct_s(t,k) = overflow; 31 | end 32 | L_funct_s(t,k) = exp(L_funct_s(t,k)); 33 | end 34 | end 35 | 36 | alpha = forward_L1(O, h_est, Nvar_est, tr, T); 37 | L_Y = 0; 38 | for m = 1:4 39 | L_Y = L_Y + alpha(T+1,m); 40 | end 41 | 42 | 43 | -------------------------------------------------------------------------------- /HMM non-linear channel/MESSAGE_RECEIVER.m: -------------------------------------------------------------------------------- 1 | function [A_est, accuracy] = MESSAGE_RECEIVER(T, L_funct_s_test, A) 2 | 3 | A_est = zeros(1,T); 4 | accuracy = 0; 5 | 6 | for t = 1:T 7 | if(L_funct_s_test(t,1)+L_funct_s_test(t,2)+L_funct_s_test(t,3)+L_funct_s_test(t,4) >= L_funct_s_test(t,5)+L_funct_s_test(t,6)+L_funct_s_test(t,7)+L_funct_s_test(t,8)) 8 | A_est(t) = -1; 9 | else 10 | A_est(t) = 1; 11 | end 12 | if A_est(t) == A(t) 13 | accuracy = accuracy + 1; 14 | end 15 | end 16 | 17 | A_est = (A_est'+1)/2; 18 | 19 | accuracy = accuracy / T; -------------------------------------------------------------------------------- /HMM non-linear channel/Make_plot_L1.m: -------------------------------------------------------------------------------- 1 | function Make_plot_L1(A, A_est, O, T, h, h_vector, L_Y_vector, n) 2 | n1 = 0:n; 3 | hline_n = zeros(8,n+1); 4 | t= 1:T; 5 | hline = zeros(8,T); 6 | 7 | for n2 = 0:n; 8 | for k = 1:8 9 | hline_n(k,n2+1) = h(k); 10 | end 11 | end 12 | for t1 = 1:T; 13 | for k = 1:8 14 | hline(k,t1) = h(k); 15 | end 16 | end 17 | 18 | close all; 19 | plot(n1,hline_n(1,n1+1),'--k'); 20 | hold on; 21 | plot(n1,hline_n(2,n1+1),'--k'); 22 | hold on; 23 | plot(n1,hline_n(3,n1+1),'--k'); 24 | hold on; 25 | plot(n1,hline_n(4,n1+1),'--k'); 26 | hold on; 27 | plot(n1,hline_n(5,n1+1),'--k'); 28 | hold on; 29 | plot(n1,hline_n(6,n1+1),'--k'); 30 | hold on; 31 | plot(n1,hline_n(7,n1+1),'--k'); 32 | hold on; 33 | plot(n1,hline_n(8,n1+1),'--k'); 34 | hold on; 35 | axis([0 n -2 2]); 36 | title('Channel Output Estimation') 37 | xlabel('n (number of iterations)'); 38 | ylabel('h'); 39 | pause(5); 40 | 41 | % plot(n1,h_vector(1,n1+1)); 42 | % hold on; 43 | % plot(n1,h_vector(2,n1+1)); 44 | % hold on; 45 | % plot(n1,h_vector(3,n1+1)); 46 | % hold on; 47 | % plot(n1,h_vector(4,n1+1)); 48 | % hold on; 49 | % plot(n1,h_vector(5,n1+1)); 50 | % hold on; 51 | % plot(n1,h_vector(6,n1+1)); 52 | % hold on; 53 | % plot(n1,h_vector(7,n1+1)); 54 | % hold on; 55 | % plot(n1,h_vector(8,n1+1)); 56 | 57 | l1=line(NaN,NaN, 'Marker', 'o', 'linesty','-','erasemode','none'); 58 | l2=line(NaN,NaN, 'Marker', 'o', 'linesty','-','erasemode','none'); 59 | l3=line(NaN,NaN, 'Marker', 'o', 'linesty','-','erasemode','none'); 60 | l4=line(NaN,NaN, 'Marker', 'o', 'linesty','-','erasemode','none'); 61 | l5=line(NaN,NaN, 'Marker', 'o', 'linesty','-','erasemode','none'); 62 | l6=line(NaN,NaN, 'Marker', 'o', 'linesty','-','erasemode','none'); 63 | l7=line(NaN,NaN, 'Marker', 'o', 'linesty','-','erasemode','none'); 64 | l8=line(NaN,NaN, 'Marker', 'o', 'linesty','-','erasemode','none'); 65 | tt = 1:n+1; 66 | 67 | for test1 = 1:n+1; 68 | set(l1, 'xdata', n1(1:test1), 'ydata', h_vector(1,tt(1:test1))); 69 | 70 | set(l2, 'xdata', n1(1:test1), 'ydata', h_vector(2,tt(1:test1))); 71 | 72 | set(l3, 'xdata', n1(1:test1), 'ydata', h_vector(3,tt(1:test1))); 73 | 74 | set(l4, 'xdata', n1(1:test1), 'ydata', h_vector(4,tt(1:test1))); 75 | 76 | set(l5, 'xdata', n1(1:test1), 'ydata', h_vector(5,tt(1:test1))); 77 | 78 | set(l6, 'xdata', n1(1:test1), 'ydata', h_vector(6,tt(1:test1))); 79 | 80 | set(l7, 'xdata', n1(1:test1), 'ydata', h_vector(7,tt(1:test1))); 81 | 82 | set(l8, 'xdata', n1(1:test1), 'ydata', h_vector(8,tt(1:test1))); 83 | 84 | 85 | pause(0.35); 86 | end 87 | % subplot(1,2,2); 88 | % plot(n1,L_Y_vector(1,n1+1)); 89 | % title('Weighted likelihood function') 90 | % xlabel('n (number of iterations)'); 91 | % ylabel('Likelihood function'); 92 | % 93 | % 94 | % figure(2); 95 | % plot(t,hline(1,t),'--k'); 96 | % hold on; 97 | % plot(t,hline(2,t),'--k'); 98 | % hold on; 99 | % plot(t,hline(3,t),'--k'); 100 | % hold on; 101 | % plot(t,hline(4,t),'--k'); 102 | % hold on; 103 | % plot(t,hline(5,t),'--k'); 104 | % hold on; 105 | % plot(t,hline(6,t),'--k'); 106 | % hold on; 107 | % plot(t,hline(7,t),'--k'); 108 | % hold on; 109 | % plot(t,hline(8,t),'--k'); 110 | % hold on; 111 | % plot(t,O(t),'+',t,O(t)); 112 | % xlim([0 T]); 113 | % title('Observed sequence'); 114 | % xlabel('t'); 115 | % ylabel('O(t)'); 116 | % 117 | % t1 = [t;t+1]; 118 | % t2 = t1(:); 119 | % A1 = [A;A]; 120 | % A2 = A1(:); 121 | % A_est1 = [A_est;A_est]; 122 | % A_est2 = A_est1(:); 123 | % 124 | % figure(3); 125 | % subplot(2,1,1); 126 | % plot(t2,A2); 127 | % axis([1 T+1 -1.5 1.5]); 128 | % title('Orignial information symbols'); 129 | % xlabel('t'); 130 | % ylabel('A(t)'); 131 | % 132 | % subplot(2,1,2); 133 | % plot(t2,A_est2); 134 | % axis([1 T+1 -1.5 1.5]); 135 | % title('Estimated information symbols'); 136 | % xlabel('t'); 137 | % ylabel('A_est(t)'); 138 | 139 | 140 | -------------------------------------------------------------------------------- /HMM non-linear channel/Map_estimate_L1.m: -------------------------------------------------------------------------------- 1 | function [A_est, accuracy] = Map_estimate_L1(T, L_funct_s_test, A) 2 | 3 | A_est = zeros(1,T); 4 | accuracy = 0; 5 | 6 | for t = 1:T 7 | if(L_funct_s_test(t,1)+L_funct_s_test(t,2)+L_funct_s_test(t,3)+L_funct_s_test(t,4) >= L_funct_s_test(t,5)+L_funct_s_test(t,6)+L_funct_s_test(t,7)+L_funct_s_test(t,8)) 8 | A_est(t) = -1; 9 | else 10 | A_est(t) = 1; 11 | end 12 | if A_est(t) == A(t) 13 | accuracy = accuracy + 1; 14 | end 15 | end 16 | 17 | accuracy = accuracy / T; -------------------------------------------------------------------------------- /HMM non-linear channel/backward_scaling1_L1.m: -------------------------------------------------------------------------------- 1 | function beta_s = backward_scaling1_L1(O, h_est, Nvar_est, tr, T) 2 | 3 | beta_s = zeros(T+1,4); 4 | beta_numerator = zeros(T+1,4); 5 | [~, c] = forward_scaling1_L1(O, h_est, Nvar_est, tr, T); 6 | 7 | %initialization 8 | for k = 1:4 9 | beta_s(T+1,k) = 1; 10 | end 11 | 12 | overflow = log(1.79769313486231570E+308); 13 | underflow = log(4.94065645841246544E-324); 14 | 15 | %iteration 16 | for t = T:-1:1 17 | for i = 1:4 18 | for j = 1:4 19 | if mod(j-1,2) ~= floor((i-1)/2) 20 | beta_numerator(t,i) = beta_numerator(t,i) + 0; 21 | else 22 | index = (i-1) + floor((j-1)/2)*4 + 1; 23 | beta_numerator_logterm = log(beta_s(t+1,j))+log(tr(j,i))-log(sqrt(2*pi*Nvar_est))-(O(t)-h_est(index))^2/(2*Nvar_est); 24 | if beta_numerator_logterm < underflow 25 | beta_numerator_logterm = underflow; 26 | elseif beta_numerator_logterm > overflow 27 | beta_numerator_logterm = overflow; 28 | end 29 | beta_numerator_logterm = exp(beta_numerator_logterm); 30 | beta_numerator(t,i) = beta_numerator(t,i) + beta_numerator_logterm; 31 | end 32 | end 33 | beta_s(t,i) = beta_numerator(t,i); 34 | end 35 | beta_s(t,:) = beta_s(t,:)/c(t); 36 | end 37 | 38 | 39 | -------------------------------------------------------------------------------- /HMM non-linear channel/decoding_bin2text.m: -------------------------------------------------------------------------------- 1 | function M = decoding_bin2text(A_est) 2 | A_est = dec2bin(A_est); 3 | 4 | % Now decode: 5 | M = char(bin2dec(reshape(A_est,7,[]).').'); 6 | 7 | disp(M); -------------------------------------------------------------------------------- /HMM non-linear channel/encoding_text2bin.m: -------------------------------------------------------------------------------- 1 | function A_bin = encoding_text2bin(text) 2 | 3 | % Now encode: 4 | A_bin = reshape(dec2bin(double(text),7).',[],1); 5 | -------------------------------------------------------------------------------- /HMM non-linear channel/forward_L1.m: -------------------------------------------------------------------------------- 1 | function alpha = forward_L1(O, h_est, Nvar_est, tr, T) 2 | 3 | alpha = zeros(T+1,4); 4 | 5 | %initialization 6 | for i = 1:4 7 | alpha(1,i) = 1/4; 8 | end 9 | 10 | overflow = log(1.79769313486231570E+308); 11 | underflow = log(4.94065645841246544E-324); 12 | 13 | %iteration 14 | for t = 2:T+1 15 | for j = 1:4 16 | for i = 1:4 17 | if mod(j-1,2) ~= floor((i-1)/2) 18 | alpha(t,j) = alpha(t,j) + 0; 19 | else 20 | index = (i-1) + floor((j-1)/2)*4 + 1; 21 | alpha_logterm = log(alpha(t-1,i))+log(tr(j,i))-log(sqrt(2*pi*Nvar_est))-(O(t-1)-h_est(index))^2/(2*Nvar_est); 22 | if alpha_logterm < underflow 23 | alpha_logterm = underflow; 24 | elseif alpha_logterm > overflow 25 | alpha_logterm = overflow; 26 | end 27 | alpha_logterm = exp(alpha_logterm); 28 | alpha(t,j) = alpha(t,j) + alpha_logterm; 29 | end 30 | end 31 | end 32 | end -------------------------------------------------------------------------------- /HMM non-linear channel/forward_scaling1_L1.m: -------------------------------------------------------------------------------- 1 | function [alpha_s, c] = forward_scaling1_L1(O, h_est, Nvar_est, tr, T) 2 | 3 | alpha_s = zeros(T+1,4); 4 | c = zeros(T+1,1); 5 | alpha_numerator = zeros(T+1,4); 6 | 7 | %initialization 8 | for i = 1:4 9 | alpha_s(1,i) = 1/4; 10 | end 11 | 12 | 13 | overflow = log(1.79769313486231570E+308); 14 | underflow = log(4.94065645841246544E-324); 15 | 16 | 17 | %iteration 18 | for t = 2:T+1 19 | for j = 1:4 20 | for i = 1:4 21 | if mod(j-1,2) ~= floor((i-1)/2) 22 | alpha_numerator(t,j) = alpha_numerator(t,j) + 0; 23 | else 24 | index = (i-1) + floor((j-1)/2)*4 + 1; 25 | alpha_logterm = log(alpha_s(t-1,i))+log(tr(j,i))-log(sqrt(2*pi*Nvar_est))-(O(t-1)-h_est(index))^2/(2*Nvar_est); 26 | if alpha_logterm < underflow 27 | alpha_logterm = underflow; 28 | elseif alpha_logterm > overflow 29 | alpha_logterm = overflow; 30 | end 31 | alpha_logterm = exp(alpha_logterm); 32 | alpha_numerator(t,j) = alpha_numerator(t,j) + alpha_logterm; 33 | end 34 | end 35 | alpha_s(t,j) = alpha_numerator(t,j); 36 | c(t) = c(t) + alpha_numerator(t,j) ; 37 | end 38 | alpha_s(t,:) = alpha_s(t,:)/c(t); 39 | end 40 | 41 | 42 | -------------------------------------------------------------------------------- /HMM non-linear channel/hmmgen_L1.m: -------------------------------------------------------------------------------- 1 | function [A, S, X, O] = hmmgen_L1(T, h, Nvar) 2 | 3 | %O is the observation sequence. T is the 4 | %length of the HMM. L is the length of the channel memory(L=1 in this case). H is the column vector 5 | %which has linear channel coefficients as its elements. Nvar is the noise variance 6 | %for Gaussian distribution. 7 | 8 | A = 2 * randi([0 1],1,T) - 1; %%%%S(1) is initilized 9 | S = zeros(T+1, 2); %%%%%specify S(2) to S(T+1) 10 | O = zeros(T, 1); 11 | for j = 1:2 12 | S(1,j) = 2 * randi([0 1],1,1) - 1; 13 | end 14 | 15 | for i = 2:T+1 16 | S(i,1) = A(i-1); 17 | S(i,2) = S(i-1,1); 18 | end 19 | 20 | X = zeros(T, 3); 21 | for i = 1:T %%%%%specify transition branch 22 | X(i,1) = A(i); 23 | X(i,2:3) = S(i,:); 24 | end 25 | 26 | 27 | for i = 1:T %output received by the receiver 28 | index = (X(i,1)+1)/2*4 + (X(i,2)+1)/2*2 + (X(i,3)+1)/2 + 1; 29 | O(i) = normrnd(h(index),Nvar); 30 | end 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /HMM non-linear channel/hmmparameter_scaling1_reestimate_L1.m: -------------------------------------------------------------------------------- 1 | function [L_Y_vector, h_vector, Nvar_vector, h_est, h_est_A, h_est_B, Nvar_est_A, Nvar_est_B, Nvar_est, L_funct_s_test] = hmmparameter_scaling1_reestimate_L1(O, T, h0, Nvar0, tr, n) 2 | %H_est_A is akin to the symbol autocorrelation matrix and H_est_B is akin 3 | %to the cross-correlation of observations and symbols. 4 | 5 | h_vector = zeros(8,n+1); 6 | Nvar_vector = zeros(1,n+1); 7 | h_vector(:,1) = h0; 8 | Nvar_vector(1) = Nvar0; 9 | 10 | L_Y_vector = zeros(1,n+1); 11 | [~, L_Y_vector(1)] = Lfunction_scaling1_L1(O, h0, Nvar0, tr, T); 12 | 13 | for m = 1:n 14 | [L_funct_s, ~] = Lfunction_scaling1_L1(O, h0, Nvar0, tr, T); 15 | h_est_A = zeros(8,1); 16 | h_est_B = zeros(8,1); 17 | h_est = zeros(8,1); 18 | Nvar_est_A = 0; 19 | Nvar_est_B = 0; 20 | for k = 1:8 21 | for t = 1:T 22 | h_est_A(k) = h_est_A(k) + L_funct_s(t,k)*O(t); 23 | h_est_B(k) = h_est_B(k) + L_funct_s(t,k); 24 | end 25 | h_est(k) = h_est_A(k) / h_est_B(k); 26 | end 27 | 28 | 29 | for t = 1:T 30 | for k = 1:8 31 | Nvar_est_A = Nvar_est_A + L_funct_s(t,k)*(O(t)-h_est(k))^2; 32 | Nvar_est_B = Nvar_est_B + L_funct_s(t,k); 33 | end 34 | end 35 | Nvar_est = Nvar_est_A / Nvar_est_B; 36 | % Nvar_est = Nvar0; 37 | h_vector(:,m+1) = h_est; 38 | Nvar_vector(m+1) = Nvar_est; 39 | 40 | [L_funct_s_test, L_Y_test] = Lfunction_scaling1_L1(O, h_est, Nvar_est, tr, T); 41 | L_Y_vector(m+1) = L_Y_test; 42 | h0 = h_est; 43 | Nvar0 = Nvar_est; 44 | end 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /HMM non-linear channel/run_program1_original.m: -------------------------------------------------------------------------------- 1 | function [h_est, A_est, accuracy] = run_program1_original(T, h, Nvar, h0, Nvar0, n) 2 | %This function is used to complie all the subrountines(functions) in order 3 | %to get the simulation results. Although some variables are unused in this 4 | %particular function, we still keep those variables since it is more 5 | %convinent for us when we need to check those variables inside the whole 6 | %system. 7 | 8 | tr = [1/2,0,1/2,0;1/2,0,1/2,0;0,1/2,0,1/2;0,1/2,0,1/2]; 9 | tr = tr.'; 10 | [A, S, X, O] = hmmgen_L1(T, h, Nvar); 11 | [L_Y_vector, h_vector, Nvar_vector, h_est, h_est_A, h_est_B, Nvar_est_A, Nvar_est_B, Nvar_est, L_funct_s_test] = hmmparameter_scaling1_reestimate_L1(O, T, h0, Nvar0, tr, n); 12 | [A_est, accuracy] = Map_estimate_L1(T, L_funct_s_test, A); 13 | Make_plot_L1(A, A_est, O, T, h, h_vector, L_Y_vector, n); -------------------------------------------------------------------------------- /HMM non-linear channel/run_program2_SNR_accuracy.m: -------------------------------------------------------------------------------- 1 | function [accuracy, accuracy_mean, h_est, time] = run_program2_SNR_accuracy(T, h, SNR, h0, n) 2 | %This function is used to complie all the subrountines(functions) in order 3 | %to get the simulation results. Although some variables are unused in this 4 | %particular function, we still keep those variables since it is more 5 | %convinent for us when we need to check those variables inside the whole 6 | %system. 7 | 8 | Nvar = 1/10^(SNR/10); 9 | Nvar0 = 2.1; 10 | 11 | tr = [1/2,0,1/2,0;1/2,0,1/2,0;0,1/2,0,1/2;0,1/2,0,1/2]; 12 | tr = tr.'; 13 | 14 | %performance evaluation 15 | accuracy = zeros(1,100); 16 | accuracy_mean = 0; 17 | time = 0; 18 | 19 | for m = 1:1 20 | tic; 21 | [A, S, X, O] = hmmgen_L1(T, h, Nvar); 22 | [L_Y_vector, h_vector, Nvar_vector, h_est, h_est_A, h_est_B, Nvar_est_A, Nvar_est_B, Nvar_est, L_funct_s_test] = hmmparameter_scaling1_reestimate_L1(O, T, h0, Nvar0, tr, n); 23 | [A_est, accuracy(m)] = Map_estimate_L1(T, L_funct_s_test, A); 24 | time1 = toc; 25 | time = time + time1; 26 | accuracy_mean = accuracy_mean + accuracy(m); 27 | end 28 | accuracy_mean = accuracy_mean / 100; 29 | time = time / 100; 30 | 31 | Make_plot_L1(A, A_est, O, T, h, h_vector, L_Y_vector, n); -------------------------------------------------------------------------------- /HMM non-linear channel/run_program3_SNR_plot.m: -------------------------------------------------------------------------------- 1 | function run_program3_SNR_plot(T, h, h0, n) 2 | 3 | SNR = 0:10; 4 | Nvar = zeros(1,11); 5 | for i = 1:11 6 | Nvar(i) = 1/10^(SNR(i)/10); 7 | end 8 | Nvar0 = Nvar; 9 | 10 | tr = [1/2,0,1/2,0;1/2,0,1/2,0;0,1/2,0,1/2;0,1/2,0,1/2]; 11 | tr = tr.'; 12 | accuracy_mean = zeros(1,11); 13 | 14 | for j = 1:11 15 | for m = 1:100 16 | [A, ~, ~, O] = hmmgen_L1(T, h, Nvar0(j)); 17 | [~, ~, ~, ~, ~, ~, ~, ~, ~, L_funct_s_test] = hmmparameter_scaling1_reestimate_L1(O, T, h0, Nvar0(j), tr, n); 18 | [~, accuracy] = Map_estimate_L1(T, L_funct_s_test, A); 19 | accuracy_mean(j) = accuracy_mean(j) + accuracy; 20 | end 21 | end 22 | accuracy_mean = accuracy_mean / 100; 23 | 24 | Hundred_percent(SNR+1) = 1; 25 | plot(SNR,Hundred_percent(SNR+1),'--k'); 26 | hold on; 27 | plot(SNR,accuracy_mean(SNR+1),'r'); 28 | axis([0 10 0.65 1.05]); 29 | title('Accuracy-SNR'); 30 | xlabel('SNR(dB)'); 31 | ylabel('Accuracy'); 32 | ylabel('Accuracy'); -------------------------------------------------------------------------------- /HMM non-linear channel/run_program4_ASCII_COMM.m: -------------------------------------------------------------------------------- 1 | function accuracy = run_program4_ASCII_COMM(h, h0, SNR, n) 2 | %This function is used to complie all the subrountines(functions) in order 3 | %to get the simulation results. Although some variables are unused in this 4 | %particular function, we still keep those variables since it is more 5 | %convinent for us when we need to check those variables inside the whole 6 | %system. 7 | 8 | Nvar = 1/10^(SNR/10); 9 | Nvar0 = Nvar; 10 | 11 | tr = [1/2,0,1/2,0;1/2,0,1/2,0;0,1/2,0,1/2;0,1/2,0,1/2]; 12 | tr = tr.'; 13 | 14 | %input data and encoding 15 | str = INPUT_TEXT; 16 | A_bin = encoding_text2bin(str); 17 | T = length(A_bin); 18 | 19 | [A, S, X, O] = HMM_ENTRY(T, h, Nvar, A_bin); 20 | [L_Y_vector, h_vector, Nvar_vector, h_est, h_est_A, h_est_B, Nvar_est_A, Nvar_est_B, Nvar_est, L_funct_s_test] = hmmparameter_scaling1_reestimate_L1(O, T, h0, Nvar0, tr, n); 21 | [A_est, accuracy] = MESSAGE_RECEIVER(T, L_funct_s_test, A); 22 | 23 | %output data and decoding 24 | decoding_bin2text(A_est); 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Qing Chen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Blind-Channel-Equalization-based-on-HMM-and-EM 2 | Matlab simulation of an EM algorithm based on HMM to blind channel equalization.
3 | Details of algorithm are described in the document. 4 | -------------------------------------------------------------------------------- /hmm with channel memory=2/HMM_ENTRY.m: -------------------------------------------------------------------------------- 1 | function [A, S, X, O, h] = HMM_ENTRY(T, H, Nvar, A_bin) 2 | 3 | %O is the observation sequence. T is the 4 | %length of the HMM. L is the length of the channel memory(L=1 in this case). H is the column vector 5 | %which has linear channel coefficients as its elements. Nvar is the noise variance 6 | %for Gaussian distribution. 7 | 8 | A = 2*(bin2dec(A_bin).')-1; %%%%S(1) is initilized 9 | S = zeros(T+1, 2); %%%%%specify S(2) to S(T+1) 10 | O = zeros(T, 1); 11 | for j = 1:2 12 | S(1,j) = 2 * randi([0 1],1,1) - 1; 13 | end 14 | 15 | for i = 2:T+1 16 | S(i,1) = A(i-1); 17 | S(i,2) = S(i-1,1); 18 | end 19 | 20 | X = zeros(T, 3); 21 | for i = 1:T %%%%%specify transition branch 22 | X(i,1) = A(i); 23 | X(i,2:3) = S(i,:); 24 | end 25 | 26 | X_space = [-1,-1,-1;-1,-1,1;-1,1,-1;-1,1,1;1,-1,-1;1,-1,1;1,1,-1;1,1,1]; 27 | X_space = X_space.'; 28 | h = zeros(1,8); 29 | 30 | for k = 1:8 %%%%%output of the linear channel 31 | h(k) = H.'*X_space(:,k); 32 | end 33 | 34 | for i = 1:T %output received by the receiver 35 | hco = H.'*X(i,:).'; 36 | O(i) = normrnd(hco,Nvar); 37 | end -------------------------------------------------------------------------------- /hmm with channel memory=2/INPUT_TEXT.m: -------------------------------------------------------------------------------- 1 | function str = INPUT_TEXT 2 | prompt = 'Sending: '; 3 | str = input(prompt, 's'); 4 | -------------------------------------------------------------------------------- /hmm with channel memory=2/Lfunction_scaling1_L1.m: -------------------------------------------------------------------------------- 1 | function [L_funct_s, L_Y] = Lfunction_scaling1_L1(O, H_est, Nvar_est, tr, T) 2 | 3 | %choose tr(n) in tr matrix will be in column order. Since we number all 4 | %possible transtion branches in a left-msb based method. tr(n) will 5 | %exactly represent the nth transition brach probability. e.g we number xt = 6 | %[st+1,st] = [0,1] as 2. 7 | %from 1->0 we should take tr(1,0) = tr(2).(Assume that tr(i,j) represents the transition probability Si -> Sj in state space) 8 | 9 | 10 | 11 | %t = 1:T and k = 1:4 12 | %i = mod (k-1,2) + 1 13 | %j = floor((k-1)/2) + 1 14 | 15 | [alpha_s, ~] = forward_scaling1_L1(O, H_est, Nvar_est, tr, T); 16 | beta_s = backward_scaling1_L1(O, H_est, Nvar_est, tr, T); 17 | 18 | X_space = [-1,-1,-1;-1,-1,1;-1,1,-1;-1,1,1;1,-1,-1;1,-1,1;1,1,-1;1,1,1]; 19 | X_space = X_space.'; 20 | h = zeros(1,8); 21 | 22 | for k = 1:8 %%%%%output of the linear channel 23 | h(k) = H_est.'*X_space(:,k); 24 | end 25 | 26 | L_funct_s = zeros(T,8); 27 | overflow = log(1.79769313486231570E+308); 28 | underflow = log(4.94065645841246544E-324); 29 | 30 | for t = 1:T 31 | for k = 1:8 32 | i = mod (k-1,4) + 1; 33 | j = floor((k-1)/2) + 1; 34 | L_funct_s(t,k) = -log(sqrt(2*pi*Nvar_est))-(O(t)-h(k))^2/(2*Nvar_est)+log(tr(j,i))+log(alpha_s(t,i))+log(beta_s(t+1,j)); 35 | if L_funct_s(t,k) < underflow 36 | L_funct_s(t,k) = underflow; 37 | elseif L_funct_s(t,k) > overflow 38 | L_funct_s(t,k) = overflow; 39 | end 40 | L_funct_s(t,k) = exp(L_funct_s(t,k)); 41 | end 42 | end 43 | 44 | alpha = forward_L1(O, H_est, Nvar_est, tr, T); 45 | L_Y = 0; 46 | for m = 1:4 47 | L_Y = L_Y + alpha(T+1,m); 48 | end 49 | 50 | 51 | -------------------------------------------------------------------------------- /hmm with channel memory=2/MESSAGE_RECEIVER.m: -------------------------------------------------------------------------------- 1 | function [A_est, accuracy] = MESSAGE_RECEIVER(T, L_funct_s_test, A) 2 | 3 | A_est = zeros(1,T); 4 | accuracy = 0; 5 | 6 | for t = 1:T 7 | if(L_funct_s_test(t,1)+L_funct_s_test(t,2)+L_funct_s_test(t,3)+L_funct_s_test(t,4) >= L_funct_s_test(t,5)+L_funct_s_test(t,6)+L_funct_s_test(t,7)+L_funct_s_test(t,8)) 8 | A_est(t) = -1; 9 | else 10 | A_est(t) = 1; 11 | end 12 | if A_est(t) == A(t) 13 | accuracy = accuracy + 1; 14 | end 15 | end 16 | 17 | A_est = (A_est'+1)/2; 18 | 19 | accuracy = accuracy / T; -------------------------------------------------------------------------------- /hmm with channel memory=2/Make_plot_L1.m: -------------------------------------------------------------------------------- 1 | function Make_plot_L1(A, A_est, O, T, H, h, H_vector, L_Y_vector, n) 2 | n1 = 0:n; 3 | Hline = zeros(3,n+1); 4 | t= 1:T; 5 | hline = zeros(8,T); 6 | 7 | for n2 = 0:n; 8 | for k = 1:3 9 | Hline(k,n2+1) = H(k); 10 | end 11 | end 12 | for t1 = 1:T; 13 | for k = 1:8 14 | hline(k,t1) = h(k); 15 | end 16 | end 17 | 18 | close all; 19 | plot(n1,Hline(1,n1+1),'--k'); 20 | hold on; 21 | plot(n1,Hline(2,n1+1),'--k'); 22 | hold on; 23 | plot(n1,Hline(3,n1+1),'--k'); 24 | hold on; 25 | axis([0 n 0 1]); 26 | title('Channel Impulse Response Estimation') 27 | xlabel('n (number of iterations)'); 28 | ylabel('H'); 29 | pause(5); 30 | 31 | l1=line(NaN,NaN, 'Marker', 'o', 'linesty','-','erasemode','none'); 32 | l2=line(NaN,NaN, 'Marker', 'o', 'linesty','-','erasemode','none'); 33 | l3=line(NaN,NaN, 'Marker', 'o', 'linesty','-','erasemode','none'); 34 | tt = 1:n+1; 35 | 36 | for test1 = 1:n+1; 37 | set(l1, 'xdata', n1(1:test1), 'ydata', H_vector(1,tt(1:test1))); 38 | 39 | set(l2, 'xdata', n1(1:test1), 'ydata', H_vector(2,tt(1:test1))); 40 | 41 | set(l3, 'xdata', n1(1:test1), 'ydata', H_vector(3,tt(1:test1))); 42 | 43 | 44 | % subplot(1,2,2); 45 | % plot(n1(test1),L_Y_vector(1,n1+1)); 46 | % title('Weighted likelihood function') 47 | % xlabel('n (number of iterations)'); 48 | % ylabel('Likelihood function'); 49 | pause(0.35); 50 | end 51 | 52 | % figure(2); 53 | % plot(t,hline(1,t),'--k'); 54 | % hold on; 55 | % plot(t,hline(2,t),'--k'); 56 | % hold on; 57 | % plot(t,hline(3,t),'--k'); 58 | % hold on; 59 | % plot(t,hline(4,t),'--k'); 60 | % hold on; 61 | % plot(t,hline(5,t),'--k'); 62 | % hold on; 63 | % plot(t,hline(6,t),'--k'); 64 | % hold on; 65 | % plot(t,hline(7,t),'--k'); 66 | % hold on; 67 | % plot(t,hline(8,t),'--k'); 68 | % hold on; 69 | % plot(t,O(t),'+',t,O(t)); 70 | % xlim([0 T]); 71 | % title('Observed sequence'); 72 | % xlabel('t'); 73 | % ylabel('O(t)'); 74 | % 75 | % t1 = [t;t+1]; 76 | % t2 = t1(:); 77 | % A1 = [A;A]; 78 | % A2 = A1(:); 79 | % A_est1 = [A_est;A_est]; 80 | % A_est2 = A_est1(:); 81 | % 82 | % figure(3); 83 | % subplot(2,1,1); 84 | % plot(t2,A2); 85 | % axis([1 T+1 -1.5 1.5]); 86 | % title('Orignial information symbols'); 87 | % xlabel('t'); 88 | % ylabel('A(t)'); 89 | % 90 | % subplot(2,1,2); 91 | % plot(t2,A_est2); 92 | % axis([1 T+1 -1.5 1.5]); 93 | % title('Estimated information symbols'); 94 | % xlabel('t'); 95 | % ylabel('A_est(t)'); 96 | 97 | 98 | -------------------------------------------------------------------------------- /hmm with channel memory=2/Map_estimate_L1.m: -------------------------------------------------------------------------------- 1 | function [A_est, accuracy] = Map_estimate_L1(T, L_funct_s_test, A) 2 | 3 | A_est = zeros(1,T); 4 | accuracy = 0; 5 | 6 | for t = 1:T 7 | if(L_funct_s_test(t,1)+L_funct_s_test(t,2)+L_funct_s_test(t,3)+L_funct_s_test(t,4) >= L_funct_s_test(t,5)+L_funct_s_test(t,6)+L_funct_s_test(t,7)+L_funct_s_test(t,8)) 8 | A_est(t) = -1; 9 | else 10 | A_est(t) = 1; 11 | end 12 | if A_est(t) == A(t) 13 | accuracy = accuracy + 1; 14 | end 15 | end 16 | 17 | accuracy = accuracy / T; -------------------------------------------------------------------------------- /hmm with channel memory=2/backward_scaling1_L1.m: -------------------------------------------------------------------------------- 1 | function beta_s = backward_scaling1_L1(O, H_est, Nvar_est, tr, T) 2 | 3 | beta_s = zeros(T+1,4); 4 | beta_numerator = zeros(T+1,4); 5 | [~, c] = forward_scaling1_L1(O, H_est, Nvar_est, tr, T); 6 | 7 | %initialization 8 | for k = 1:4 9 | beta_s(T+1,k) = 1; 10 | end 11 | 12 | X_space = [-1,-1,-1;-1,-1,1;-1,1,-1;-1,1,1;1,-1,-1;1,-1,1;1,1,-1;1,1,1]; 13 | X_space = X_space.'; 14 | h = zeros(1,8); 15 | 16 | for k = 1:8 %%%%%output of the linear channel 17 | h(k) = H_est.'*X_space(:,k); 18 | end 19 | 20 | overflow = log(1.79769313486231570E+308); 21 | underflow = log(4.94065645841246544E-324); 22 | 23 | %iteration 24 | for t = T:-1:1 25 | for i = 1:4 26 | for j = 1:4 27 | if mod(j-1,2) ~= floor((i-1)/2) 28 | beta_numerator(t,i) = beta_numerator(t,i) + 0; 29 | else 30 | index = (i-1) + floor((j-1)/2)*4 + 1; 31 | beta_numerator_logterm = log(beta_s(t+1,j))+log(tr(j,i))-log(sqrt(2*pi*Nvar_est))-(O(t)-h(index))^2/(2*Nvar_est); 32 | if beta_numerator_logterm < underflow 33 | beta_numerator_logterm = underflow; 34 | elseif beta_numerator_logterm > overflow 35 | beta_numerator_logterm = overflow; 36 | end 37 | beta_numerator_logterm = exp(beta_numerator_logterm); 38 | beta_numerator(t,i) = beta_numerator(t,i) + beta_numerator_logterm; 39 | end 40 | end 41 | beta_s(t,i) = beta_numerator(t,i); 42 | end 43 | beta_s(t,:) = beta_s(t,:)/c(t); 44 | end 45 | 46 | 47 | -------------------------------------------------------------------------------- /hmm with channel memory=2/decoding_bin2text.m: -------------------------------------------------------------------------------- 1 | function M = decoding_bin2text(A_est) 2 | A_est = dec2bin(A_est); 3 | 4 | % Now decode: 5 | M = char(bin2dec(reshape(A_est,7,[]).').'); 6 | 7 | M1 = ['receiving: ', M]; 8 | disp(M1); -------------------------------------------------------------------------------- /hmm with channel memory=2/encoding_text2bin.m: -------------------------------------------------------------------------------- 1 | function A_bin = encoding_text2bin(text) 2 | 3 | % Now encode: 4 | A_bin = reshape(dec2bin(double(text),7).',[],1); 5 | -------------------------------------------------------------------------------- /hmm with channel memory=2/forward_L1.m: -------------------------------------------------------------------------------- 1 | function alpha = forward_L1(O, H_est, Nvar_est, tr, T) 2 | 3 | alpha = zeros(T+1,4); 4 | 5 | %initialization 6 | for i = 1:4 7 | alpha(1,i) = 1/4; 8 | end 9 | 10 | X_space = [-1,-1,-1;-1,-1,1;-1,1,-1;-1,1,1;1,-1,-1;1,-1,1;1,1,-1;1,1,1]; 11 | X_space = X_space.'; 12 | h = zeros(1,8); 13 | 14 | for k = 1:8 %%%%%output of the linear channel 15 | h(k) = H_est.'*X_space(:,k); 16 | end 17 | 18 | overflow = log(1.79769313486231570E+308); 19 | underflow = log(4.94065645841246544E-324); 20 | 21 | %iteration 22 | for t = 2:T+1 23 | for j = 1:4 24 | for i = 1:4 25 | if mod(j-1,2) ~= floor((i-1)/2) 26 | alpha(t,j) = alpha(t,j) + 0; 27 | else 28 | index = (i-1) + floor((j-1)/2)*4 + 1; 29 | alpha_logterm = log(alpha(t-1,i))+log(tr(j,i))-log(sqrt(2*pi*Nvar_est))-(O(t-1)-h(index))^2/(2*Nvar_est); 30 | if alpha_logterm < underflow 31 | alpha_logterm = underflow; 32 | elseif alpha_logterm > overflow 33 | alpha_logterm = overflow; 34 | end 35 | alpha_logterm = exp(alpha_logterm); 36 | alpha(t,j) = alpha(t,j) + alpha_logterm; 37 | end 38 | end 39 | end 40 | end -------------------------------------------------------------------------------- /hmm with channel memory=2/forward_scaling1_L1.m: -------------------------------------------------------------------------------- 1 | function [alpha_s, c] = forward_scaling1_L1(O, H_est, Nvar_est, tr, T) 2 | 3 | alpha_s = zeros(T+1,4); 4 | c = zeros(T+1,1); 5 | alpha_numerator = zeros(T+1,4); 6 | 7 | %initialization 8 | for i = 1:4 9 | alpha_s(1,i) = 1/4; 10 | end 11 | 12 | X_space = [-1,-1,-1;-1,-1,1;-1,1,-1;-1,1,1;1,-1,-1;1,-1,1;1,1,-1;1,1,1]; 13 | X_space = X_space.'; 14 | h = zeros(1,8); 15 | 16 | for k = 1:8 %%%%%output of the linear channel 17 | h(k) = H_est.'*X_space(:,k); 18 | end 19 | 20 | overflow = log(1.79769313486231570E+308); 21 | underflow = log(4.94065645841246544E-324); 22 | 23 | 24 | %iteration 25 | for t = 2:T+1 26 | for j = 1:4 27 | for i = 1:4 28 | if mod(j-1,2) ~= floor((i-1)/2) 29 | alpha_numerator(t,j) = alpha_numerator(t,j) + 0; 30 | else 31 | index = (i-1) + floor((j-1)/2)*4 + 1; 32 | alpha_logterm = log(alpha_s(t-1,i))+log(tr(j,i))-log(sqrt(2*pi*Nvar_est))-(O(t-1)-h(index))^2/(2*Nvar_est); 33 | if alpha_logterm < underflow 34 | alpha_logterm = underflow; 35 | elseif alpha_logterm > overflow 36 | alpha_logterm = overflow; 37 | end 38 | alpha_logterm = exp(alpha_logterm); 39 | alpha_numerator(t,j) = alpha_numerator(t,j) + alpha_logterm; 40 | end 41 | end 42 | alpha_s(t,j) = alpha_numerator(t,j); 43 | c(t) = c(t) + alpha_numerator(t,j) ; 44 | end 45 | alpha_s(t,:) = alpha_s(t,:)/c(t); 46 | end 47 | 48 | 49 | -------------------------------------------------------------------------------- /hmm with channel memory=2/hmmgen_L1.m: -------------------------------------------------------------------------------- 1 | function [A, S, X, O, h] = hmmgen_L1(T, H, Nvar) 2 | 3 | %O is the observation sequence. T is the 4 | %length of the HMM. L is the length of the channel memory(L=1 in this case). H is the column vector 5 | %which has linear channel coefficients as its elements. Nvar is the noise variance 6 | %for Gaussian distribution. 7 | 8 | A = 2 * randi([0 1],1,T) - 1; %%%%S(1) is initilized 9 | S = zeros(T+1, 2); %%%%%specify S(2) to S(T+1) 10 | O = zeros(T, 1); 11 | for j = 1:2 12 | S(1,j) = 2 * randi([0 1],1,1) - 1; 13 | end 14 | 15 | for i = 2:T+1 16 | S(i,1) = A(i-1); 17 | S(i,2) = S(i-1,1); 18 | end 19 | 20 | X = zeros(T, 3); 21 | for i = 1:T %%%%%specify transition branch 22 | X(i,1) = A(i); 23 | X(i,2:3) = S(i,:); 24 | end 25 | 26 | X_space = [-1,-1,-1;-1,-1,1;-1,1,-1;-1,1,1;1,-1,-1;1,-1,1;1,1,-1;1,1,1]; 27 | X_space = X_space.'; 28 | h = zeros(1,8); 29 | 30 | for k = 1:8 %%%%%output of the linear channel 31 | h(k) = H.'*X_space(:,k); 32 | end 33 | 34 | for i = 1:T %output received by the receiver 35 | hco = H.'*X(i,:).'; 36 | O(i) = normrnd(hco,Nvar); 37 | end 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /hmm with channel memory=2/hmmparameter_scaling1_reestimate_L1.m: -------------------------------------------------------------------------------- 1 | function [L_Y_vector, H_vector, Nvar_vector, H_est, h_est, H_est_A, H_est_B, Nvar_est_A, Nvar_est_B, Nvar_est, L_funct_s_test] = hmmparameter_scaling1_reestimate_L1(O, T, H0, Nvar0, tr, n) 2 | %H_est_A is akin to the symbol autocorrelation matrix and H_est_B is akin 3 | %to the cross-correlation of observations and symbols. 4 | 5 | H_vector = zeros(3,n+1); 6 | Nvar_vector = zeros(1,n+1); 7 | H_vector(:,1) = H0; 8 | Nvar_vector(1) = Nvar0; 9 | 10 | L_Y_vector = zeros(1,n+1); 11 | [~, L_Y_vector(1)] = Lfunction_scaling1_L1(O, H0, Nvar0, tr, T); 12 | 13 | for m = 1:n 14 | [L_funct_s, ~] = Lfunction_scaling1_L1(O, H0, Nvar0, tr, T); 15 | X_space = [-1,-1,-1;-1,-1,1;-1,1,-1;-1,1,1;1,-1,-1;1,-1,1;1,1,-1;1,1,1]; 16 | X_space = X_space.'; 17 | H_est_A = zeros(3,3); 18 | H_est_B = zeros(3,1); 19 | Nvar_est_A = 0; 20 | Nvar_est_B = 0; 21 | for t = 1:T 22 | for k = 1:8 23 | H_est_A = H_est_A + L_funct_s(t,k)*X_space(:,k)*X_space(:,k).'; 24 | H_est_B = H_est_B + L_funct_s(t,k)*O(t)*X_space(:,k); 25 | end 26 | end 27 | H_est = H_est_A\H_est_B; 28 | 29 | h_est = zeros(1,8); 30 | for k = 1:8 %%%%%output of the linear channel 31 | h_est(k) = H_est.'*X_space(:,k); 32 | end 33 | 34 | for t = 1:T 35 | for k = 1:8 36 | Nvar_est_A = Nvar_est_A + L_funct_s(t,k)*(O(t)-h_est(k))^2; 37 | Nvar_est_B = Nvar_est_B + L_funct_s(t,k); 38 | end 39 | end 40 | Nvar_est = Nvar_est_A / Nvar_est_B; 41 | % Nvar_est = Nvar0; 42 | H_vector(:,m+1) = H_est; 43 | Nvar_vector(m+1) = Nvar_est; 44 | 45 | [L_funct_s_test, L_Y_test] = Lfunction_scaling1_L1(O, H_est, Nvar_est, tr, T); 46 | L_Y_vector(m+1) = L_Y_test; 47 | H0 = H_est; 48 | Nvar0 = Nvar_est; 49 | end 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /hmm with channel memory=2/run_program1_original.m: -------------------------------------------------------------------------------- 1 | function [A_est, accuracy] = run_program1_original(T, H, Nvar, H0, Nvar0, n) 2 | %This function is used to complie all the subrountines(functions) in order 3 | %to get the simulation results. Although some variables are unused in this 4 | %particular function, we still keep those variables since it is more 5 | %convinent for us when we need to check those variables inside the whole 6 | %system. 7 | 8 | tr = [1/2,0,1/2,0;1/2,0,1/2,0;0,1/2,0,1/2;0,1/2,0,1/2]; 9 | tr = tr.'; 10 | [A, S, X, O, h] = hmmgen_L1(T, H, Nvar); 11 | [L_Y_vector, H_vector, Nvar_vector, H_est, h_est, H_est_A, H_est_B, Nvar_est_A, Nvar_est_B, Nvar_est, L_funct_s_test] = hmmparameter_scaling1_reestimate_L1(O, T, H0, Nvar0, tr, n); 12 | [A_est, accuracy] = Map_estimate_L1(T, L_funct_s_test, A); 13 | Make_plot_L1(A, A_est, O, T, H, h, H_vector, L_Y_vector, n); -------------------------------------------------------------------------------- /hmm with channel memory=2/run_program2_SNR_accuracy.m: -------------------------------------------------------------------------------- 1 | function [Nvar_vector, accuracy, accuracy_mean, H_est, time] = run_program2_SNR_accuracy(T, H, SNR, H0, n) 2 | %This function is used to complie all the subrountines(functions) in order 3 | %to get the simulation results. Although some variables are unused in this 4 | %particular function, we still keep those variables since it is more 5 | %convinent for us when we need to check those variables inside the whole 6 | %system. 7 | 8 | Nvar = 1/10^(SNR/10); 9 | Nvar0 = 0.7; 10 | 11 | tr = [1/2,0,1/2,0;1/2,0,1/2,0;0,1/2,0,1/2;0,1/2,0,1/2]; 12 | tr = tr.'; 13 | 14 | %performance evaluation 15 | accuracy = zeros(1,100); 16 | accuracy_mean = 0; 17 | time = 0; 18 | 19 | for m = 1:1 20 | [A, S, X, O, h] = hmmgen_L1(T, H, Nvar); 21 | tic; 22 | [L_Y_vector, H_vector, Nvar_vector, H_est, h_est, H_est_A, H_est_B, Nvar_est_A, Nvar_est_B, Nvar_est, L_funct_s_test] = hmmparameter_scaling1_reestimate_L1(O, T, H0, Nvar0, tr, n); 23 | [A_est, accuracy(m)] = Map_estimate_L1(T, L_funct_s_test, A); 24 | time1 = toc; 25 | time = time + time1; 26 | accuracy_mean = accuracy_mean + accuracy(m); 27 | end 28 | accuracy_mean = accuracy_mean / 100; 29 | time = time / 100; 30 | 31 | Make_plot_L1(A, A_est, O, T, H, h, H_vector, L_Y_vector, n) -------------------------------------------------------------------------------- /hmm with channel memory=2/run_program3_SNR_plot.m: -------------------------------------------------------------------------------- 1 | function run_program3_SNR_plot(T, H, H0, n) 2 | 3 | SNR = 0:10; 4 | Nvar = zeros(1,11); 5 | for i = 1:11 6 | Nvar(i) = 1/10^(SNR(i)/10); 7 | end 8 | Nvar0 = Nvar; 9 | 10 | tr = [1/2,0,1/2,0;1/2,0,1/2,0;0,1/2,0,1/2;0,1/2,0,1/2]; 11 | tr = tr.'; 12 | accuracy_mean = zeros(1,11); 13 | 14 | for j = 1:11 15 | for m = 1:100 16 | [A, ~, ~, O, ~] = hmmgen_L1(T, H, Nvar(j)); 17 | [~, ~, ~, ~, ~, ~, ~, ~, ~, ~, L_funct_s_test] = hmmparameter_scaling1_reestimate_L1(O, T, H0, Nvar0(j), tr, n); 18 | [~, accuracy] = Map_estimate_L1(T, L_funct_s_test, A); 19 | accuracy_mean(j) = accuracy_mean(j) + accuracy; 20 | end 21 | end 22 | accuracy_mean = accuracy_mean / 100; 23 | 24 | Hundred_percent(SNR+1) = 1; 25 | plot(SNR,Hundred_percent(SNR+1),'--k'); 26 | hold on; 27 | plot(SNR,accuracy_mean(SNR+1),'r'); 28 | axis([0 10 0.65 1.05]); 29 | title('Accuracy-SNR'); 30 | xlabel('SNR(dB)'); 31 | ylabel('Accuracy'); 32 | ylabel('Accuracy'); -------------------------------------------------------------------------------- /hmm with channel memory=2/run_program4_ASCII_COMM.m: -------------------------------------------------------------------------------- 1 | function BER = run_program4_ASCII_COMM(H, H0, SNR, n) 2 | %This function is used to complie all the subrountines(functions) in order 3 | %to get the simulation results. Although some variables are unused in this 4 | %particular function, we still keep those variables since it is more 5 | %convinent for us when we need to check those variables inside the whole 6 | %system. 7 | 8 | Nvar = 1/10^(SNR/10); 9 | Nvar0 = Nvar; 10 | 11 | tr = [1/2,0,1/2,0;1/2,0,1/2,0;0,1/2,0,1/2;0,1/2,0,1/2]; 12 | tr = tr.'; 13 | 14 | %input data and encoding 15 | str = INPUT_TEXT; 16 | A_bin = encoding_text2bin(str); 17 | T = length(A_bin); 18 | 19 | [A, S, X, O, h] = HMM_ENTRY(T, H, Nvar, A_bin); 20 | [L_Y_vector, H_vector, Nvar_vector, H_est, h_est, H_est_A, H_est_B, Nvar_est_A, Nvar_est_B, Nvar_est, L_funct_s_test] = hmmparameter_scaling1_reestimate_L1(O, T, H0, Nvar0, tr, n); 21 | [A_est, accuracy] = MESSAGE_RECEIVER(T, L_funct_s_test, A); 22 | BER = 1-accuracy; 23 | 24 | %output data and decoding 25 | decoding_bin2text(A_est); 26 | --------------------------------------------------------------------------------