Schmidl算法代码
算法原理
训练序列结构 T=[A A],其中A表示复伪随机序列PN,进行N/2点ifft变换得到的符号序列
\[M(d)=\frac{\left | P(d) \right |}{R^{2}(d)}^{2}\]
\[P(d)=\sum_{m=0}^{L-1}r^{*}(d+m) r(d+m+L)\]
\[R(d)=\sum_{m=0}^{L-1}\left | r(d+m+L) \right |^{2}\]
\[L=N/2\]
所求得的d对应的是训练序列(不包含循环前缀)的开始位置。
★Schmidl:Schmidl算法利用一个由两端时域上完全相同的序列的前导来进行定时同步,但是这种方法得到的同步效果并不好,其同步度量函数曲线存在一个平顶,这使得定时同步估计存在偏差和不确定性。
参考文献
Schmidl T M,COX D C.Robust frequency and timing synchronization for OFDM[J].IEEE Trans.Commun.,1997,45(12):1613-1612.
%********************schmidl algorithm*******************
%Example:
% If
% X = rand(2,3,4);
% then
% d = size(X) returns d = [2 3 4]
% [m1,m2,m3,m4] = size(X) returns m1 = 2, m2 = 3, m3 = 4, m4 = 1
% [m,n] = size(X) returns m = 2, n = 12
% m2 = size(X,2) returns m2 = 3
close all;
clear all;
clc;
%参数定义
N=256; %FFT/IFFT 变换的点数或者子载波个数(Nu=N)
Ng=N/8; %循环前缀的长度 (保护间隔的长度)
Ns=Ng+N; %包括循环前缀的符号长度
%************利用查表法生成复随机序列**********************
QAMTable=[7+7i,-7+7i,-7-7i,7-7i];
buf=QAMTable(randi([0,3],N/2,1)+1); %加1是为了下标可能是0不合法
%*************在奇数子载波的位置插入零*********************zj:是偶数吧?
x=zeros(N,1);
index = 1;
for n=1:2:N
x(n)=buf(index);
index=index+1;
end;
%**************利用IFFT变换生成Schmidl训练符号***************
sch = ifft(x); %[A A]的形式
%*****************添加一个空符号以及一个后缀符号*************
src = QAMTable(randi([0,3],N,1)+1).';
sym = ifft(src);
sig =[zeros(N,1) sch sym];
%**********************添加循环前缀*************************
tx =[sig(N - Ng +1:N,:);sig];
%***********************经过信道***************************
recv = reshape(tx,1,size(tx,1)*size(tx,2)); %size的1表示行,2表示列,从%前向后数,超过了为1
%recv1 = awgn(recv,1,'measured');
%recv2 = awgn(recv,5,'measured');
%recv3 = awgn(recv,10,'measured');
%*****************计算符号定时*****************************
P=zeros(1,2*Ns);
R=zeros(1,2*Ns);
%P1=zeros(1,2*Ns);
%R1=zeros(1,2*Ns);
P2=zeros(1,2*Ns);
R2=zeros(1,2*Ns);
%P3=zeros(1,2*Ns);
%R3=zeros(1,2*Ns);
for d = Ns/2+1:1:2*Ns
for m=0:1:N/2-1
P(d-Ns/2) = P(d-Ns/2) + conj(recv(d+m))*recv(d+N/2+m);
R(d-Ns/2) = R(d-Ns/2) + power(abs(recv(d+N/2+m)),2);
%P1(d-Ns/2) = P1(d-Ns/2) + conj(recv1(d+m))*recv1(d+N/2+m);
%R1(d-Ns/2) = R1(d-Ns/2) + power(abs(recv1(d+N/2+m)),2);
%P2(d-Ns/2) = P2(d-Ns/2) + conj(recv2(d+m))*recv2(d+N/2+m);
%R2(d-Ns/2) = R2(d-Ns/2) + power(abs(recv2(d+N/2+m)),2);
% P3(d-Ns/2) = P3(d-Ns/2) + conj(recv3(d+m))*recv3(d+N/2+m);
% R3(d-Ns/2) = R3(d-Ns/2) + power(abs(recv3(d+N/2+m)),2);
end
end
M=power(abs(P),2)./power(abs(R),2);
%M1=power(abs(P1),2)./power(abs(R1),2);
%M2=power(abs(P2),2)./power(abs(R2),2);
%M3=power(abs(P3),2)./power(abs(R3),2);
%**********************绘图******************************
figure('Color','w');
d=1:1:400;
figure(1);
plot(d,M(d));
grid on;
axis([0,400,0,1.1]);
title('schmidl algorithm');
xlabel('Time (sample)');
ylabel('Timing Metric');
%legend('no noise','SNR=1dB','SNR=5dB','SNR=10dB');
hold on;