⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proj_cha_est.m

📁 channel estimation of ofdm using pilot based
💻 M
字号:
Ifft_bin_length=64;
No_of_carrier=31;
chan_tap=[.8 .2];
len_of_cyclic=4;
no_bit_symbol=4;
pilot_symbol=7;
snr=1;
anil=1;
P=5; %No of previous symbols
no_of_loops=100;
x=ones(P,7);
c_x_x=zeros(P,P);
H_pilot=ones(1,7);
c_h_x=zeros(1,P);

while snr<=40

    c_x_x=zeros(P,P);
    H_pilot=ones(1,7);
    c_h_x=zeros(1,P);

for i=1:P
    x(i,:)=rand(1,7);
end

while anil<=no_of_loops
      anil;
      
% Random bit generation
input_signal=randint(24,4)
%Display(input_signal);

%Conversion to symbols
symbol=bi2de(input_signal);
msg_1=transpose(symbol);
msg_pilot_1=[2 2 2 2 2 2 2];

%modulating the matrix
[inph quad]=qaskenco(symbol,16);
symbol_matrix=complex(inph,quad);

%insertion of pilot symbols
pilot_matrix=zeros(No_of_carrier,1);
i_pilot=0;
i_symbol=1;
while i_pilot<(No_of_carrier)
    if (mod(i_pilot,5)==0)
        pilot_matrix(i_pilot+1,1)=complex(1,-1);
    else
        pilot_matrix(i_pilot+1,1)=symbol_matrix(i_symbol,1);
        i_symbol=i_symbol+1;
    end
    i_pilot=i_pilot+1;
end
%display(pilot_matrix);


%Taking the IFFT of the Pilot matrix and storing it in Transmit_mat
transmit_mat=[0;pilot_matrix;0;flipud(conj(pilot_matrix))];
% Display(transmit_mat);
Ifft_out=ifft(transmit_mat);
%display(Ifft_out);

%Adding the Cyclic prefix
Ifft_out=[Ifft_out(length(Ifft_out)-len_of_cyclic+1:length(Ifft_out));Ifft_out];
%display(pilot_matrix);

%passing it through channel
y=conv(chan_tap,transpose(Ifft_out)); %for convolution we need both the terms in to be in serial
y=awgn(y,snr,'measured');
sig_noise=transpose(y);
%display(sig_noise);



%%%%%%%%%% Receiver %%%%%%%%%%%%

%removing the Cyclic prefix
sig_prefix=sig_noise(1:len_of_cyclic);
sig_data=sig_noise(len_of_cyclic+1:2*No_of_carrier+2+len_of_cyclic);
%display(sig_data);

%Taking FFT
sig_fft=fft(sig_data);
%display(sig_fft);

%removing the complex conjugates
sig_fft_cr=sig_fft(2:No_of_carrier+1);
%display(sig_fft_cr);

%Separating the Pilot points;
pilot_ppt=zeros(pilot_symbol,1);
for j=0:pilot_symbol-1
    pilot_ppt(j+1,1)=sig_fft_cr(5*j+1);
end
%display(pilot_ppt);


% For calculations in the Channel Estimation %
scaled_matrix=pilot_ppt/complex(1,-1);
% for storing the previous 4 values of scaled matrix
for i=(P-1):-1:1
    x(i+1,:)=x(i,:);
end
x(1,:)=transpose(scaled_matrix);
%display(x);

%Separating the info data
info_matrix=zeros(No_of_carrier-pilot_symbol,1);
k=1;
for j=0:30
    if (mod(j,5)==0)
        %no step
    else
        info_matrix(k,1)=sig_fft_cr(j+1);
        k=k+1;
    end
end
info_matrix_tr=transpose(info_matrix);
%display(info_matrix);


%%%%% Channel Estimation %%%%%

c_x_x=(x*x')+c_x_x;
c_h_x=(H_pilot*x')+c_h_x;
H_pilot=(c_h_x*inv(c_x_x))*x;
%display(H_pilot);

% To Calculate the Error between actual and the estimated Pilot channel %
% kumar=fft(chan_tap,31);
% for counter=0:6
%      kumar(1,1+4*counter)-H_pilot(1,i+1);             %Error
% end

% Interpolate between the points
location_points=[1,6,11,16,21,26,31];
H_int=[];
for p=1:length(H_pilot)-1
    if location_points(p+1)-location_points(p)>1
        H_int=[H_int H_pilot(p)];
        for q=location_points(p)+1:location_points(p+1)-1
            h=H_pilot(p)+(H_pilot(p+1)-H_pilot(p))/(location_points(p+1)-location_points(p))*(q-location_points(p));
            H_int=[H_int h];
        end
    else
        H_int=[H_int H_pilot(p)];
    end
end
H_int=[H_int H_pilot(end)];
%display(H_int);

%% Removing the weights corresponding to the Information channel
H_info_matrix=zeros(1,No_of_carrier-pilot_symbol);
k=1;
for j=0:30
    if(mod(j,5)==0)
        %no step
    else
        H_info_matrix(1,k)=H_int(j+1);
        k=k+1;
    end
end
%display(H_info_matrix);

%Equalising the effect of channel to obtain data %
est_info_matrix=info_matrix_tr./H_info_matrix;
est_pilot_matrix=transpose(pilot_ppt)./H_pilot;

%Demodulating the Received Symbols
inphase=real(est_info_matrix);
quadr=imag(est_info_matrix);
msg=qaskdeco(inphase,quadr,16);
msg_received=de2bi(msg)
%msg11= transpose(de2bi(msg));%
%display(msg); 

%Demodulating the Pilot symbols%
inphase=real(est_pilot_matrix);
quadr=imag(est_pilot_matrix);
msg_pilot=qaskdeco(inphase,quadr,16);



% Calculating the Bit Error %
[number,ratio]=biterr(msg,msg_1);
%display(number);
%display(ratio);

if anil==1
    BIT=[ratio];
    no=[anil];
 else
    BIT=[BIT ratio];
    no= [no anil];
 end

anil=anil+1;
end

   

if snr==1
    final=[mean(BIT)];
    X_axis=[snr];
  else
    final=[final mean(BIT)];
    X_axis=[X_axis snr];
 end
   snr=snr+1;
   anil=1;
end

p=polyfit(X_axis,final,1);
Y=p(1)*X_axis+p(2);

figure(6)
semilogy(X_axis,Y);
grid on
xlabel('SNR')
ylabel('BER')
title('Channel Estimation of OFDM System')
figure(7);
subplot(3,1,1);
stem(symbol);
title('input')

subplot(3,1,2);

stem(msg);
title('estimated')
error= symbol-msg';

subplot(3,1,3);
stem(error);
title('error')






    


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -