clear all, clf, close all
%[left,right] = receive('line',44100,200000);
%save dsp_tr_test_1 left right
t_s = [];
m_u = [];
%%% Modulation format of received data %%%
%QAM = 64;
%QAM = 32;
QAM = 16;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load train_128
%Alpha1 = [-1-sqrt(-1), +1+sqrt(-1)];
%Alpha2 = [-1+sqrt(-1), +1-sqrt(-1)];
%for k = 1:length(ms1)
% bit1 = ms1(k);
% bit2 = ms2(k);
% bit1 = ceil(bit1/2);
% bit2 = ceil(bit2/2);
% sym1 = Alpha1(bit1+1);
% sym2 = Alpha2(bit2+1);
% ms1(k) = sym1;
% ms2(k) = sym2;
%end
ms1 = [upfirdn(ms1,1,4,1) 0 0 0];
ms2 = [upfirdn(ms2,1,4,1) 0 0 0];
%%% Number of receive antennas %%%
rec_ant = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Length of pilots used for channel estimation %%%
pilot = 8;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%h11_old = 0;
%apa = 0;
%mu_1_all = [];
%mu_2_all = [];
%cw_1_a = [];
%cw_2_a = [];
%str_err_all = [];
%beta = 0.4536; % Optimal ??
beta = 2.0;
sym_index = 1;
h11_hat = 0;
h12_hat = 0;
h21_hat = 0;
h22_hat = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% _____Loading data______ %
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%load rec6
if QAM == 64
64
%load image_trans_64
%load rec_mimo_image_64
load c:\dsp_tr_test_1
end
if QAM == 32
32
%load image_trans_32
%load rec_mimo_image_32
load c:\dsp_tr_test_1
end
if QAM == 16
16
%load image_trans_16
load c:\dsp_tr_test_1
%load dsp_tr_dump
end
%load rls_tr
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Loading m-seq. for training %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if QAM == 64
load train_ort_64
end
if QAM == 32
load train_ort_32
end
if QAM == 16
load train_ort_16
end
%load train_128;
%pilot_1_128 = ms1;
%pilot_2_128 = ms2;
%load train_8;
%pilot_1_8 = ms1;
%pilot_2_8 = ms2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ______QAM alphabet_____ %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if QAM == 64
A_S = [-7+7*j -5+7*j -5+5*j -7+5*j -3+7*j -1+7*j -1+5*j -3+5*j ...
-3+3*j -1+3*j -1+j -3+j -7+3*j -5+3*j -5+j -7+j ...
-7-j -5-j -5-3*j -7-3*j -3-j -1-j -1-3*j -3-3*j ...
-3-5*j -1-5*j -1-7*j -3-7*j -7-5*j -5-5*j -5-7*j -7-7*j ...
1-j 3-j 3-3*j 1-3*j 5-j 7-j 7-3*j 5-3*j ...
5-5*j 7-5*j 7-7*j 5-7*j 1-5*j 3-5*j 3-7*j 1-7*j ...
1+7*j 3+7*j 3+5*j 1+5*j 5+7*j 7+7*j 7+5*j 5+5*j ...
5+3*j 7+3*j 7+j 5+j 1+3*j 3+3*j 3+j 1+j];
end
if QAM == 32
A_S = [-1+sqrt(-1) -1+3*sqrt(-1) -3+sqrt(-1) -3+3*sqrt(-1) 1+sqrt(-1)...
1+3*sqrt(-1) 3+sqrt(-1) 3+3*sqrt(-1) -1-sqrt(-1) -1-3*sqrt(-1)...
-3-sqrt(-1) -3-3*sqrt(-1) 1-sqrt(-1) 1-3*sqrt(-1) 3-sqrt(-1)...
3-3*sqrt(-1) -5+3*sqrt(-1) -1+5*sqrt(-1) -5+sqrt(-1) -3+5*sqrt(-1)...
5+3*sqrt(-1) 1+5*sqrt(-1) 5+sqrt(-1) 3+5*sqrt(-1) -5-3*sqrt(-1)...
-1-5*sqrt(-1) -5-sqrt(-1) -3-5*sqrt(-1) 5-3*sqrt(-1) 1-5*sqrt(-1)...
5-sqrt(-1) 3-5*sqrt(-1)];
end
if QAM == 16
A_S = [-1-sqrt(-1) -3-sqrt(-1) 1-sqrt(-1) 3-sqrt(-1)...
-1-3*sqrt(-1) -3-3*sqrt(-1) 1-3*sqrt(-1) 3-3*sqrt(-1)...
-1+sqrt(-1) -3+sqrt(-1) 1+sqrt(-1) 3+sqrt(-1)...
-1+3*sqrt(-1) -3+3*sqrt(-1) 1+3*sqrt(-1) 3+3*sqrt(-1)];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% _____ Set up general parameters_____ %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Upsampling factor
I = 4;
% Sampling frequency
fs = 44100;
% Roll-off factor
alpha = 0.4
% Pulse shape
p = root_raised_cosine(I, alpha, 5.9);
%p_2 = root_raised_cosine(I/2, alpha, 6);
%p = [0 p 0];
% Length of pulse shaping filter
M = length(p);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Matched filter %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mfp = fliplr(p);
%mfp = p;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Received signals %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%s1 = [zeros(1,1000) 32000/7*s1];
%s1 = [zeros(1,1000) 1*(1*trans_1+1*trans_2)];
s1 = right';
%s1 = right;
clf
plot(s1)
%pause
%s2 = [zeros(1,1000) 1*(1*trans_1+1*trans_2)];
if rec_ant == 1
s2 = zeros(1,length(s1));
else
s2 = right';
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Thresholds %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
begin_1 = min(find(abs(s1)>2000));
if rec_ant == 1
begin_2 = begin_1;
else
begin_2 = min(find(abs(s2)>2000));
end
sin_length = fs*1.2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ______Collecting the test sinusoid_____ %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
s1_test = s1(begin_1:begin_1+sin_length-1);
s2_test = s2(begin_1:begin_1+sin_length-1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Spectrum of transmited and received sinusiod %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
no_points = 2^12;
sinv_known = 2*sin(2*pi*10000/fs*(1:length(s1_test)));
sinv = s1_test;
sinf = fftshift(fft(sinv,no_points));
sinf = sinf(end/2+1:end);
sinf = sinf/max(abs(sinf));
sinf_known = fftshift(fft(sinv_known,no_points));
sinf_known = sinf_known(end/2+1:end);
sinf_known = sinf_known/max(abs(sinf_known));
[maxa, W] = max(sinf)
figure(11)
clf
plot(abs(sinf_known), 'b')
hold on
plot(abs(sinf), 'r')
pause
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% _____Removing the test sinusiod from the received data_____ %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%s1 = s1(begin_1+57856:end);
%s2 = s2(begin_2+57856:end);
s1 = s1(begin_1+57856+512:end);
s2 = s2(begin_2+57856+512:end);
figure(999)
plot(s1)
pause
%s1 = s1(begin_1+1.5*44100+1000:end);
%s2 = s2(begin_2+1.5*44100+1000:end);
%s1 = s1(68855:end);
%s2 = s2(68855:end);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ______Frequenct offset estimation_____ %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Zeros crossing algorithm
sin_sign_1 = sign(s1_test);
sin_sign_2 = sign(s2_test);
shifts_1 = zeros(1, length(s1_test)-1);
shifts_2 = zeros(1, length(s2_test)-1);
for i=1:length(s1_test)-1
shifts_1(i) = abs(sin_sign_1(i+1)-sin_sign_1(i))/2;
shifts_2(i) = abs(sin_sign_2(i+1)-sin_sign_2(i))/2;
end
time = sin_length/fs
fc_1 = sum(shifts_1)/2/time
fc_2 = sum(shifts_2)/2/time
fc_2 = fc_1;
%fc_1 = fc_1-3;
%fc_1 = 10000;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% _____ Spectum of received signal_____ %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%sig_f = fft(s1,1024);
%sig_f_known = fft(s1_sig,1024);
%sig_f = sig_f(end/2+1:end);
%sig_f_known = sig_f_known(end/2+1:end);
%[maxa , W] = max(abs(sig_f));
%sig_f = sig_f/maxa;
%[maxa , W] = max(abs(sig_f_known));
%sig_f_known = sig_f_known/maxa;
%ff = linspace(0,fs/2,512);
%figure(99)
%subplot(211)
%plot(ff, abs(sig_f))
%subplot(212)
%plot(ff, abs(sig_f_known),'r')
%pause
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% _____Split blocks_____ %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% _____Set up block structure______ %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nr_blocks = 1;
nr_subblocks_block = 20;
%nr_subblocks_block = 18;
nr_subblocks = nr_subblocks_block;
nr_data_subblock = 128-2*pilot;
subblock_length = 128;
nr_symbols = nr_subblocks * nr_data_sub