%维特比算法
clear all;
close all;
filename=['tempdata_viterbi_v'];
PAM=[-3 -1 1 3];
N=10000; %产
生序列的长度
%x=[-3 3 1 -1 3 -1 -1 1 3 -3]; %输入 x
x_path=ceil(4*rand(1,N));
for i=1:N
x(i)=PAM(x_path(i));
end
y=zeros(1,length(x)+1); %输出 y
path=zeros(length(y),4); %路径存储
L=zeros(length(y),4); %距离存储
d=zeros(1,4);
%SNR_dB=1:2:20;
%count=1; %计数器
for SNR_dB=1:20
%检验输入序列
for i=1:N
switch x(i)
case -3
case -1
case 1
case 3
otherwise
error('wrong input.');
end
end
%关于状态转移表(不加入噪声)y(i+1)=0.8*x(i+1)-0.6*x(i)
P=[PAM;PAM;PAM;PAM];
state=(0.8*P'-0.6*P); %生成状态转
移表--取原表的转置,便于计算
n=randn(1,length(x)); %噪声
sigma=sqrt(5)*10^(-SNR_dB/20);
%经过信道