summaryrefslogtreecommitdiff
path: root/viterbi_generator
diff options
context:
space:
mode:
authorAndreas Bogk <andreas@pt141.(none)>2009-01-15 17:17:29 +0100
committerAndreas Bogk <andreas@pt141.(none)>2009-01-15 17:17:29 +0100
commit7ebd609b4f4139f4dac8627ac00678de89ef4575 (patch)
tree44cc5b2816c8096e6e22781ee4332d840c5658a4 /viterbi_generator
parent602a3c8aa8a3d9bd4d93deda6ac932404f39584d (diff)
Viterbi generator by Piotr Krysik.
Diffstat (limited to 'viterbi_generator')
-rw-r--r--viterbi_generator/COPYING674
-rw-r--r--viterbi_generator/Makefile22
-rw-r--r--viterbi_generator/README16
-rwxr-xr-xviterbi_generator/make_function.m54
-rw-r--r--viterbi_generator/tests/data/normal_burst.dat6
-rw-r--r--viterbi_generator/tests/data/rhh.dat6
-rwxr-xr-xviterbi_generator/tests/test_check.m56
-rwxr-xr-xviterbi_generator/tests/test_gen.m83
-rw-r--r--viterbi_generator/tests/utils/make_increment.m70
-rw-r--r--viterbi_generator/tests/utils/make_next.m54
-rw-r--r--viterbi_generator/tests/utils/make_previous.m54
-rw-r--r--viterbi_generator/tests/utils/make_start.m63
-rw-r--r--viterbi_generator/tests/utils/make_stops.m67
-rw-r--r--viterbi_generator/tests/utils/viterbi_detector.m218
-rw-r--r--viterbi_generator/tests/utils/viterbi_init.m38
-rw-r--r--viterbi_generator/utils/lower_utils/equations_gen.m124
-rw-r--r--viterbi_generator/utils/lower_utils/generate_increment.m72
-rw-r--r--viterbi_generator/utils/lower_utils/lower_utils/complex_vect2number.m44
-rw-r--r--viterbi_generator/utils/lower_utils/lower_utils/generate_previous.m35
-rw-r--r--viterbi_generator/utils/lower_utils/lower_utils/make_symbols.m35
-rw-r--r--viterbi_generator/utils/viterbi_generator.m305
21 files changed, 2096 insertions, 0 deletions
diff --git a/viterbi_generator/COPYING b/viterbi_generator/COPYING
new file mode 100644
index 0000000..94a9ed0
--- /dev/null
+++ b/viterbi_generator/COPYING
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/viterbi_generator/Makefile b/viterbi_generator/Makefile
new file mode 100644
index 0000000..4730a7c
--- /dev/null
+++ b/viterbi_generator/Makefile
@@ -0,0 +1,22 @@
+Lh=4
+CXX=g++
+CFLAGS=-O
+
+viterbi_detector.c: ./utils/viterbi_generator.m ./utils/lower_utils/equations_gen.m make_function.m
+ @./make_function.m $(Lh)
+
+test: tests/test_gen.m tests/test_check.m ./utils/viterbi_generator.m ./utils/lower_utils/equations_gen.m
+ @./tests/$@_gen.m $(Lh)
+ @$(CXX) $(LDFLAGS) $(CFLAGS) $@.cpp -o $@
+ @./$@ > $@_result
+# @less $@_result
+# @rm $@.c
+ @rm $@
+ @./tests/$@_check.m $(Lh)
+ @rm $@_result
+
+
+clean:
+ rm -f *.o
+ rm -f *.c
+ rm *~
diff --git a/viterbi_generator/README b/viterbi_generator/README
new file mode 100644
index 0000000..d9502fd
--- /dev/null
+++ b/viterbi_generator/README
@@ -0,0 +1,16 @@
+This is generator for Viterbi Algorithm part of Viterbi Equalizer.
+It is able to generate viterbi detector for channels with memory lengths
+of 2,3,4,5 symbols.
+
+To generate function in C++ for channel memory length of four symbols (Lh=4)
+just type:
+$ make
+
+
+To generate function for some other channel memory length type:
+$ make Lh=x
+where 'x' is channel memory length (value from 2 to 5)
+
+To check if algorithm works properly type:
+$ make test Lh=x
+
diff --git a/viterbi_generator/make_function.m b/viterbi_generator/make_function.m
new file mode 100755
index 0000000..98eae81
--- /dev/null
+++ b/viterbi_generator/make_function.m
@@ -0,0 +1,54 @@
+#!/usr/bin/octave --silent
+
+ ###########################################################################
+ # Copyright (C) 2008 by Piotr Krysik #
+ # pkrysik@stud.elka.pw.edu.pl #
+ # #
+ # This program is free software; you can redistribute it and/or modify #
+ # it under the terms of the GNU General Public License as published by #
+ # the Free Software Foundation; either version 3 of the License, or #
+ # (at your option) any later version. #
+ # #
+ # This program is distributed in the hope that it will be useful, #
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of #
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+ # GNU General Public License for more details. #
+ # #
+ # You should have received a copy of the GNU General Public License #
+ # along with this program; if not, write to the #
+ # Free Software Foundation, Inc., #
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
+ ###########################################################################
+
+addpath("./utils");
+addpath("./utils/lower_utils");
+addpath("./utils/lower_utils/lower_utils");
+arg_list=argv();
+Lh=sscanf(arg_list{1}, "%d", "C");
+license_statement="\
+/***************************************************************************\n\
+ * Copyright (C) 2008 by Piotr Krysik *\n\
+ * pkrysik@stud.elka.pw.edu.pl *\n\
+ * *\n\
+ * This program is free software; you can redistribute it and/or modify *\n\
+ * it under the terms of the GNU General Public License as published by *\n\
+ * the Free Software Foundation; either version 2 of the License, or *\n\
+ * (at your option) any later version. *\n\
+ * *\n\
+ * This program is distributed in the hope that it will be useful, *\n\
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *\n\
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *\n\
+ * GNU General Public License for more details. *\n\
+ * *\n\
+ * You should have received a copy of the GNU General Public License *\n\
+ * along with this program; if not, write to the *\n\
+ * Free Software Foundation, Inc., *\n\
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *\n\
+ ***************************************************************************/\n\n";
+f_name="viterbi_detector";
+viterbi_detector_file = fopen([f_name '.cpp'],'w');
+viterbi_detector = viterbi_generator(Lh);
+fprintf(viterbi_detector_file, "%s", license_statement);
+fprintf(viterbi_detector_file, "%s", viterbi_detector);
+
+
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);
diff --git a/viterbi_generator/utils/lower_utils/equations_gen.m b/viterbi_generator/utils/lower_utils/equations_gen.m
new file mode 100644
index 0000000..af7d37e
--- /dev/null
+++ b/viterbi_generator/utils/lower_utils/equations_gen.m
@@ -0,0 +1,124 @@
+function [increment, pm_candidates_imag, pm_candidates_real]= equations_gen(Lh)
+
+ ###########################################################################
+ # Copyright (C) 2008 by Piotr Krysik #
+ # pkrysik@stud.elka.pw.edu.pl #
+ # #
+ # This program is free software; you can redistribute it and/or modify #
+ # it under the terms of the GNU General Public License as published by #
+ # the Free Software Foundation; either version 3 of the License, or #
+ # (at your option) any later version. #
+ # #
+ # This program is distributed in the hope that it will be useful, #
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of #
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+ # GNU General Public License for more details. #
+ # #
+ # You should have received a copy of the GNU General Public License #
+ # along with this program; if not, write to the #
+ # Free Software Foundation, Inc., #
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
+ ###########################################################################
+
+INCREMENT_NUM=2**(Lh-1);
+
+SYMBOLS = make_symbols(Lh);
+PREVIOUS = generate_previous(Lh);
+
+load tests/data/rhh.dat
+
+[INCREMENT NUMBERS] = generate_increment(SYMBOLS,PREVIOUS);
+
+function_real="real";
+function_imag="imag";
+sign="";
+fction="";
+equation_num="";
+increment = { };
+equation="";
+
+for equation_num=1:INCREMENT_NUM,
+ for part_num=1:Lh,
+ coefficient=INCREMENT(equation_num,part_num);
+ if(coefficient==1 || coefficient==-1),
+ fction=function_real;
+ else
+ fction=function_imag;
+ coefficient=coefficient*j;
+ end
+
+ if(coefficient==1 && part_num != 1),
+ sign="+";
+ elseif(coefficient==-1),
+ sign="-";
+ else
+ sign="";
+ end
+
+ equation = [equation " " sign "rhh[" int2str(part_num) "]." fction "()" ];
+ end
+
+ increment(equation_num) = ["increment[" int2str(equation_num-1) "] =" equation];
+ equation="";
+end
+
+
+BRANCH_NUM=2**(Lh+1);
+
+
+%make path metrics
+pm_candidates_real={};
+pm_candidates_imag={};
+for symbol_num=1:BRANCH_NUM,
+
+ inc1_num=NUMBERS(PREVIOUS(symbol_num,1),symbol_num);
+ inc2_num=NUMBERS(PREVIOUS(symbol_num,2),symbol_num);
+
+ symbol=SYMBOLS(symbol_num,1);
+
+ if(inc1_num<0)
+ inc1_sign="+";
+ inc1_num=-inc1_num;
+ else
+ inc1_sign="-";
+ end
+
+ if(inc2_num<0)
+ inc2_sign="+";
+ inc2_num=-inc2_num;
+ else
+ inc2_sign="-";
+ end
+
+ inc1_num=inc1_num-1;
+ inc2_num=inc2_num-1;
+
+ if(symbol==1 || symbol==-1),
+ fction=function_real;
+ else
+ fction=function_imag;
+ symbol=symbol*(-j);
+ end
+
+ if(symbol==1),
+ symbol_sign="+";
+ else
+ symbol_sign="-";
+ end
+
+ branch_metric1=[" " symbol_sign " input_symbol_" fction " " inc1_sign " increment[" int2str(inc1_num) "]" ];
+ branch_metric2=[" " symbol_sign " input_symbol_" fction " " inc2_sign " increment[" int2str(inc2_num) "]" ];
+
+ num = ceil((symbol_num)/2);
+ prev1_num = ceil((PREVIOUS(symbol_num,1))/2)-1;
+ prev2_num = ceil((PREVIOUS(symbol_num,2))/2)-1;
+
+ if(mod(symbol_num,2)==1),
+ pm_candidates_imag(num, 1)=[ "pm_candidate1 = old_path_metrics[" int2str(prev1_num) "]" branch_metric1 ];
+ pm_candidates_imag(num, 2)=[ "pm_candidate2 = old_path_metrics[" int2str(prev2_num) "]" branch_metric2 ];
+ else
+ pm_candidates_real(num, 1)=[ "pm_candidate1 = old_path_metrics[" int2str(prev1_num) "]" branch_metric1 ];
+ pm_candidates_real(num, 2)=[ "pm_candidate2 = old_path_metrics[" int2str(prev2_num) "]" branch_metric2 ];
+ end
+end
+
diff --git a/viterbi_generator/utils/lower_utils/generate_increment.m b/viterbi_generator/utils/lower_utils/generate_increment.m
new file mode 100644
index 0000000..9575796
--- /dev/null
+++ b/viterbi_generator/utils/lower_utils/generate_increment.m
@@ -0,0 +1,72 @@
+function [INCREMENT NUMBERS] = generate_increment(SYMBOLS,PREVIOUS)%,Rhh)
+
+ ###########################################################################
+ # Copyright (C) 2008 by Piotr Krysik #
+ # pkrysik@stud.elka.pw.edu.pl #
+ # #
+ # This program is free software; you can redistribute it and/or modify #
+ # it under the terms of the GNU General Public License as published by #
+ # the Free Software Foundation; either version 3 of the License, or #
+ # (at your option) any later version. #
+ # #
+ # This program is distributed in the hope that it will be useful, #
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of #
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+ # GNU General Public License for more details. #
+ # #
+ # You should have received a copy of the GNU General Public License #
+ # along with this program; if not, write to the #
+ # Free Software Foundation, Inc., #
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
+ ###########################################################################
+
+MSK_STATES_NUM=4; % 1,-1,j,-j
+[POSIBLE_SEQ_NUM,Lh]=size(SYMBOLS);
+INCREMENT_NUM=2**(Lh-1);
+%Lh - channel memory length
+%POSIBLE_SEQ_NUM - number of posible sequences of MSK symbols (1,-1,j,-j) for given Lh
+
+%INCREMENT=zeros(2,Lh,POSIBLE_SEQ_NUM/8);
+
+% Rhh IS STORED AS:
+% [ Rhh(1) Rhh(2) Rhh(3) ... Rhh(Lh) ]
+INCREMENT=zeros(INCREMENT_NUM, Lh);
+
+for n=1:POSIBLE_SEQ_NUM,
+ % ONLY TWO LEGAL PREVIOUS STATES EXIST, SO THE LOOP IS UNROLLED
+ m=PREVIOUS(n,1);
+ vector=[conj(SYMBOLS(n,1))* SYMBOLS(m,:)];
+ number=complex_vect2number(vector);
+ if(number>0)
+ INCREMENT(number,:)=vector;
+ end
+
+ NUMBERS(m,n)=number;
+
+ m=PREVIOUS(n,2);
+ vector=[conj(SYMBOLS(n,1))* SYMBOLS(m,:)];
+ number=complex_vect2number(vector);
+ if(number>0)
+ INCREMENT(number,:)=vector;
+ end
+ NUMBERS(m,n)=number;
+end
+
+%test_inc=zeros(2**(Lh+1),2**(Lh+1));
+%for n=1:2**(Lh+1),
+% for m=1:2**(Lh+1),
+% number=NUMBERS(m,n);
+
+% if(number!=0)
+% sign=1;
+% if(number<0),
+% sign=-1;
+% number=-number;
+% end
+% test_inc(m,n)=real(sign*INCREMENT(number,:)*Rhh(2:Lh+1).');
+% end
+% end
+%end
+%INCREMENT
+%test_inc
+%NUMBERS
diff --git a/viterbi_generator/utils/lower_utils/lower_utils/complex_vect2number.m b/viterbi_generator/utils/lower_utils/lower_utils/complex_vect2number.m
new file mode 100644
index 0000000..f0d6d25
--- /dev/null
+++ b/viterbi_generator/utils/lower_utils/lower_utils/complex_vect2number.m
@@ -0,0 +1,44 @@
+function [ number ] = complex_vect2number(vector)
+
+ ###########################################################################
+ # Copyright (C) 2008 by Piotr Krysik #
+ # pkrysik@stud.elka.pw.edu.pl #
+ # #
+ # This program is free software; you can redistribute it and/or modify #
+ # it under the terms of the GNU General Public License as published by #
+ # the Free Software Foundation; either version 3 of the License, or #
+ # (at your option) any later version. #
+ # #
+ # This program is distributed in the hope that it will be useful, #
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of #
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+ # GNU General Public License for more details. #
+ # #
+ # You should have received a copy of the GNU General Public License #
+ # along with this program; if not, write to the #
+ # Free Software Foundation, Inc., #
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
+ ###########################################################################
+
+% Change complex vector of values: 1,-1 or j,-j
+% into a integer number.
+
+ number=0;
+ [r,Lh] = size(vector);
+ for l=1:Lh,
+ position=2**(l-1);
+ if(vector(l)==1),
+ number=number+position*(1);
+ elseif(vector(l)==-1),
+ number=number+position*(-1);
+ elseif(vector(l)==-j),
+ number=number+position*(1);
+ elseif(vector(l)==j),
+ number=number+position*(-1);
+ end
+ end
+ if number < 0,
+ number=floor(number/2);
+ else
+ number=ceil(number/2);
+ end
diff --git a/viterbi_generator/utils/lower_utils/lower_utils/generate_previous.m b/viterbi_generator/utils/lower_utils/lower_utils/generate_previous.m
new file mode 100644
index 0000000..942c4dc
--- /dev/null
+++ b/viterbi_generator/utils/lower_utils/lower_utils/generate_previous.m
@@ -0,0 +1,35 @@
+function [ PREVIOUS ] = generate_previous(Lh)
+
+ ###########################################################################
+ # Copyright (C) 2008 by Piotr Krysik #
+ # pkrysik@stud.elka.pw.edu.pl #
+ # #
+ # This program is free software; you can redistribute it and/or modify #
+ # it under the terms of the GNU General Public License as published by #
+ # the Free Software Foundation; either version 3 of the License, or #
+ # (at your option) any later version. #
+ # #
+ # This program is distributed in the hope that it will be useful, #
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of #
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+ # GNU General Public License for more details. #
+ # #
+ # You should have received a copy of the GNU General Public License #
+ # along with this program; if not, write to the #
+ # Free Software Foundation, Inc., #
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
+ ###########################################################################
+
+SYMBOLS_NUM = 2**(Lh+1);
+n=1;
+for i=1:4:SYMBOLS_NUM,
+ PREVIOUS(i,1) = n+1;
+ PREVIOUS(i,2) = n+SYMBOLS_NUM/2+1;
+ PREVIOUS(i+1,1) = n;
+ PREVIOUS(i+1,2) = n+SYMBOLS_NUM/2;
+ PREVIOUS(i+2,1) = n+1;
+ PREVIOUS(i+2,2) = n+SYMBOLS_NUM/2+1;
+ PREVIOUS(i+3,1) = n;
+ PREVIOUS(i+3,2) = n+SYMBOLS_NUM/2;
+ n=n+2;
+end
diff --git a/viterbi_generator/utils/lower_utils/lower_utils/make_symbols.m b/viterbi_generator/utils/lower_utils/lower_utils/make_symbols.m
new file mode 100644
index 0000000..3849fbd
--- /dev/null
+++ b/viterbi_generator/utils/lower_utils/lower_utils/make_symbols.m
@@ -0,0 +1,35 @@
+function [ SYMBOLS ] = make_symbols(Lh)
+
+ ###########################################################################
+ # Copyright (C) 2008 by Piotr Krysik #
+ # pkrysik@stud.elka.pw.edu.pl #
+ # #
+ # This program is free software; you can redistribute it and/or modify #
+ # it under the terms of the GNU General Public License as published by #
+ # the Free Software Foundation; either version 3 of the License, or #
+ # (at your option) any later version. #
+ # #
+ # This program is distributed in the hope that it will be useful, #
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of #
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+ # GNU General Public License for more details. #
+ # #
+ # You should have received a copy of the GNU General Public License #
+ # along with this program; if not, write to the #
+ # Free Software Foundation, Inc., #
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
+ ###########################################################################
+
+BRANCH_NUM=2**(Lh+1);
+SYMBOLS=ones(BRANCH_NUM, Lh);
+
+for column=1:Lh,
+ for i=1:(2**column),
+ SYMBOLS(i:(2**(column+1)):BRANCH_NUM,column)=-1;
+ end
+
+end
+
+SYMBOLS(1:2:BRANCH_NUM, 1:2:Lh) = SYMBOLS(1:2:BRANCH_NUM, 1:2:Lh).*(-j);
+SYMBOLS(2:2:BRANCH_NUM, 2:2:Lh) = SYMBOLS(2:2:BRANCH_NUM, 2:2:Lh).*(-j);
+
diff --git a/viterbi_generator/utils/viterbi_generator.m b/viterbi_generator/utils/viterbi_generator.m
new file mode 100644
index 0000000..f9a9621
--- /dev/null
+++ b/viterbi_generator/utils/viterbi_generator.m
@@ -0,0 +1,305 @@
+function [viterbi_detector] = viterbi_generator(Lh, varargin)
+
+ ###########################################################################
+ # Copyright (C) 2008 by Piotr Krysik #
+ # pkrysik@stud.elka.pw.edu.pl #
+ # #
+ # This program is free software; you can redistribute it and/or modify #
+ # it under the terms of the GNU General Public License as published by #
+ # the Free Software Foundation; either version 3 of the License, or #
+ # (at your option) any later version. #
+ # #
+ # This program is distributed in the hope that it will be useful, #
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of #
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+ # GNU General Public License for more details. #
+ # #
+ # You should have received a copy of the GNU General Public License #
+ # along with this program; if not, write to the #
+ # Free Software Foundation, Inc., #
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
+ ###########################################################################
+
+if(nargin!=1 && nargin !=3),
+ printf("Bad number of arguments in viterbi_generator(...)");
+ exit(1)
+elseif(nargin==1)
+ print_matrix_type="";
+ print_path_metrics="";
+elseif(nargin==3)
+ %additional parameters for test
+ print_matrix_type=varargin{1};
+ print_path_metrics=varargin{2};
+end
+
+INCREMENT_NUM=2**(Lh-1);
+BRANCH_NUM=2**(Lh+1);
+PATHS_NUM=2**(Lh);
+PREVIOUS = generate_previous(Lh);
+
+[increment, pm_candidates_imag, pm_candidates_real] = equations_gen(Lh);
+
+function_interface_comment="\
+/*\n\
+** viterbi_detector:\n\
+** This part does the detection of received sequnece.\n\
+** Employed algorithm is viterbi Maximum Likehood Sequence Estimation.\n\
+** At this moment it gives hard decisions on the output, but\n\
+** it was designed with soft decisions in mind.\n\
+**\n\
+** SYNTAX: void viterbi_detector(\n\
+** const gr_complex * input, \n\
+** unsigned int samples_num, \n\
+** gr_complex * rhh, \n\
+** unsigned int start_state, \n\
+** const unsigned int * stop_states, \n\
+** unsigned int stops_num, \n\
+** float * output)\n\
+**\n\
+** INPUT: input: Complex received signal afted matched filtering.\n\
+** samples_num: Number of samples in the input table.\n\
+** rhh: The autocorrelation of the estimated channel \n\
+** impulse response.\n\
+** start_state: Number of the start point. In GSM each burst \n\
+** starts with sequence of three bits (0,0,0) which \n\
+** indicates start point of the algorithm.\n\
+** stop_states: Table with numbers of possible stop states.\n\
+** stops_num: Number of possible stop states\n\
+** \n\
+**\n\
+** OUTPUT: output: Differentially decoded hard output of the algorithm: \n\
+** -1 for logical \"0\" and 1 for logical \"1\"\n\
+**\n\
+** SUB_FUNC: none\n\
+**\n\
+** TEST(S): Tested with real world normal burst.\n\
+*/\n\n";
+
+beginning=[ "\
+#include <gnuradio/gr_complex.h>\n\
+#define BURST_SIZE 148\n\
+#define PATHS_NUM " int2str(PATHS_NUM) "\n\
+\n\
+void viterbi_detector(const gr_complex * input, unsigned int samples_num, gr_complex * rhh, unsigned int start_state, const unsigned int * stop_states, unsigned int stops_num, float * output)\n\
+{\n\
+ float increment[" int2str(INCREMENT_NUM) "];\n\
+ float path_metrics1[" int2str(PATHS_NUM) "];\n\
+ float path_metrics2[" int2str(PATHS_NUM) "];\n\
+ float * new_path_metrics;\n\
+ float * old_path_metrics;\n\
+ float * tmp;\n\
+ float trans_table[BURST_SIZE][" int2str(PATHS_NUM) "];\n\
+ float pm_candidate1, pm_candidate2;\n\
+ bool real_imag;\n\
+ float input_symbol_real, input_symbol_imag;\n\
+ unsigned int i, sample_nr;\n\n" ];
+
+
+
+start_point_comment="\
+/*\n\
+* Setup first path metrics, so only state pointed by start_state is possible.\n\
+* Start_state metric is equal to zero, the rest is written with some very low value,\n\
+* which makes them practically impossible to occur.\n\
+*/\n";
+
+start_point=[ "\
+ for(i=0; i<PATHS_NUM; i++){\n\
+ path_metrics1[i]=(-10e30);\n\
+ }\n\
+ path_metrics1[start_state]=0;\n\n" ];
+
+
+
+increment_comment="\
+/*\n\
+* Compute Increment - a table of values which does not change for subsequent input samples.\n\
+* Increment is table of reference levels for computation of branch metrics:\n\
+* branch metric = (+/-)received_sample (+/-) reference_level\n\
+*/\n";
+
+increment_block="";
+for i=1:INCREMENT_NUM,
+ increment_block = [increment_block sprintf(" %s;\n",increment(i))];
+end
+
+
+
+path_metrics_comment="\n\n\
+/*\n\
+* Computation of path metrics and decisions (Add-Compare-Select).\n\
+* It's composed of two parts: one for odd input samples (imaginary numbers)\n\
+* and one for even samples (real numbers).\n\
+* Each part is composed of independent (parallelisable) statements like \n\
+* this one:\n\
+* pm_candidate1 = old_path_metrics[0] - input_symbol_real - increment[7];\n\
+* pm_candidate2 = old_path_metrics[8] - input_symbol_real + increment[0];\n\
+* if(pm_candidate1 > pm_candidate2){\n\
+* new_path_metrics[0] = pm_candidate1;\n\
+* trans_table[sample_nr][0] = -1.0;\n\
+* }\n\
+* else{\n\
+* new_path_metrics[0] = pm_candidate2;\n\
+* trans_table[sample_nr][0] = 1.0;\n\
+* }\n\
+* This is very good point for optimisations (SIMD or OpenMP) as it's most time \n\
+* consuming part of this function. \n\
+*/\n";
+
+path_metrics_block=" sample_nr=0;\n";
+
+path_metrics_block=[path_metrics_block " old_path_metrics=path_metrics1;\n"];
+path_metrics_block=[path_metrics_block " new_path_metrics=path_metrics2;\n"];
+
+path_metrics_block=[path_metrics_block "\
+ while(sample_nr<samples_num){\n\
+ //Processing imag states\n\
+ real_imag=1;\n\
+ input_symbol_imag = input[sample_nr].imag();\n"];
+
+
+ for i=1:PATHS_NUM,
+ path_metrics_block=[path_metrics_block sprintf("\n %s;\n %s;\n", pm_candidates_imag(i, 1), pm_candidates_imag(i, 2)) ];
+
+ path_metrics_block=[path_metrics_block "\
+ if(pm_candidate1 > pm_candidate2){\n\
+ new_path_metrics[" int2str(i-1) "] = pm_candidate1;\n\
+ trans_table[sample_nr][" int2str(i-1) "] = -1.0;\n\
+ }\n\
+ else{\n\
+ new_path_metrics[" int2str(i-1) "] = pm_candidate2;\n\
+ trans_table[sample_nr][" int2str(i-1) "] = 1.0;\n\
+ }\n"];
+ end
+
+ path_metrics_block=[path_metrics_block print_path_metrics];
+ %change new metrics into old metrics
+ path_metrics_block=[path_metrics_block " tmp=old_path_metrics;\n"];
+ path_metrics_block=[path_metrics_block " old_path_metrics=new_path_metrics;\n"];
+ path_metrics_block=[path_metrics_block " new_path_metrics=tmp;\n\n"];
+
+ path_metrics_block=[path_metrics_block " sample_nr++;\n"];
+ path_metrics_block=[path_metrics_block " if(sample_nr==samples_num)\n break;\n\n"];
+ path_metrics_block=[path_metrics_block " //Processing real states\n"];
+ path_metrics_block=[path_metrics_block " real_imag=0;\n"];
+ path_metrics_block=[path_metrics_block " input_symbol_real = input[sample_nr].real();\n"];
+ for i=1:PATHS_NUM,
+ path_metrics_block=[path_metrics_block sprintf("\n %s;\n %s;\n", pm_candidates_real(i, 1), pm_candidates_real(i, 2)) ];
+ path_metrics_block=[path_metrics_block "\
+ if(pm_candidate1 > pm_candidate2){\n\
+ new_path_metrics[" int2str(i-1) "] = pm_candidate1;\n\
+ trans_table[sample_nr][" int2str(i-1) "] = -1.0;\n\
+ }\n\
+ else{\n\
+ new_path_metrics[" int2str(i-1) "] = pm_candidate2;\n\
+ trans_table[sample_nr][" int2str(i-1) "] = 1.0;\n\
+ }\n"];
+ end
+ path_metrics_block=[path_metrics_block print_path_metrics];
+ %change new metrics into old metrics
+ path_metrics_block=[path_metrics_block " tmp=old_path_metrics;\n"];
+ path_metrics_block=[path_metrics_block " old_path_metrics=new_path_metrics;\n"];
+ path_metrics_block=[path_metrics_block " new_path_metrics=tmp;\n"];
+
+ path_metrics_block=[path_metrics_block "\n sample_nr++;\n"];
+
+path_metrics_block=[path_metrics_block " }\n\n"];
+
+
+
+find_best_stop_comment="\
+/*\n\
+* Find the best from the stop states by comparing their path metrics.\n\
+* Not every stop state is always possible, so we are searching in\n\
+* a subset of them.\n\
+*/\n";
+
+find_best_stop=[ " unsigned int best_stop_state;\n"];
+find_best_stop=[ find_best_stop " float stop_state_metric, max_stop_state_metric;\n" ];
+find_best_stop=[ find_best_stop " best_stop_state = stop_states[0];\n"];
+find_best_stop=[ find_best_stop " max_stop_state_metric = old_path_metrics[best_stop_state];\n"];
+find_best_stop=[ find_best_stop " for(i=1; i< stops_num; i++){\n"];
+find_best_stop=[ find_best_stop " stop_state_metric = old_path_metrics[stop_states[i]];\n"];
+find_best_stop=[ find_best_stop " if(stop_state_metric > max_stop_state_metric){\n"];
+find_best_stop=[ find_best_stop " max_stop_state_metric = stop_state_metric;\n"];
+find_best_stop=[ find_best_stop " best_stop_state = stop_states[i];\n"];
+find_best_stop=[ find_best_stop " }\n"];
+find_best_stop=[ find_best_stop " }\n\n"];
+
+
+
+parity_table_comment="\
+/*\n\
+* This table was generated with hope that it gives a litle speedup during\n\
+* traceback stage. \n\
+* Received bit is related to the number of state in the trellis.\n\
+* I've numbered states so their parity (number of ones) is related\n\
+* to a received bit. \n\
+*/\n";
+
+parity_table=[" static const unsigned int parity_table[PATHS_NUM] = { "];
+for i=1:PATHS_NUM/4,
+ parity_table=[ parity_table "0, 1, 1, 0, " ]; %int2str(even_parity(i-1))
+end
+parity_table=[ parity_table " };\n\n" ];
+
+
+
+prev_table_comment="\
+/*\n\
+* Table of previous states in the trellis diagram.\n\
+* For GMSK modulation every state has two previous states.\n\
+* Example:\n\
+* previous_state_nr1 = prev_table[current_state_nr][0]\n\
+* previous_state_nr2 = prev_table[current_state_nr][1]\n\
+*/\n";
+
+prev=ceil(PREVIOUS(1:2:2**(Lh+1),:)/2);
+prev_table=[" static const unsigned int prev_table[PATHS_NUM][2] = { "];
+for i=1:PATHS_NUM,
+ prev_table=[ prev_table "{" int2str(prev(i,1)-1) "," int2str(prev(i,2)-1) "}, " ];
+end
+prev_table=[ prev_table " };\n\n" ];
+
+
+
+traceback_comment="\
+/*\n\
+* Traceback and differential decoding of received sequence.\n\
+* Decisions stored in trans_table are used to restore best path in the trellis.\n\
+*/\n";
+
+traceback = [ " sample_nr=samples_num;\n"];
+traceback = [traceback " unsigned int state_nr=best_stop_state;\n"];
+traceback = [traceback " unsigned int decision;\n"];
+traceback = [traceback " bool out_bit=0;\n\n"];
+traceback = [traceback " while(sample_nr>0){\n" ];
+traceback = [traceback " sample_nr--;\n" ];
+traceback = [traceback " decision = (trans_table[sample_nr][state_nr]>0);\n\n" ];
+
+traceback = [traceback " if(decision != out_bit)\n"];
+traceback = [traceback " output[sample_nr]=-trans_table[sample_nr][state_nr];\n" ];
+traceback = [traceback " else\n" ];
+traceback = [traceback " output[sample_nr]=trans_table[sample_nr][state_nr];\n\n" ];
+
+traceback = [traceback " out_bit = out_bit ^ real_imag ^ parity_table[state_nr];\n" ];
+traceback = [traceback " state_nr = prev_table[state_nr][decision];\n" ];
+traceback = [traceback " real_imag = !real_imag;\n"];
+traceback = [traceback " }\n" ];
+
+
+
+end_of_viterbi_detector = [ "}\n" ];
+
+viterbi_detector=[function_interface_comment \
+ beginning \
+ start_point_comment start_point \
+ increment_comment increment_block \
+ path_metrics_comment print_matrix_type path_metrics_block \
+ find_best_stop_comment find_best_stop \
+ parity_table_comment parity_table \
+ prev_table_comment prev_table \
+ traceback_comment traceback \
+ end_of_viterbi_detector];
+
+
personal git repositories of Harald Welte. Your mileage may vary