OFDM_LS_directly.m
资源名称:信道估计算法.rar [点击查看]
上传用户:dgwtdq
上传日期:2013-04-19
资源大小:2k
文件大小:4k
源码类别:
matlab例程
开发平台:
Matlab
- %16QAM-OFDM system;
- clear all;
- clear all;
- N = 1024; %the total number of all subcarriers
- Np = 128; %the number of pilot carriers
- B = 2e6; %bandwidth 2MHz
- T = 1/B;
- Ng = 256; %the length of Guard Interval
- Xp = 3 + 1.0*j ; %pilot value
- t= 0; % erro code number
- for u = 1:20 % run 20 times
- %-------------------------------------Data generator--------------------------------------------------
- xr1 = rand(1,N-Np);
- Xre = (-3) * (xr1 < 0.25) + (-1) * (0.25 <= xr1 & xr1 < 0.5)...
- + (0.5 <= xr1 & xr1 < 0.75) + 3 * (0.75 <= xr1 & xr1 < 1);
- xr2 = rand(1,N-Np);
- Xim = (-3) * (xr2< 0.25) + (-1) * (0.25 <= xr2 & xr2 < 0.5)...
- + (0.5 <= xr2 & xr2 < 0.75) + 3 * (0.75 <= xr2 & xr2 < 1);
- X = complex(Xre,Xim); %16QAM
- % Xre = (-1) * (xr1 < 0.5) + 1 * (0.5 <= xr1 & xr1 < 1);
- % xr2 = rand(1,N-Np);
- % Xim = (-1) * (xr2< 0.5) + 1 * (0.5 <= xr2 & xr2 < 1);
- % X = complex(Xre,Xim); %QPSK
- %---------------------------------- insert pilot in carriers -------------------------------------
- % pilots locate at 8*i + 3;
- Xc = zeros(1,N); %the carrier value
- m = 0;
- for i = 1 : N
- if(mod(i,8) == 3)
- Xc(i) = Xp;
- m = m + 1;
- else
- Xc(i) = X(i - m);
- end
- end
- %----------------------------------OFDM modulation-------------------------------------------------------
- Ym = ifft(Xc,N);
- %----------------------------------Insert GI CP---------------------------------------------------------
- Y = [Ym(769:N),Ym];
- %----------------------------------pass channel-----------------------------------------------------------
- Yc = ray_channel(Y,T);
- %---------------------------------add noice -------------------------------------------------------------
- SNR = 40;
- % for S=1:21
- %SNR= 10log10(Es/N0)
- % N0 = var(Yc)/(10^(SNR/10));
- % sgma = sqrt(N0/2);
- % Yawgn=Yc+sgma*randn(1,length(Yc))+sgma*randn(1,length(Yc))*j;
- Yawgn = awgn(Yc,SNR,'measured');
- %-------------------------------------------------------------------------------------------------------
- % ----------------------------------------------OFDM RECEIVER-------------------------------------------
- %----------------------------------------------OFDM demodulation----------------------------------------
- Yr = fft(Yawgn,N);
- %-----------------------------------------------Pilot signal Extraction---------------------------------
- c = 1;
- for i = 3:8:N
- Yp(c) = Yr(i);
- c = c + 1;
- end
- %----------------------------------- Pilot signal Estimation with LS Algorithm -------------------------
- Hp = Yp ./ Xp;
- % figure(1)
- % plot(abs(Hp))
- %---------------------------------Interpolation Appoach-----------------------------------------------------
- pilot_loca = 3:8:N;
- Hk = interp1(pilot_loca,Hp,1:N);
- H = fft(Yc,N) ./ fft(Ym,N);
- figure(3)
- plot(abs(Hk))
- hold on
- plot(abs(H),'r')
- %-------------------------------------data correction ------------------------------------------------------
- Xcc = Yr ;
- Xcc_line = Yr ./ Hk;
- figure(4)
- plot(Xcc_line,'+')
- hold on
- plot(X,'r*')
- %----------------------------------------16QAM demodulation--------------
- Xdre = zeros(1,N);
- Xdim = zeros(1,N);
- for i = 1 :N
- if(real(Xcc_line(i)) < -2)
- Xdre(i) = -3;
- elseif((real(Xcc_line(i)) >= -2)&(real(Xcc_line(i)) < 0))
- Xdre(i) = -1;
- elseif((real(Xcc_line(i)) >= 0)&(real(Xcc_line(i)) < 2))
- Xdre(i) = 1;
- else
- Xdre(i) = 3;
- end
- end
- for i = 1 :N
- if(imag(Xcc_line(i)) < -2)
- Xdim(i) = -3;
- elseif((imag(Xcc_line(i)) >= -2)&(imag(Xcc_line(i)) < 0))
- Xdim(i) = -1;
- elseif((imag(Xcc_line(i)) >= 0)&(imag(Xcc_line(i)) < 2))
- Xdim(i) = 1;
- else
- Xdim(i) = 3;
- end
- end
- Xd = complex(Xdre,Xdim);
- Xq = zeros(1,N-Np);
- m = 0;
- for i = 1 : N;
- if(mod(i,8) == 3)
- m = m + 1;
- else
- Xq(i - m) = Xd(i) ;
- end
- end
- for i= 1:Np
- if(Xq(i) ~= X(i))
- t = t + 1;
- end
- end
- end
- BER = t/(u * (N-Np));
- % Xq(1:10)'
- % X(1:10)'
- %Xcc_lowpass(1:10)
- BER
- SNR
- % t = t/u
- % SNR
- % figure(10)
- % plot(SNR,abs(BER))
English
