From 7ebd609b4f4139f4dac8627ac00678de89ef4575 Mon Sep 17 00:00:00 2001 From: Andreas Bogk Date: Thu, 15 Jan 2009 17:17:29 +0100 Subject: Viterbi generator by Piotr Krysik. --- viterbi_generator/tests/utils/make_increment.m | 70 ++++++++ viterbi_generator/tests/utils/make_next.m | 54 ++++++ viterbi_generator/tests/utils/make_previous.m | 54 ++++++ viterbi_generator/tests/utils/make_start.m | 63 +++++++ viterbi_generator/tests/utils/make_stops.m | 67 +++++++ viterbi_generator/tests/utils/viterbi_detector.m | 218 +++++++++++++++++++++++ viterbi_generator/tests/utils/viterbi_init.m | 38 ++++ 7 files changed, 564 insertions(+) create mode 100644 viterbi_generator/tests/utils/make_increment.m create mode 100644 viterbi_generator/tests/utils/make_next.m create mode 100644 viterbi_generator/tests/utils/make_previous.m create mode 100644 viterbi_generator/tests/utils/make_start.m create mode 100644 viterbi_generator/tests/utils/make_stops.m create mode 100644 viterbi_generator/tests/utils/viterbi_detector.m create mode 100644 viterbi_generator/tests/utils/viterbi_init.m (limited to 'viterbi_generator/tests/utils') diff --git a/viterbi_generator/tests/utils/make_increment.m b/viterbi_generator/tests/utils/make_increment.m new file mode 100644 index 0000000..91cc0ae --- /dev/null +++ b/viterbi_generator/tests/utils/make_increment.m @@ -0,0 +1,70 @@ +function [ INCREMENT ] = make_increment(SYMBOLS,NEXT,Rhh) +% +% MAKE_INCREMENT: +% This function returns a lookuptable containing the +% metric increments related to moving from state n to m. +% The data is arranged so that the increment accosiated +% with a move from state n to m is located in +% INCREMENT(n,m). To minimize computations only legal +% transitions are considdered. +% +% SYNTAX: [ INCREMENT ] = make_increment(SYMBOLS,NEXT,Rhh) +% +% INPUT: SYMBOLS: The table of symbols corresponding the the state- +% numbers. +% NEXT: A transition table containing the next legal +% states, as it is generated by the code make_next. +% Rhh: The autocorrelation as estimated by mf.m. +% +% OUTPUT: INCREMENT: +% The increment table as described above. +% +% SUB_FUNC: None +% +% WARNINGS: There is no syntax checking on input or output. +% +% TEST(S): By hand, against expected values. +% +% AUTOR: Jan H. Mikkelsen / Arne Norre Ekstrøm +% EMAIL: hmi@kom.auc.dk / aneks@kom.auc.dk +% +% $Id: make_increment.m,v 1.6 1997/09/22 11:39:34 aneks Exp $ + +% IN THIS PEACE OF CODE THE SYNTAX CHECKING IS MINIMAL +% THIS HAS BEEN CHOSEN TO AVOID THE OVERHEAD. RECALL THAT +% THIS CODE IS EXECUTED EACH TIME A BURST IS RECEIVED. + +% FIND THE NUMBER OF SYMBOLS THAT WE HAVE +% +[M,Lh]=size(SYMBOLS); + +% INITIALIZE THE INCREMENT MATRIX +% +INCREMENT=zeros(M); + +% RECALL THAT THE I SEQUENCE AS IT IS STORED IN STORED AS: +% [ I(n-1) I(n-2) I(n-3) ... I(n-Lh) ] +% +% ALSO RECALL THAT Rhh IS STORED AS: +% [ Rhh(1) Rhh(2) Rhh(3) ... Rhh(Lh) ] +% +% THE FORMULA TO USE IS: +% INCREMENT(n,m) +% = +% real(conj(I(n))*(I(n-Lh)*Rhh(Lh)+I(n-Lh+1)*Rhh(Lh-1)+...+I(n-1)*Rhh(1)) +% +% THEY CAN THUS BE MULTIPLIED DIRECTLY WITH EACH OTHER + +% LOOP OVER THE STATES, AS FOUND IN THE ROWS IN SYMBOLS. +% +for n=1:M, + % ONLY TWO LEGAL NEXT STATES EXIST, SO THE LOOP IS UNROLLED + % + m=NEXT(n,1); + + INCREMENT(n,m)=real((conj(SYMBOLS(m,1))*SYMBOLS(n,:))*Rhh(2:Lh+1).'); + m=NEXT(n,2); + + INCREMENT(n,m)=real((conj(SYMBOLS(m,1))*SYMBOLS(n,:))*Rhh(2:Lh+1).'); +end + diff --git a/viterbi_generator/tests/utils/make_next.m b/viterbi_generator/tests/utils/make_next.m new file mode 100644 index 0000000..f5af8dc --- /dev/null +++ b/viterbi_generator/tests/utils/make_next.m @@ -0,0 +1,54 @@ +function [ NEXT ] = make_next(SYMBOLS) +% +% MAKE_NEXT: +% This function returns a lookuptable containing a mapping +% between the present state and the legal next states. +% Each row correspond to a state, and the two legal states +% related to state n is located in NEXT(n,1) and in +% NEXT(n,2). States are represented by their related +% numbers. +% +% SYNTAX: [ NEXT ] = make_next(SYMBOLS) +% +% INPUT: SYMBOLS: The table of symbols corresponding the the state- +% numbers. +% +% OUTPUT: NEXT: The transition table describing the legal next +% states asdescribed above. +% +% SUB_FUNC: None +% +% WARNINGS: None +% +% TEST(S): The function has been verified to return the expected +% results. +% +% AUTOR: Jan H. Mikkelsen / Arne Norre Ekstrøm +% EMAIL: hmi@kom.auc.dk / aneks@kom.auc.dk +% +% $Id: make_next.m,v 1.3 1997/09/22 08:13:29 aneks Exp $ + +% FIRST WE NEED TO FIND THE NUMBER OF LOOPS WE SHOULD RUN. +% THIS EQUALS THE NUMBER OF SYMBOLS. ALSO MAXSUM IS NEEDED FOR +% LATER OPERATIONS. +% +[ states , maxsum ]=size(SYMBOLS); + +search_matrix=SYMBOLS(:,2:maxsum); +maxsum=maxsum-1; + +% LOOP OVER THE SYMBOLS. +% +for this_state=1:states, + search_vector=SYMBOLS(this_state,1:maxsum); + k=0; + for search=1:states, + if (sum(search_matrix(search,:)==search_vector)==maxsum) + k=k+1; + NEXT(this_state,k)=search; + if k > 2, + error('Error: identified too many next states'); + end + end + end +end \ No newline at end of file diff --git a/viterbi_generator/tests/utils/make_previous.m b/viterbi_generator/tests/utils/make_previous.m new file mode 100644 index 0000000..678fa43 --- /dev/null +++ b/viterbi_generator/tests/utils/make_previous.m @@ -0,0 +1,54 @@ +function [ PREVIOUS ] = make_previous(SYMBOLS) +% +% MAKE_PREVIOUS: +% This function returns a lookuptable containing a mapping +% between the present state and the legal previous states. +% Each row correspond to a state, and the two legal states +% related to state n is located in PREVIOUS(n,1) and in +% previous(n,2). States are represented by their related +% numbers. +% +% SYNTAX: [ PREVIOUS ] = make_previous(SYMBOLS) +% +% INPUT: SYMBOLS: The table of symbols corresponding the the state- +% numbers. +% +% OUTPUT: PREVIOUS: +% The transition table describing the legal previous +% states asdescribed above. +% +% SUB_FUNC: None +% +% WARNINGS: None +% +% TEST(S): Verified against expected result. +% +% AUTOR: Jan H. Mikkelsen / Arne Norre Ekstrøm +% EMAIL: hmi@kom.auc.dk / aneks@kom.auc.dk +% +% $Id: make_previous.m,v 1.3 1997/09/22 08:14:27 aneks Exp $ + +% FIRST WE NEED TO FIND THE NUMBER OF LOOPS WE SHOULD RUN. +% THIS EQUALS THE NUMBER OF SYMBOLS. ALSO MAXSUM IS NEEDED FOR +% LATER OPERATIONS. +% +[ states , maxsum ]=size(SYMBOLS); + +maxsum=maxsum-1; +search_matrix=SYMBOLS(:,1:maxsum); + +% LOOP OVER THE SYMBOLS. +% +for this_state=1:states, + search_vector=SYMBOLS(this_state,2:maxsum+1); + k=0; + for search=1:states, + if (sum(search_matrix(search,:)==search_vector)==maxsum) + k=k+1; + PREVIOUS(this_state,k)=search; + if k > 2, + error('Error: identified too many previous states'); + end + end + end +end \ No newline at end of file diff --git a/viterbi_generator/tests/utils/make_start.m b/viterbi_generator/tests/utils/make_start.m new file mode 100644 index 0000000..83275fd --- /dev/null +++ b/viterbi_generator/tests/utils/make_start.m @@ -0,0 +1,63 @@ +function [ START ] = make_start(Lh,SYMBOLS) +% +% MAKE_START: +% This code returns a statenumber corresponding to the start +% state as it is found from Lh. The method is to use the table +% of symbolic start states as it is listed in the report made +% by 95gr870T. For the table lookups are made in SYMBOLS. in +% order to map from the symbol representation to the state number +% representation. +% +% SYNTAX: [ START ] = make_start(Lh,SYMBOLS) +% +% INPUT: SYMBOLS: The table of symbols corresponding the the state- +% numbers. +% Lh: Length of the estimated impulseresponse. +% +% OUTPUT: START: The number representation of the legal start state. +% +% SUB_FUNC: None +% +% WARNINGS: The table of symbolic representations has not been verified +% but is used directly as it is listed in the report made +% by 95gr870T. +% +% TEST(S): The function has been verified to return a state number +% which matches the symbolic representation. +% +% AUTOR: Jan H. Mikkelsen / Arne Norre Ekstrøm +% EMAIL: hmi@kom.auc.dk / aneks@kom.auc.dk +% +% $Id: make_start.m,v 1.2 1997/09/22 11:40:17 aneks Exp $ + +% WE HAVEN'T FOUND IT YET. +% +START_NOT_FOUND = 1; + +% OBTAIN THE SYMBOLS FROM Lh. THIS IS THE TABLE LISTED IN THE REPORT MADE +% BY 95gr870T. (SATEREPRESENTATION IS SLIGHTLY CHANGED). +% +if Lh==1, + start_symbols = [ 1 ]; +elseif Lh==2, + start_symbols = [ 1 -j ]; +elseif Lh==3, + start_symbols = [ 1 -j -1 ]; +elseif Lh==4, + start_symbols = [ 1 -j -1 j ]; +elseif Lh==5, + start_symbols = [ 1 -j -1 j 1]; +else + fprintf('\n\nError: Illegal value of Lh, terminating...'); +end + +% NOW MAP FROM THE SYMBOLS TO A STATE NUMBER BY SEARCHING +% SYMBOLS. +% +START=0; +while START_NOT_FOUND, + START=START+1; + if sum(SYMBOLS(START,:)==start_symbols)==Lh, + START_NOT_FOUND=0; + end +end diff --git a/viterbi_generator/tests/utils/make_stops.m b/viterbi_generator/tests/utils/make_stops.m new file mode 100644 index 0000000..98734c9 --- /dev/null +++ b/viterbi_generator/tests/utils/make_stops.m @@ -0,0 +1,67 @@ +function [ STOPS ] = make_stops(Lh,SYMBOLS) +% +% MAKE_STOPS: +% This code returns a statenumber corresponding to the set of +% legal stop states as found from Lh. The method is to use the table +% of symbolic stop states as it is listed in the report made +% by 95gr870T. For the table lookups are made in SYMBOLS. in +% order to map from the symbol representation to the state number +% representation. +% +% SYNTAX: [ STOPS ] = make_stops(Lh,SYMBOLS) +% +% INPUT: SYMBOLS: The table of symbols corresponding the the state- +% numbers. +% Lh: Length of the estimated impulseresponse. +% +% OUTPUT: STOPS: The number representation of the set of legal stop +% states. +% +% SUB_FUNC: None +% +% WARNINGS: The table of symbolic representations has not been verified +% but is used directly as it is listed in the report made +% by 95gr870T. +% +% TEST(S): The function has been verified to return a state number +% which matches the symbolic representation. +% +% AUTOR: Jan H. Mikkelsen / Arne Norre Ekstrøm +% EMAIL: hmi@kom.auc.dk / aneks@kom.auc.dk +% +% $Id: make_stops.m,v 1.2 1997/09/22 11:44:21 aneks Exp $ + +% OBTAIN THE SYMBOLS FROM Lh. THIS IS THE TABLE LISTED IN THE REPORT MADE +% BY 95gr870T. (SATEREPRESENTATION IS SLIGHTLY CHANGED). +% +if Lh==1, + stop_symbols = [ -1 ]; + count=1; +elseif Lh==2, + stop_symbols = [ -1 j ]; + count=1; +elseif Lh==3, + stop_symbols = [ -1 j 1 ]; + count=1; +elseif Lh==4, + stop_symbols = [ [ -1 j 1 j ] ; [ -1 j 1 -j ] ]; + count=2; +elseif Lh==5, + stop_symbols = [ [ -1 j 1 j -1] ; [ -1 j 1 -j -1] ; [ -1 j 1 j 1] ; [ -1 j 1 -j 1] ]; + count=2; +else + fprintf('\n\nError: Illegal value of Lh, terminating...'); +end + +% NOW THAT WE HAVE THE SYMBOL REPRESENTATION THE REMAINING JOB IS +% TO MAP THE MSK SYMBOLS TO STATE NUMBERS +% +index = 0; +stops_found=0; +while stops_found < count, + index=index+1; + if sum(SYMBOLS(index,:)==stop_symbols(stops_found+1,:))==Lh, + stops_found=stops_found+1; + STOPS(stops_found)=index; + end +end diff --git a/viterbi_generator/tests/utils/viterbi_detector.m b/viterbi_generator/tests/utils/viterbi_detector.m new file mode 100644 index 0000000..31e8f93 --- /dev/null +++ b/viterbi_generator/tests/utils/viterbi_detector.m @@ -0,0 +1,218 @@ +function [ rx_burst METRIC] = viterbi_detector(SYMBOLS,NEXT,PREVIOUS,START,STOPS,Y,Rhh) +% +% VITERBI_DETECTOR: +% This matlab code does the actual detection of the +% received sequence. As indicated by the name the algorithm +% is the viterbi algorithm, which is a MLSE. At this time +% the approch is to use Ungerboecks modified algorithm, and +% to return hard output only. +% +% SYNTAX: [ rx_burst ] +% = +% viterbi_detector(SYMBOLS,NEXT,PREVIOUS,START,STOPS,Y,Rhh) +% +% INPUT: SYMBOLS: The table of symbols corresponding the the state- +% numbers. Format as made by make_symbols.m +% NEXT: A transition table containing the next legal +% states, as it is generated by the code make_next.m +% PREVIOUS: The transition table describing the legal previous +% states as generated by make_previous.m +% START: The start state of the algorithm. +% STOPS: The legal stop states. +% Y: Complex baseband representation of the matched +% filtered and down converted received signal, as it +% is returned by mf.m +% Rhh: The autocorrelation as estimated by mf.m +% +% OUTPUT: rx_burst: The most likely sequence of symbols. +% +% SUB_FUNC: make_increment +% +% WARNINGS: None. +% +% TEST(S): Tested with no noise, perfect syncronization, and channel +% estimation/filtering. (Refer to viterbi_ill.m) +% +% AUTOR: Jan H. Mikkelsen / Arne Norre Ekstrøm +% EMAIL: hmi@kom.auc.dk / aneks@kom.auc.dk +% +% $Id: viterbi_detector.m,v 1.7 1997/11/18 12:41:26 aneks Exp $ + +% KNOWLEDGE OF Lh AND M IS NEEDED FOR THE ALGORITHM TO OPERATE +% +[ M , Lh ] = size(SYMBOLS); + +% THE NUMBER OF STEPS IN THE VITERBI +% +STEPS=length(Y); +% INITIALIZE TABLES (THIS YIELDS A SLIGHT SPEEDUP). +% +METRIC = zeros(M,STEPS); +SURVIVOR = zeros(M,STEPS); + +% DETERMINE PRECALCULATABLE PART OF METRIC +% +INCREMENT=make_increment(SYMBOLS,NEXT,Rhh); +%INCREMENT +% THE FIRST THING TO DO IS TO ROLL INTO THE ALGORITHM BY SPREADING OUT +% FROM THE START STATE TO ALL THE LEGAL STATES. +% +PS=START; + +% NOTE THAT THE START STATE IS REFERRED TO AS STATE TO TIME 0 +% AND THAT IT HAS NO METRIC. +% +S=NEXT(START,1); + +METRIC(S,1)=real(conj(SYMBOLS(S,1))*Y(1))-INCREMENT(PS,S); +SURVIVOR(S,1)=START; + +S=NEXT(START,2); +METRIC(S,1)=real(conj(SYMBOLS(S,1))*Y(1))-INCREMENT(PS,S); +SURVIVOR(S,1)=START; + +PREVIOUS_STATES=NEXT(START,:); + +% MARK THE NEXT STATES AS REAL. N.B: COMPLEX INDICATES THE POLARITY +% OF THE NEXT STATE, E.G. STATE 2 IS REAL. +% +COMPLEX=0; + +for N = 2:Lh, + if COMPLEX, + COMPLEX=0; + else + COMPLEX=1; + end + STATE_CNTR=0; + for PS = PREVIOUS_STATES, + STATE_CNTR=STATE_CNTR+1; + S=NEXT(PS,1); + METRIC(S,N)=METRIC(PS,N-1)+real(conj(SYMBOLS(S,1))*Y(N))-INCREMENT(PS,S); + SURVIVOR(S,N)=PS; + USED(STATE_CNTR)=S; + STATE_CNTR=STATE_CNTR+1; + S=NEXT(PS,2); + METRIC(S,N)=METRIC(PS,N-1)+real(conj(SYMBOLS(S,1))*Y(N))-INCREMENT(PS,S); + SURVIVOR(S,N)=PS; + USED(STATE_CNTR)=S; + end + PREVIOUS_STATES=USED; +end +% AT ANY RATE WE WILL HAVE PROCESSED Lh STATES AT THIS TIME +% +PROCESSED=Lh; + +% WE WANT AN EQUAL NUMBER OF STATES TO BE REMAINING. THE NEXT LINES ENSURE +% THIS. +% + +if ~COMPLEX, + COMPLEX=1; + PROCESSED=PROCESSED+1; + N=PROCESSED; + for S = 2:2:M, + PS=PREVIOUS(S,1); + M1=METRIC(PS,N-1)+real(conj(SYMBOLS(S,1))*Y(N)-INCREMENT(PS,S)); + PS=PREVIOUS(S,2); + M2=METRIC(PS,N-1)+real(conj(SYMBOLS(S,1))*Y(N)-INCREMENT(PS,S)); + if M1 > M2, + METRIC(S,N)=M1; + SURVIVOR(S,N)=PREVIOUS(S,1); + else + METRIC(S,N)=M2; + SURVIVOR(S,N)=PREVIOUS(S,2); + end + end +end + +% NOW THAT WE HAVE MADE THE RUN-IN THE REST OF THE METRICS ARE +% CALCULATED IN THE STRAIGHT FORWARD MANNER. OBSERVE THAT ONLY +% THE RELEVANT STATES ARE CALCULATED, THAT IS REAL FOLLOWS COMPLEX +% AND VICE VERSA. +% +N=PROCESSED+1; +while N <= STEPS, + for S = 1:2:M-1, + PS=PREVIOUS(S,1); + M1=METRIC(PS,N-1)+real(conj(SYMBOLS(S,1))*Y(N)-INCREMENT(PS,S)); + PS=PREVIOUS(S,2); + M2=METRIC(PS,N-1)+real(conj(SYMBOLS(S,1))*Y(N)-INCREMENT(PS,S)); + if M1 > M2, + METRIC(S,N)=M1; + SURVIVOR(S,N)=PREVIOUS(S,1); + else + METRIC(S,N)=M2; + SURVIVOR(S,N)=PREVIOUS(S,2); + end + end + N=N+1; + for S = 2:2:M, + PS=PREVIOUS(S,1); + M1=METRIC(PS,N-1)+real(conj(SYMBOLS(S,1))*Y(N)-INCREMENT(PS,S)); + PS=PREVIOUS(S,2); + M2=METRIC(PS,N-1)+real(conj(SYMBOLS(S,1))*Y(N)-INCREMENT(PS,S)); + if M1 > M2, + METRIC(S,N)=M1; + SURVIVOR(S,N)=PREVIOUS(S,1); + else + METRIC(S,N)=M2; + SURVIVOR(S,N)=PREVIOUS(S,2); + end + end + N=N+1; +end + + +% HAVING CALCULATED THE METRICS, THE MOST PROBABLE STATESEQUENCE IS +% INITIALIZED BY CHOOSING THE HIGHEST METRIC AMONG THE LEGAL STOP +% STATES. +% +BEST_LEGAL=0; +for FINAL = STOPS, + if METRIC(FINAL,STEPS) > BEST_LEGAL, + S=FINAL; + BEST_LEGAL=METRIC(FINAL,STEPS); + end +end + +% UNCOMMENT FOR TEST OF METRIC +% +% METRIC +% BEST_LEGAL +% S +% pause + +% HAVING FOUND THE FINAL STATE, THE MSK SYMBOL SEQUENCE IS ESTABLISHED +% + +IEST(STEPS)=SYMBOLS(S,1); +N=STEPS-1; +while N > 0, + +% if(N>STEPS-40), +% previo=ceil(S/2) +% end + S=SURVIVOR(S,N+1); + IEST(N)=SYMBOLS(S,1); + N=N-1; +end + +% THE ESTIMATE IS NOW FOUND FROM THE FORMULA: +% IEST(n)=j*rx_burst(n)*rx_burst(n-1)*IEST(n-1) +% THE FORMULA IS REWRITTEN AS: +% rx_burst(n)=IEST(n)/(j*rx_burst(n-1)*IEST(n-1)) +% FOR INITIALIZATION THE FOLLOWING IS USED: +% IEST(0)=1 og rx_burst(0)=1 +% +rx_burst(1)=IEST(1)/(j*1*1); +for n = 2:STEPS, + rx_burst(n)=IEST(n)/(j*rx_burst(n-1)*IEST(n-1)); +end + +% rx_burst IS POLAR (-1 AND 1), THIS TRANSFORMS IT TO +% BINARY FORM (0 AND 1). +% + +rx_burst=(rx_burst+1)./2; + diff --git a/viterbi_generator/tests/utils/viterbi_init.m b/viterbi_generator/tests/utils/viterbi_init.m new file mode 100644 index 0000000..a43b801 --- /dev/null +++ b/viterbi_generator/tests/utils/viterbi_init.m @@ -0,0 +1,38 @@ +function [ SYMBOLS , PREVIOUS , NEXT , START , STOPS ] = viterbi_init(Lh) +% VITERBI_INIT: +% This function returns the tables which are used by the +% viterbi demodulator which is implemented in the GSMsim +% package. +% +% SYNTAX: [ SYMBOLS , PREVIOUS , NEXT , START , STOPS ] +% = +% viterbi_init(Lh) +% +% INPUT: Lh: The length of the channel impulse response +% minus one. +% +% OUTPUT: SYMBOLS: Statenumber to MSK-symbols mapping table. +% PREVIOUS: This state to legal previous state mapping table. +% NEXT: This state to legal next state mapping table. +% START: The start state of the viterbi algorithm. +% STOPS: The set of legal stop states for the viterbi +% algorithm. +% +% GLOBAL: None +% +% SUB_FUNC: make_symbols,make_previous,make_next,make_start,make_stops +% +% WARNINGS: None +% +% TEST: Verified that the function actually runs the subfunctions. +% +% AUTHOR: Jan H. Mikkelsen / Arne Norre Ekstrøm +% EMAIL: hmi@kom.auc.dk / aneks@kom.auc.dk +% +% $Id: viterbi_init.m,v 1.4 1998/02/12 10:52:15 aneks Exp $ + +SYMBOLS = make_symbols(Lh); +PREVIOUS = make_previous(SYMBOLS); +NEXT = make_next(SYMBOLS); +START = make_start(Lh,SYMBOLS); +STOPS = make_stops(Lh,SYMBOLS); -- cgit v1.2.3