?? viterbi_decoder.m
字號:
function current_state = viterbi_decoder(cpm_param,cpm_low,previous_state)
possible_path.phase=zeros(previous_state.phasenumber,1);
possible_path.preIk=zeros(power(cpm_param.M_ary,cpm_param.duration-1),1);
possible_path.number=(previous_state.number)*(cpm_param.M_ary);
possible_path.weight=zeros(possible_path.number,1);
possible_path.code=zeros((cpm_param.symbols_per_frame),(possible_path.number));
% List every possible symbol value
Ik=(-cpm_param.M_ary+1):2:(cpm_param.M_ary-1);
Ik=Ik';
imax=previous_state.phasenumber;
jmax=power(cpm_param.M_ary,cpm_param.duration-1);
kmax=cpm_param.M_ary;
% Calculate every possible path
for i=1:imax
for j=1:jmax
for k=1:kmax
index=(i-1)*kmax*jmax+(j-1)*kmax+k;
state_index=(i-1)*jmax+j;
start_index=cpm_low.start_index;
end_index=cpm_low.end_index;
cpm_state.current_phase=previous_state.phase(i);
cpm_state.preIk=previous_state.Ik(j);
cpm_state.Ik=Ik(k);
[temp_phase_vector,possible_path.phase(index)]=cpm_phase_encoder(cpm_param,cpm_state);
possible_path.preIk(index)=Ik(k);
possible_path.code(:,index)=previous_state.code(:,state_index);
possible_path.code((previous_state.index),index)=Ik(k);
possible_path.weight(index)=previous_state.weight(state_index)...
+cpm_low.cosine(start_index:end_index)'*cos(temp_phase_vector)...
+cpm_low.sine(start_index:end_index)'*sin(temp_phase_vector);
end
end
end
% Only one path can survive for each of the same state
current_state.phase=previous_state.phase;
current_state.number=previous_state.number;
current_state.Ik=previous_state.Ik;
current_state.phasenumber=previous_state.phasenumber;
near_zero=10^(-5);
for i=1:imax
cosine_component=cos(current_state.phase(i));
sine_component=sin(current_state.phase(i));
for j=1:jmax
Ik=current_state.Ik(j);
index=0;
state_index=(i-1)*jmax+j;
for k=1:(possible_path.number)
if ((abs(cos(possible_path.phase(k))-cosine_component)<near_zero) ...
&& (abs(sin(possible_path.phase(k))-sine_component)<near_zero)...
&&(abs(possible_path.preIk(k)-Ik)<near_zero))
index=index+1;
same_state.weight(index)=possible_path.weight(k);
same_state.index(index)=k;
end
end
[maxweight,max_index]=max(same_state.weight);
current_state.weight(state_index)=possible_path.weight(same_state.index(max_index));
current_state.code(:,state_index)=possible_path.code(:,same_state.index(max_index));
end
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -