diff options
Diffstat (limited to 'viterbi_generator/tests')
-rw-r--r-- | viterbi_generator/tests/data/normal_burst.dat | 6 | ||||
-rw-r--r-- | viterbi_generator/tests/data/rhh.dat | 6 | ||||
-rwxr-xr-x | viterbi_generator/tests/test_check.m | 56 | ||||
-rwxr-xr-x | viterbi_generator/tests/test_gen.m | 83 | ||||
-rw-r--r-- | viterbi_generator/tests/utils/make_increment.m | 70 | ||||
-rw-r--r-- | viterbi_generator/tests/utils/make_next.m | 54 | ||||
-rw-r--r-- | viterbi_generator/tests/utils/make_previous.m | 54 | ||||
-rw-r--r-- | viterbi_generator/tests/utils/make_start.m | 63 | ||||
-rw-r--r-- | viterbi_generator/tests/utils/make_stops.m | 67 | ||||
-rw-r--r-- | viterbi_generator/tests/utils/viterbi_detector.m | 218 | ||||
-rw-r--r-- | viterbi_generator/tests/utils/viterbi_init.m | 38 |
11 files changed, 715 insertions, 0 deletions
diff --git a/viterbi_generator/tests/data/normal_burst.dat b/viterbi_generator/tests/data/normal_burst.dat new file mode 100644 index 0000000..cbde38a --- /dev/null +++ b/viterbi_generator/tests/data/normal_burst.dat @@ -0,0 +1,6 @@ +# Created by Octave 3.0.0, Sun Dec 07 22:10:44 2008 CET <piotr@piotr-laptop> +# name: normal_burst +# type: complex matrix +# rows: 1 +# columns: 148 + (7977179.575842334,-2764222.417438231) (6856794.837415899,4865869.971701522) (9811374.762481783,5183732.883723894) (6679440.954922386,-4428971.382695343) (-4696701.829875357,-5933567.044617306) (-6541783.913531991,4653341.980626347) (2084689.136089761,10178136.33389057) (6147479.654568939,8874496.300197551) (5904918.085298464,8800690.925502732) (6748883.359764119,8777701.99895237) (6778221.845496094,8045655.950100697) (6364128.866015259,8022191.027790485) (8722069.281154793,4776436.493770716) (10932320.66341553,-1558217.346711523) (8712591.829617452,-1858753.981212688) (2379782.554878909,2932506.621771185) (-5444416.779109947,5946987.812324719) (-5424576.301366795,8041132.549737221) (4060723.573739645,5559136.64846923) (9867910.71698026,-1816506.536824186) (9116570.97744694,-6509021.212210049) (5005755.561673803,-8815847.513357516) (-2234914.896357608,-10346435.29296497) (-7202255.959453276,-9713796.984525394) (-9190470.490641661,-4700539.204802573) (-10344677.56318331,3164735.076391134) (-8144676.035821493,3689244.844807261) (-2187512.878540438,-2405086.800766177) (4192422.735599967,-2302450.194812776) (7246362.648469473,4298058.743439186) (6556902.896761281,8229181.331930954) (6142925.014497022,8026586.954769152) (8129663.314625547,4033126.426787131) (5840297.475172411,-4620492.674842792) (-1914675.110364774,-10020347.74689682) (-2940115.449563568,-8372239.28186238) (4008522.173926762,-6826920.4027513) (8135500.914007598,-7047328.230427532) (8405763.865765207,-6931698.977370714) (8929684.60841676,-6179537.907816172) (8180060.234703613,-2186703.089556943) (3091335.431867111,4054954.833985379) (-4295697.157828381,7927174.133346504) (-8473978.891786665,8708279.094237776) (-8307511.019450527,8912587.711675741) (-3924398.366246906,9788935.76403868) (3578818.136331406,9475507.775523672) (7878887.060875434,8305521.621609254) (7661073.44413343,8193166.008805315) (7711201.656500887,8476321.863353506) (8106392.393772357,8574168.66012821) (4338938.673600335,8161180.253521944) (-2892764.559653326,7908598.189004728) (-7361426.229118877,8354406.99665704) (-7399748.199851307,9027400.138110537) (-2985443.126902175,10343848.63110767) (4056164.268281491,10098505.09400246) (3662304.483904882,7612823.121273955) (-3973366.81657888,7937078.917571188) (-4235798.145293494,10334281.08680061) (3036808.068953499,9898067.648818504) (7473543.535633441,7807926.377577701) (9079322.039812893,3406424.495665565) (9858644.625831679,-3257437.035834751) (8880394.89067794,-7679278.009140568) (3363837.002219063,-9429173.71625155) (-5976744.033579396,-5385450.603450965) (-9557981.008868802,3050312.808275135) (-7022882.07013285,3640309.418994936) (-6956342.70055424,-3448204.434753519) (-7352343.418384315,-7661573.785117128) (-2991151.171234549,-7200411.918698126) (2885118.044527493,-2984883.7704812) (7032828.106442515,3581754.794175046) (10088763.75405868,3662867.846789958) (10564181.44456883,-3225930.10124573) (8350222.259163288,-3732983.787176989) (7833973.714202324,2987993.691082503) (9706408.673943322,3052094.809291443) (9745006.60948544,-3935102.054010465) (7816404.563798211,-8252538.72673445) (2986277.663389235,-9487975.529977793) (-5695845.629277196,-5169515.812036891) (-10054151.19384441,3411496.45829031) (-8051379.265738308,2941255.219687932) (-3549464.58574895,-3756761.751613705) (2758228.097400823,-3356159.692788773) (3030904.799713606,2423714.179333686) (-4312484.664824991,6565622.532791231) (-8292628.102357071,7907719.341642237) (-7526932.969593002,8014555.798755471) (-7845877.058982445,7739528.888483866) (-8621562.52814143,7418568.373775017) (-8417158.059851743,7181224.216350028) (-8512688.8578708,7987622.681439973) (-4394195.283606119,9949034.472254608) (5266129.291599136,6195329.68568805) (10194253.69504469,-2784736.708811181) (8824963.809236836,-7786593.488088661) (3396738.808078639,-9691138.584095873) (-5722550.505156678,-5556953.717315165) (-5714701.21871692,5472711.90841134) (3332017.262149745,9704527.797128931) (7342514.528813555,7753950.512219134) (6818048.987995462,8189460.303227851) (3394201.964273538,7945062.7654535) (-4167885.511983512,6895554.165900515) (-8619065.547944224,6801211.716255617) (-7427938.633889003,2908143.990531422) (-6703266.997337797,-4149571.893369118) (-7397979.408319066,-8091927.82717395) (-8023643.386183736,-8148580.271161931) (-9593984.742403097,-3401373.756765883) (-9949905.478216713,3693487.850592313) (-7643884.055928037,3256209.472513159) (-2697566.672122434,-3206105.087111734) (3377896.546916216,-3637995.937387224) (7053276.04109713,2764169.146215447) (8628643.160917941,3396969.972018227) (8591483.693362383,-3571890.231694249) (7631932.362041099,-7892583.334526137) (3523270.049984952,-9235294.629945757) (-5210049.188676764,-5470018.026155467) (-5729032.983653861,4597120.705589911) (4722045.647456144,5593554.046296648) (9943005.230296012,-3058974.832172701) (7338276.272285849,-3095524.728011495) (6924101.789435759,4679671.472522281) (9394305.400845038,4311128.98481571) (9835558.718232434,-3667900.007702321) (8223108.712000148,-8579057.297566241) (2845955.65886871,-9157587.991012959) (-5965686.3459505,-4635464.373605222) (-9515672.979250863,3206974.918525696) (-8344649.14188644,7073463.424866714) (-8254731.199008162,7048210.74046527) (-7504645.106599139,3469527.977909835) (-6905884.654448108,-4071500.776307517) (-7265828.021198342,-8724546.709091771) (-3159001.544609685,-7599002.095846066) (4820872.724960422,-7688968.483649141) (4538964.484279973,-10655536.8874595) (-4627802.476316519,-6342339.722614718) (-5229789.984553174,4793436.509895318) (3023641.900808552,9426626.555313969) (3151170.485840399,7510483.156596448) (-3112381.95965953,6480539.799831223) (-3526072.302890599,4305425.630118813) diff --git a/viterbi_generator/tests/data/rhh.dat b/viterbi_generator/tests/data/rhh.dat new file mode 100644 index 0000000..4a06772 --- /dev/null +++ b/viterbi_generator/tests/data/rhh.dat @@ -0,0 +1,6 @@ +# Created by Octave 3.0.0, Sun Dec 07 22:10:44 2008 CET <piotr@piotr-laptop> +# name: Rhh +# type: complex matrix +# rows: 1 +# columns: 6 + (6681134.234745174,3.462940897916484e-11) (4315167.063742221,-860367.8252039659) (935284.8973972955,-371780.5098627206) (-51462.68718506447,50393.67553327526) (-7439.804484758702,8028.159897103877) (-0.804484758702,0.159897103877) diff --git a/viterbi_generator/tests/test_check.m b/viterbi_generator/tests/test_check.m new file mode 100755 index 0000000..a08c801 --- /dev/null +++ b/viterbi_generator/tests/test_check.m @@ -0,0 +1,56 @@ +#!/usr/bin/octave --silent +addpath("./tests/utils"); +addpath("./utils"); +addpath("./utils/lower_utils"); +addpath("./utils/lower_utils/lower_utils"); + +arg_list=argv(); +Lh=sscanf(arg_list{1}, "%d", "C"); +PATHS_NUM=2**(Lh); +load tests/data/rhh.dat; +load tests/data/normal_burst.dat; +load test_result; + +[r BURST_SIZE] = size(normal_burst); + +[ SYMBOLS , PREVIOUS , NEXT , START , STOPS ] = viterbi_init(Lh); + +path_metrics_test_result = path_metrics_test_result.'; +[rx_burst METRIC] = viterbi_detector(SYMBOLS,NEXT,PREVIOUS,START,STOPS,normal_burst,Rhh); +[r,burst_size] = size(METRIC); +sum_check=0; %number of errors + +%find branch metrics computation errors number (errors bigger than 1000) +for i=1:2:burst_size, + check_matrix = (abs(METRIC(1:2:r,i)-path_metrics_test_result(:,i))); + suma=sum( check_matrix > ones(PATHS_NUM,1)*1000); + sum_check = sum_check + suma; + + check_matrix = (abs(METRIC(2:2:r,i+1)-path_metrics_test_result(:,i+1))); + suma=sum( check_matrix > ones(PATHS_NUM,1)*1000); + sum_check = sum_check + suma; +end + +%compute expected number of errors (errors from the beginning) +q=2; +expected_result=0; +while(q<PATHS_NUM), + expected_result=expected_result + (PATHS_NUM-q); + q=q*2; +end + +%check result +if(sum_check == expected_result), + printf("Path metrics test: ok\n"); +else + sum_check + printf("Path metrics test: failed\n"); +end + +%check output of the viterbi_detector function +if(sum(output==rx_burst) == BURST_SIZE), + printf("Final result test: ok\n"); +else + printf("Final result test: failed\n"); +end + diff --git a/viterbi_generator/tests/test_gen.m b/viterbi_generator/tests/test_gen.m new file mode 100755 index 0000000..a2639fb --- /dev/null +++ b/viterbi_generator/tests/test_gen.m @@ -0,0 +1,83 @@ +#!/usr/bin/octave --silent + +addpath("./tests/utils"); +addpath("./utils"); +addpath("./utils/lower_utils"); +addpath("./utils/lower_utils/lower_utils"); +arg_list=argv(); +Lh=sscanf(arg_list{1}, "%d", "C"); + +INCREMENT_NUM=2**(Lh-1); +BRANCH_NUM=2**(Lh+1); +PATHS_NUM=2**(Lh); + +load tests/data/rhh.dat; +load tests/data/normal_burst.dat; + +[r BURST_SIZE] = size(normal_burst); + +SYMBOLS = make_symbols(Lh); +START = make_start(Lh,SYMBOLS); +STOP = make_stops(Lh,SYMBOLS); + +[increment, pm_candidates_imag, pm_candidates_real] = equations_gen(Lh); + +f_name="test"; +test_file = fopen([f_name '.cpp'],'w'); + +print_matrix_type=sprintf(" printf(\"# name: path_metrics_test_result\\n# type: matrix\\n# rows: %d\\n# columns: %d\\n\");\n", BURST_SIZE, PATHS_NUM);; + +print_path_metrics=[ "\n\ + for(i=0; i<" int2str(PATHS_NUM) "; i++){\n\ + printf(\" %0.6f\", new_path_metrics[i]);\n\ + }\n\ + printf(\"\\n\");\n\n" ]; + +viterbi_detector = viterbi_generator(Lh, print_matrix_type, print_path_metrics); + +fprintf(test_file, "\ +#include <stdio.h>\n", BURST_SIZE); + +fprintf(test_file, "%s", viterbi_detector); + +fprintf(test_file, [ "\ +int main()\n\ +{\n\ + gr_complex rhh[" int2str(Lh+1) "];\n\ + gr_complex input[BURST_SIZE];\n\ + float output[BURST_SIZE];\n\ + float path_metrics[" int2str(PATHS_NUM) "];\n\ + unsigned int i;\n\n" ]); + +for i=1:Lh+1, + fprintf(test_file," rhh[%d] = gr_complex(%0.10f,%0.10f);\n",i-1, real(Rhh(i)), imag(Rhh(i))); +end + +for i=1:BURST_SIZE, + fprintf(test_file," input[%d] = gr_complex(%0.10f,%0.10f);\n",i-1, real(normal_burst(i)), imag(normal_burst(i))); +end + +[STOPS_NUM c] = size(STOP); + +stop_states=[" unsigned int stop_states[" int2str(STOPS_NUM) "] = { "]; +for i=1:STOPS_NUM, + stop_states=[ stop_states int2str(ceil(STOP(i)/2)-1) ", "]; +end +stop_states=[ stop_states " };\n\n" ]; + +fprintf(test_file, stop_states); + +fprintf(test_file, [" viterbi_detector(input, BURST_SIZE, rhh, " int2str(ceil(START/2)-1) ", stop_states, " int2str(STOPS_NUM) ", output);" ]); + +print_output=[ "\n\ + printf(\"# name: output\\n# type: matrix\\n# rows: 1\\n# columns: " int2str(BURST_SIZE) "\\n\");\n\ + for(i=0; i<BURST_SIZE ; i++){\n\ + printf(\" %d\\n\", output[i]>0);\n\ + }\n\ + printf(\"\\n\");\n" ]; + +fprintf(test_file, "%s", print_output); + +fprintf(test_file, "\n}\n"); + + 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); |