A source coding method, device, apparatus and medium

By constructing a binary prefix code tree to finely control the branch node probability of Huffman coding, the problem that traditional Huffman coding cannot regulate bit stream distribution is solved, improving the transmission reliability and spectral efficiency of the communication system and simplifying the shaping process.

CN122179062APending Publication Date: 2026-06-09COMMUNICATION UNIVERSITY OF CHINA

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
COMMUNICATION UNIVERSITY OF CHINA
Filing Date
2026-04-23
Publication Date
2026-06-09

AI Technical Summary

Technical Problem

Traditional Huffman coding cannot control the distribution of binary symbols in the output bitstream, resulting in the output bitstream naturally not matching the target distribution requirements of the probabilistic shaping system. It must undergo secondary processing by a distribution matcher, increasing the complexity and efficiency loss of the communication system.

Method used

By constructing a binary prefix code tree using the Huffman algorithm through recursive node partitioning, the probability of branch nodes in the binary prefix code tree can be finely controlled, directly achieving binary distribution matching of the encoded output bit stream and simplifying the probability shaping process.

Benefits of technology

It achieves precise matching of the global occurrence probability of the encoded output bit stream, improves the transmission reliability and spectral efficiency of the communication system, reduces system complexity and latency, and is suitable for low-power and low-latency communication scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122179062A_ABST
    Figure CN122179062A_ABST
Patent Text Reader

Abstract

This application relates to a source coding method, apparatus, device, and medium. The method includes: obtaining the target bit probability and the source symbol probability of each source symbol; constructing a binary prefix code tree by recursively partitioning the Huffman algorithm based on the target bit probability and the source symbol probabilities; traversing the binary prefix code tree to obtain the binary prefix code of each source symbol, and constructing a Huffman codebook based on the binary prefix codes of each source symbol; and mapping the source symbol sequence to a compressed binary bit stream based on the Huffman codebook. This method enables probability shaping during source coding, thereby reducing efficiency losses.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of source coding, and in particular relates to a source coding method, device, apparatus and medium. Background Technology

[0002] As communication systems increasingly demand higher reliability, spectral efficiency, and power efficiency, traditional equal-probability bit transmission schemes can no longer meet the high-performance transmission requirements in complex channel environments. Probabilistic shaping technology has emerged in this context and has gradually become a core technology in modern communication systems. By adjusting the binary symbol distribution of the transmitted bit stream, probabilistic shaping technology matches the probability distribution of the channel input symbols to maximize channel capacity. This significantly improves channel capacity and transmission robustness without altering the system hardware architecture. Among these, Probabilistic Amplitude Shaping (PAS) has become the most widely used probabilistic shaping scheme in engineering applications due to its low implementation complexity and high adaptability.

[0003] In the existing technology system, the core implementation process of probability amplitude shaping is to perform secondary processing on the bit stream output by the source encoder through a distribution matcher. First, the non-equal probability bit stream output by the source encoder is converted into an equal probability sequence, and then the equal probability sequence is mapped into a shaped bit stream that conforms to the target probability distribution, thereby achieving the matching of bit stream distribution with channel characteristics.

[0004] Within the existing technological framework, traditional source coding algorithms, represented by Huffman coding, are designed with minimizing the average code length as their core focus. They prioritize compression efficiency above all else, completely neglecting the binary symbol distribution characteristics of the output bitstream. This prevents them from controlling the probability of "0" and "1" bits in the encoded output, resulting in a bitstream that inherently does not match the target distribution requirements of probabilistic shaping systems. A secondary processing step using a distribution matcher is necessary to complete the probabilistic shaping. The introduction of a distribution matcher not only significantly increases the implementation complexity at both the transmitting and receiving ends of the communication system but also inevitably leads to a loss of transmission efficiency. Even the most advanced distribution matching schemes in the industry, such as binary enumeration spherical shaping, suffer significant efficiency losses in short-block, long-length scenarios, largely offsetting the system performance gains brought by probabilistic shaping. Summary of the Invention

[0005] Therefore, it is necessary to provide a source coding method, device, apparatus, and medium that can perform probabilistic shaping in source coding to reduce efficiency loss, thereby addressing the aforementioned technical problems.

[0006] Firstly, this application provides a source coding method, including:

[0007] Obtain the target bit probability and the source symbol probability of each source symbol;

[0008] Based on the target bit probability and the probability of each source symbol, a binary prefix code tree is constructed by using the Huffman algorithm to partition recursively nodes.

[0009] Traverse the binary prefix code tree to obtain the binary prefix code of each source symbol, and construct the Huffman codebook based on the binary prefix code of each source symbol;

[0010] Based on the Huffman codebook, the source symbol sequence is mapped to a compressed binary bit stream.

[0011] In one embodiment, based on the target bit probability and the probability of each source symbol, a binary prefix code tree is constructed using a recursive node partitioning Huffman algorithm, including:

[0012] The source symbols are sorted in descending order of probability to generate an ordered source symbol sequence, and the root node of the binary prefix code tree is created based on the ordered source symbol sequence.

[0013] A binary prefix code tree is constructed by recursively iterating through subtrees based on an ordered source symbol sequence and the root node.

[0014] In one embodiment, a binary prefix code tree is constructed by recursively iterating through subtrees based on an ordered source symbol sequence and a root node, including:

[0015] The target ordered partition sequence is initialized based on the ordered source symbol sequence, and nodes are constructed based on the target subtree initialized based on the root node;

[0016] Step S1: Select source symbols from the target ordered partition sequence in descending order of source symbol probability. Set the ordered source symbol subsequence with the largest number of source symbols whose sum of source symbol probabilities is less than or equal to the target bit probability as the largest left subsequence of the target ordered partition sequence. Set the ordered source symbol subsequence with the smallest number of source symbols whose sum of source symbol probabilities is greater than the target bit probability as the smallest left subsequence of the target ordered partition sequence.

[0017] Step S2: The sum of the source symbol probabilities of the source symbols in the largest left subsequence is taken as the total probability of the largest left subsequence; the sum of the source symbol probabilities of the source symbols in the smallest left subsequence is taken as the total probability of the smallest left subsequence; the absolute value of the difference between the total probability of the largest left subsequence and the target bit probability is taken as the absolute selection error of the largest left subsequence; the absolute value of the difference between the total probability of the smallest left subsequence and the target bit probability is taken as the absolute selection error of the smallest left subsequence.

[0018] Step S3: The sequence with the smaller absolute selection error between the largest and smallest left subsequences is set as the optimal left subsequence of the target ordered partitioning sequence, and the optimal right subsequence of the target ordered partitioning sequence is constructed based on the source symbols in the target ordered partitioning sequence that are not assigned to the optimal left subsequence.

[0019] Step S4: Construct the root node of the left subtree of the target subtree construction node based on the optimal left subsequence, and construct the root node of the right subtree of the target subtree construction node based on the optimal right subsequence;

[0020] Using the optimal left subsequence as the target ordered partition sequence and the root node of the left subtree as the target subtree construction node, recursively iterate steps S1 to S4. Then, using the optimal right subsequence as the target ordered partition sequence and the root node of the right subtree as the target subtree construction node, recursively iterate steps S1 to S4 until the target ordered partition sequence contains only a single source symbol. Set the target subtree construction node as the leaf node of the binary prefix code tree corresponding to the source symbol, and complete the recursive iteration construction of the subtree to obtain the binary prefix code tree.

[0021] In one embodiment, the expressions for the total probability of the largest left subsequence and the total probability of the smallest left subsequence are:

[0022]

[0023]

[0024] In the formula, and These are the total probability of the largest left subsequence and the total probability of the smallest left subsequence, respectively. The ordered source symbol sequence is the first symbol in descending order of source symbol probability. The source symbol of the item, The ordered source symbol sequence is the first symbol in descending order of source symbol probability. The source symbol probability of the term. For the target bit probability, The total number of source symbols in the ordered source symbol sequence. It is the set of positive integers.

[0025] In one embodiment, the binary prefix code tree is traversed to obtain the binary prefix code of each source symbol, and a Huffman codebook is constructed based on the binary prefix codes of each source symbol, including:

[0026] Starting from the root node, traverse the source symbol by adding 0 to the binary prefix code each time a left branch is traversed, and add 1 to the binary prefix code of the source symbol each time a right branch is traversed.

[0027] When traversing to the leaf node corresponding to each source symbol, the binary prefix code of each source symbol is obtained;

[0028] The Huffman codebook is constructed based on the binary prefix codes of each source symbol.

[0029] Secondly, this application also provides a source coding apparatus, comprising:

[0030] The probability parameter acquisition module is used to obtain the target bit probability and the source symbol probability of each source symbol;

[0031] The prefix code tree construction module is used to construct a binary prefix code tree based on the target bit probability and the probability of each source symbol by using the Huffman algorithm with recursive node partitioning.

[0032] The prefix codebook construction module is used to traverse the binary prefix code tree, obtain the binary prefix code of each source symbol, and construct the Huffman codebook based on the binary prefix code of each source symbol.

[0033] The bitstream mapping module is used to map source symbol sequences into compressed binary bitstreams based on the Huffman codebook.

[0034] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the method as described in any of the first aspects of this application.

[0035] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method as described in any of the first aspects of this application.

[0036] The aforementioned source coding method, device, apparatus, and medium, by constructing a binary prefix code tree, establishes a direct mathematical correlation between the local partitioning decisions of each internal node and the global statistical characteristics of the final output bitstream. This enables fine-grained control over the left branch probabilities of all branch nodes in the binary prefix code tree. Consequently, the global occurrence probability of 0 bits in the encoded compressed binary bitstream highly matches the target bit probability, accurately controlling the binary distribution characteristics of the bitstream. This addresses the problem of traditional Huffman coding, which only minimizes the average code length as its sole optimization objective and cannot effectively control the binary distribution of the output bitstream. This approach addresses the inherent technical limitations of dynamic matching, improving the transmission reliability and spectral efficiency of communication systems. By deeply integrating source compression coding and bit probability shaping, data redundancy elimination and bit distribution shaping can be completed simultaneously within a single processing flow of source coding. This allows for deep coupling of the compression coding process and the bit probability control process, simplifying the overall processing flow of probability shaping, reducing the engineering complexity of communication systems, inherent transmission efficiency losses, hardware resource occupancy, and processing latency. Furthermore, it eliminates the significant efficiency loss of distributed matchers in short-block, long-term scenarios, enabling probability shaping technology to be more lightweight and adaptable to various low-power and low-latency communication application scenarios. Attached Figure Description

[0037] To more clearly illustrate the technical solutions in the embodiments or related technologies of this application, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0038] Figure 1 A flowchart illustrating a source coding method provided in one embodiment of this application. Figure 1 ;

[0039] Figure 2 A flowchart illustrating a source coding method provided in one embodiment of this application. Figure 2 ;

[0040] Figure 3 A schematic diagram of a binary prefix code tree provided in one embodiment of this application;

[0041] Figure 4 This is a schematic diagram of a source coding device provided in one embodiment of this application. Detailed Implementation

[0042] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0043] In one exemplary embodiment of this application, such as Figure 1 As shown, a source coding method is provided. This embodiment illustrates the application of this method to a source coding terminal. It is understood that this method can also be applied to a source coding server, and further to a source coding system including both a source coding terminal and a source coding server, and is implemented through the interaction between the source coding terminal and the source coding server. In this embodiment, the method includes the following steps:

[0044] Step S101: Obtain the target bit probability and the source symbol probability of each source symbol.

[0045] Schematic, the target bit probability can be used to control the target occurrence probability of bit '0' in a compressed binary bit stream, and the value range of the target bit probability can be an open interval between 0 and 1.

[0046] Optionally, the source coding terminal can perform normalization verification on the source symbol probabilities of all source symbols to ensure that the sum of the source symbol probabilities of all source symbols is 1.

[0047] Step S102: Based on the target bit probability and the probability of each source symbol, the binary prefix code tree is constructed using the Huffman algorithm with recursive node partitioning.

[0048] Specifically, the source coding terminal can use the target bit probability as a global control parameter, and use the source symbol probability of each source symbol as the basic data to execute the recursive node partitioning Huffman algorithm to construct a binary prefix code tree.

[0049] Indicatively, the core principle of the recursive node partitioning Huffman algorithm is very simple: by controlling the probability of '0' appearing at each local decision point (i.e., each node), we can precisely adjust the global probability of '0' in the final bitstream. For example, if the probability of a node choosing the left branch is... After several such decisions, the proportion of '0' in the entire bitstream will approach 100%. .

[0050] For example, the source coding terminal can sort all source symbols in the source symbol set according to their probability from largest to smallest, generating an ordered source symbol sequence. The source coding terminal can add a sequence length identifier to the generated ordered source symbol sequence; the value of the sequence length identifier can be equal to the total number of source symbols in the ordered source symbol sequence. Based on the generated ordered source symbol sequence, the source coding terminal can create the root node of a binary prefix code tree. The source coding terminal can mark the root node as an unprocessed internal node and initiate the subsequent recursive iterative construction process of the subtree, starting from the root node to complete the hierarchical construction of the entire binary prefix code tree.

[0051] Optionally, the root node of the binary prefix code tree is the top-level starting node of the coding tree, which covers the complete ordered sequence of source symbols. That is, the symbol set corresponding to the root node is the complete set of source symbols for this coding. The source coding terminal can bind the total probability of the corresponding symbol set to the created root node. The total probability of the symbol set corresponding to the root node can be the sum of the source symbol probabilities of all source symbols, that is, the normalized value of 1.

[0052] For example, when initiating the subtree recursive iterative construction process, the source coding terminal first initializes the target ordered partition sequence based on the ordered source symbol sequence, and simultaneously initializes the target subtree construction node based on the root node. In each round of recursive iteration, the source coding terminal can prioritize executing the recursion termination condition judgment operation to determine whether the current recursive iteration round needs to continue the partitioning process. The recursion termination condition can be that the current target ordered partition sequence contains only a single source symbol. When the recursion termination condition is triggered, the source coding terminal can set the current target subtree construction node as the leaf node of the binary prefix code tree corresponding to that single source symbol, and simultaneously bind the corresponding unique source symbol to that leaf node, ending the iteration process of the current recursive branch. When the recursion termination condition is not triggered, i.e., when the current target ordered partition sequence contains two or more source symbols, the source coding terminal can continue to execute the subsequent partitioning process, completing the symbol set partitioning and child node creation operations of the current node.

[0053] Furthermore, after confirming that the current recursive iteration has not triggered the recursion termination condition, the source coding terminal can sequentially select source symbols from the target ordered partition sequence in descending order of source symbol probability. The source coding terminal can set the ordered source symbol subsequence with the largest number of source symbols whose sum of source symbol probabilities is less than or equal to the target bit probability as the maximum left subsequence of the target ordered partition sequence; simultaneously, it can set the ordered source symbol subsequence with the smallest number of source symbols whose sum of source symbol probabilities is greater than the target bit probability as the minimum left subsequence of the target ordered partition sequence. The source coding terminal can use the sum of source symbol probabilities in the maximum left subsequence as the total probability of the maximum left subsequence; and simultaneously, it can use the sum of source symbol probabilities in the minimum left subsequence as the total probability of the minimum left subsequence. The source coding terminal can use the absolute value of the difference between the total probability of the maximum left subsequence and the target bit probability as the absolute selection error of the maximum left subsequence; similarly, it can use the absolute value of the difference between the total probability of the minimum left subsequence and the target bit probability as the absolute selection error of the minimum left subsequence. The source coding terminal can set the sequence with the smaller absolute selection error between the maximum and minimum left subsequences as the optimal left subsequence of the target ordered partition sequence. After determining the optimal left subsequence, the source coding terminal can construct the optimal right subsequence of the target ordered partition sequence based on the source symbols in the target ordered partition sequence that are not assigned to the optimal left subsequence. The source coding terminal can construct the left subtree root node of the target subtree construction node based on the optimal left subsequence, and simultaneously construct the right subtree root node of the target subtree construction node based on the optimal right subsequence. The source coding terminal can set the left and right subtree root nodes as the left and right child nodes of the target subtree construction node, respectively. After completing the creation of the child nodes of the current node, the source coding terminal can start the next round of recursive iteration. The source coding terminal can use the optimal left subsequence as the new target ordered partition sequence, and the root node of the left subtree as the new target subtree construction node. It recursively iterates through the above steps to complete the construction of all branches of the left subtree. Simultaneously, the source coding terminal can use the optimal right subsequence as the new target ordered partition sequence, and the root node of the right subtree as the new target subtree construction node. It recursively iterates through the above steps to complete the construction of all branches of the right subtree. The source coding terminal continues to execute the recursive iteration process until all recursive branches trigger the recursion termination condition, that is, all branches' target ordered partition sequences contain only a single source symbol, and all terminal nodes are set as leaf nodes of the corresponding source symbol. At this point, the entire recursive iteration construction process of the subtrees of the binary prefix code tree is complete, ultimately resulting in a structurally complete and clearly branched binary prefix code tree.

[0054] Optionally, the source coding terminal can establish a tree structure association between the current node and its child nodes, and agree that the left subtree branch is fixed with a mapping bit '0' and the right subtree branch is fixed with a mapping bit '1'.

[0055] Schematic: When the left branch probability of each internal node approaches the target bit probability, the global target bit occurrence probability will also approach the target bit probability in sync.

[0056] Step S103: Traverse the binary prefix code tree to obtain the binary prefix code of each source symbol, and construct the Huffman codebook based on the binary prefix code of each source symbol.

[0057] Optionally, the source encoding terminal can traverse the binary prefix code tree starting from the root node. During the traversal, each time a left branch is traversed, a bit '0' is added to the binary prefix code of the source symbol corresponding to the current traversal path; each time a right branch is traversed, a bit '1' is added to the binary prefix code of the source symbol corresponding to the current traversal path. During the traversal, the source encoding terminal maintains a dynamically updated binary sequence for each traversal path. This binary sequence is continuously appended with corresponding bit values ​​as the branch selection of the traversal path is performed, thereby recording the bit sequence corresponding to the complete path from the root node to the current node. When traversing to a leaf node corresponding to a source symbol, the source encoding terminal can stop traversing the current path and simultaneously determine the binary sequence maintained for the current path as the binary prefix code corresponding to the source symbol bound to that leaf node. The source encoding terminal can bind a corresponding binary prefix code to each source symbol and record the code length of the binary prefix code, i.e., the number of bits in the binary sequence. The source encoding terminal will complete a complete traversal of all leaf nodes of the binary prefix code tree, ensuring that each source symbol can obtain a unique binary prefix code.

[0058] Optionally, the source coding terminal may traverse the binary prefix code tree using either depth-first traversal or breadth-first traversal; no limitation is made here.

[0059] Optionally, after generating the binary prefix codes for all source symbols, the source coding terminal can construct a Huffman codebook based on the binary prefix codes of each source symbol. The codebook entries can include the source symbol identifier, the source symbol probability, and the binary prefix code. The source coding terminal can sort the codebook entries in descending order of source symbol probability.

[0060] Step S104: Map the source symbol sequence into a compressed binary bit stream according to the Huffman codebook.

[0061] For example, the source encoding terminal can sequentially read each source symbol in the source symbol sequence, and for each read source symbol, look up the corresponding binary prefix code in the Huffman codebook. The source encoding terminal can then append the binary prefix code corresponding to the source symbol to the end of the compressed binary bit stream, completing the encoding mapping operation for the current source symbol.

[0062] In the aforementioned source coding method, by constructing a binary prefix code tree, a direct mathematical correlation is established between the local partitioning decisions of each internal node and the global statistical characteristics of the final output bitstream. This enables fine-grained control over the left branch probabilities of all branch nodes in the binary prefix code tree. Consequently, the global occurrence probability of 0 bits in the encoded compressed binary bitstream closely matches the target bit probability, accurately controlling the binary distribution characteristics of the bitstream. This addresses the problem of traditional Huffman coding, which only minimizes the average code length as its sole optimization objective and cannot actively regulate the binary distribution of the output bitstream. Overcoming inherent technical limitations, this technology improves the transmission reliability and spectral efficiency of communication systems. By deeply integrating source compression coding and bit probability shaping, data redundancy elimination and bit distribution shaping can be completed simultaneously in a single processing flow of source coding. This allows for deep coupling of the compression coding process and the bit probability control process, simplifying the overall processing flow of probability shaping, reducing the engineering complexity of communication systems, inherent transmission efficiency loss, hardware resource utilization, and processing latency. Furthermore, it eliminates the significant efficiency loss of the distributed matcher in short-block, long-term scenarios, enabling probability shaping technology to be more lightweight and adaptable to various low-power and low-latency communication application scenarios.

[0063] In an optional embodiment of this application, please refer to Figure 1 and Figure 2 Step S102, based on the target bit probability and the probability of each source symbol, constructs a binary prefix code tree using the Huffman algorithm with recursive node partitioning, which may include:

[0064] Step S202: Sort the source symbols according to the probability of the source symbols from largest to smallest to generate an ordered source symbol sequence, and create the root node of the binary prefix code tree based on the ordered source symbol sequence.

[0065] For example, the source coding terminal can sort the source symbols in descending order according to their probability values. During the sorting process, the source coding terminal can perform a secondary sorting of source symbols with the same probability value according to the pre-assigned symbol identifier numbering order. The source coding terminal can then encapsulate all the source symbols that have been sorted in descending order into an ordered sequence of source symbols. The source coding terminal can assign a corresponding sequence position index to each source symbol in the ordered sequence of source symbols, and the sequence position index can be sequentially increased from the starting position according to the order of the source symbols.

[0066] Specifically, the source coding terminal can recursively construct a subtree based on an ordered source symbol sequence and the root node to obtain a binary prefix code tree.

[0067] In an optional embodiment of this application, please refer to Figure 2 The binary prefix code tree is constructed by recursively iterating through subtrees based on an ordered source symbol sequence and the root node. This can include:

[0068] Step S203: Initialize the target ordered partition sequence based on the ordered source symbol sequence, and construct nodes based on the root node to initialize the target subtree.

[0069] Schematic, the target ordered partition sequence can be the source symbol sequence that needs to be partitioned in the current recursive iteration round, and the initial value of the target ordered partition sequence can be the complete ordered source symbol sequence. The target subtree construction node can be the tree node that needs to complete the subtree construction in the current recursive iteration round, and the initial value of the target subtree construction node can be the root node of the binary prefix code tree.

[0070] Step S1: Select source symbols from the target ordered partition sequence in descending order of source symbol probability. Set the ordered source symbol subsequence with the largest sum of source symbol probabilities less than or equal to the target bit probability and the largest total number of source symbols as the largest left subsequence of the target ordered partition sequence. Set the ordered source symbol subsequence with the smallest sum of source symbol probabilities greater than the target bit probability and the smallest total number of source symbols as the smallest left subsequence of the target ordered partition sequence.

[0071] Step S2: The sum of the source symbol probabilities of the source symbols in the largest left subsequence is taken as the total probability of the largest left subsequence; the sum of the source symbol probabilities of the source symbols in the smallest left subsequence is taken as the total probability of the smallest left subsequence; the absolute value of the difference between the total probability of the largest left subsequence and the target bit probability is taken as the absolute selection error of the largest left subsequence; and the absolute value of the difference between the total probability of the smallest left subsequence and the target bit probability is taken as the absolute selection error of the smallest left subsequence.

[0072] Step S3: Select the sequence with the smaller absolute selection error between the largest and smallest left subsequences as the optimal left subsequence of the target ordered partition sequence, and construct the optimal right subsequence of the target ordered partition sequence based on the source symbols in the target ordered partition sequence that are not assigned to the optimal left subsequence.

[0073] For example, when the absolute error of selecting the largest left subsequence is less than the absolute error of selecting the smallest left subsequence, the source coding terminal can set the largest left subsequence as the optimal left subsequence; when the absolute error of selecting the smallest left subsequence is less than the absolute error of selecting the largest left subsequence, the source coding terminal can set the smallest left subsequence as the optimal left subsequence; when the absolute errors of selecting the two candidate partitions are equal, the source coding terminal can select one of the largest left subsequence and the smallest left subsequence as the optimal left subsequence according to a preset fixed rule.

[0074] Step S4: Construct the left subtree root node of the target subtree construction node based on the optimal left subsequence, and construct the right subtree root node of the target subtree construction node based on the optimal right subsequence.

[0075] Step S204: Using the optimal left subsequence as the target ordered partition sequence and the root node of the left subtree as the target subtree construction node, recursively iterate steps S1 to S4. Then, using the optimal right subsequence as the target ordered partition sequence and the root node of the right subtree as the target subtree construction node, recursively iterate steps S1 to S4 until the target ordered partition sequence contains only a single source symbol. Set the target subtree construction node as the leaf node of the binary prefix code tree corresponding to the source symbol, complete the recursive iteration construction of the subtree, and construct the binary prefix code tree.

[0076] In an optional embodiment of this application, the expressions for the total probability of the maximum left subsequence and the total probability of the minimum left subsequence can be:

[0077]

[0078]

[0079] In the formula, and These are the total probability of the largest left subsequence and the total probability of the smallest left subsequence, respectively. The ordered source symbol sequence is the first symbol in descending order of source symbol probability. The source symbol of the item, The ordered source symbol sequence is the first symbol in descending order of source symbol probability. The source symbol probability of the term. For the target bit probability, The total number of source symbols in the ordered source symbol sequence. It is the set of positive integers. The ordered source symbol sequence is the first symbol in descending order of source symbol probability. The source symbol probability of the term. The ordered source symbol sequence is the first symbol in descending order of source symbol probability. The source symbol probability of the term.

[0080] In an optional embodiment of this application, please refer to Figure 1 and Figure 2 Step S103 involves traversing the binary prefix code tree to obtain the binary prefix code of each source symbol, and constructing a Huffman codebook based on the binary prefix codes of each source symbol. This may include:

[0081] Step S205: Start traversing from the root node. Each time a left branch is traversed, add 0 to the binary prefix code of the source symbol. Each time a right branch is traversed, add 1 to the binary prefix code of the source symbol.

[0082] Step S206: When traversing to the leaf node corresponding to each source symbol, the binary prefix code of each source symbol is obtained.

[0083] Step S207: Construct the Huffman codebook based on the binary prefix codes of each source symbol.

[0084] In one exemplary embodiment of this application, such as Figure 2 As shown, a source coding method is provided, which may include:

[0085] Step S201: Obtain the target bit probability and the source symbol probability of each source symbol.

[0086] Step S202: Sort the source symbols according to the probability of the source symbols from largest to smallest to generate an ordered source symbol sequence, and create the root node of the binary prefix code tree based on the ordered source symbol sequence.

[0087] Step S203: Initialize the target ordered partition sequence based on the ordered source symbol sequence, and construct nodes based on the root node to initialize the target subtree.

[0088] Step S1: Select source symbols from the target ordered partition sequence in descending order of source symbol probability. Set the ordered source symbol subsequence with the largest sum of source symbol probabilities less than or equal to the target bit probability and the largest total number of source symbols as the largest left subsequence of the target ordered partition sequence. Set the ordered source symbol subsequence with the smallest sum of source symbol probabilities greater than the target bit probability and the smallest total number of source symbols as the smallest left subsequence of the target ordered partition sequence.

[0089] Step S2: The sum of the source symbol probabilities of the source symbols in the largest left subsequence is taken as the total probability of the largest left subsequence; the sum of the source symbol probabilities of the source symbols in the smallest left subsequence is taken as the total probability of the smallest left subsequence; the absolute value of the difference between the total probability of the largest left subsequence and the target bit probability is taken as the absolute selection error of the largest left subsequence; and the absolute value of the difference between the total probability of the smallest left subsequence and the target bit probability is taken as the absolute selection error of the smallest left subsequence.

[0090] Step S3: Select the sequence with the smaller absolute selection error between the largest and smallest left subsequences as the optimal left subsequence of the target ordered partition sequence, and construct the optimal right subsequence of the target ordered partition sequence based on the source symbols in the target ordered partition sequence that are not assigned to the optimal left subsequence.

[0091] Step S4: Construct the left subtree root node of the target subtree construction node based on the optimal left subsequence, and construct the right subtree root node of the target subtree construction node based on the optimal right subsequence.

[0092] Step S204: Using the optimal left subsequence as the target ordered partition sequence and the root node of the left subtree as the target subtree construction node, recursively iterate steps S1 to S4. Then, using the optimal right subsequence as the target ordered partition sequence and the root node of the right subtree as the target subtree construction node, recursively iterate steps S1 to S4 until the target ordered partition sequence contains only a single source symbol. Set the target subtree construction node as the leaf node of the binary prefix code tree corresponding to the source symbol, complete the recursive iteration construction of the subtree, and construct the binary prefix code tree.

[0093] Step S205: Start traversing from the root node. Each time a left branch is traversed, add 0 to the binary prefix code of the source symbol. Each time a right branch is traversed, add 1 to the binary prefix code of the source symbol.

[0094] Step S206: When traversing to the leaf node corresponding to each source symbol, the binary prefix code of each source symbol is obtained.

[0095] Step S207: Construct the Huffman codebook based on the binary prefix codes of each source symbol.

[0096] Step S208: Map the source symbol sequence into a compressed binary bit stream according to the Huffman codebook.

[0097] In the aforementioned source coding method, by obtaining the target bit probability and the source symbol probability of each source symbol, the source symbols are sorted in descending order of probability to generate an ordered sequence and the root node of the binary prefix code tree is created. Then, in a recursive iterative manner, the optimal left and right subsequences of each node's symbol set are divided using a strategy of dual-candidate partitioning and minimizing absolute error. A binary prefix code tree conforming to the prefix code rules is constructed from top to bottom. The binary prefix code corresponding to each source symbol is generated by traversing the code tree, and a Huffman codebook is constructed. Finally, the mapping from the source symbol sequence to the compressed binary bit stream is completed based on the codebook. This method can directly achieve precise control over the global occurrence probability of 0 bits in the output bit stream during the source coding stage, making the statistical distribution of the output bit stream highly consistent with the target bit probability, simplifying the overall process of probability shaping. At the same time, the generated code has strict unique translatability and can maintain a high lossless compression efficiency comparable to traditional Huffman coding. It effectively balances bit distribution control capability and data compression performance, and can adapt to source distributions with different characteristics and source symbol sets of different sizes.

[0098] Furthermore, in the aforementioned source coding method, by constructing a greedy optimal partition based on descending order of source symbol probabilities and a recursive iterative tree, the optimal partitioning decision for the symbol set can be completed at each node of the coding tree construction, minimizing the absolute deviation between the local partitioning result and the theoretical target value. Simultaneously, the average code length of the code can continuously approach the theoretical limit of the source entropy, maintaining a high compression efficiency highly similar to traditional Huffman coding. This avoids destroying the optimal prefix code characteristics of Huffman coding, improves compression efficiency and encoding / decoding stability, and ensures the core performance of data compression while completing bit distribution shaping. By employing top-down recursive iterative coding that adapts to various source distribution types, it can achieve full-scenario adaptation for source probability distributions with different degrees of skewness and source symbol sets of different sizes. It enables stable adaptation to various source scenarios, including uniform, moderately skewed, and highly skewed distributions. It can continuously improve bit probability control accuracy and coding compression efficiency as the number of source symbols increases. It supports flexible adjustment of target bit probability based on dynamic changes in channel characteristics, enabling dynamic control of the output bit stream distribution. This further reduces the algorithm's pre-requirements for source distribution characteristics and enhances the algorithm's engineering feasibility and multi-scenario generalization performance.

[0099] In one exemplary embodiment of this application, please refer to Figure 3 A source coding method is provided, which may include:

[0100] Schematic, when encoding discrete source symbols using prefix coding, the unique codeword corresponding to each source symbol is generated through a unique path from the root node to the corresponding leaf node in the binary prefix code tree. Each internal node of the binary prefix code tree corresponds to one binary decision operation. The source coding device can stipulate that the left branch of each internal node is fixedly mapped to binary bit '0', and the right branch is fixedly mapped to binary bit '1'. Based on this coding rule, in the final bitstream of the encoded output, the generation of all bits comes from the branch decisions of each internal node in the binary prefix code tree. Therefore, the global statistical characteristics of the final output bitstream can be comprehensively determined by the local partitioning decision results of all internal nodes in the binary prefix code tree.

[0101] For example, using the source symbol set Target bit probability The probability distribution of the source symbol is 0.8. Taking the example of [example], the source coding terminal can [use] the source symbol set [as an example]. Set the target ordered partition sequence corresponding to the root node. At this point... The source coding terminal can perform node partitioning operations on the target ordered partition sequence corresponding to the root node. The source coding terminal can select symbols from the ordered sequence in descending order of probability, ensuring that the sum of the probabilities of the selected symbols does not exceed 0.8 and that the total number of symbols is maximized, ultimately obtaining the largest left subsequence corresponding to the root node. Total probability of the largest left subsequence The absolute error of the selection of the maximum left subsequence corresponding to the root node The source coding terminal can select symbols from the ordered sequence in descending order of probability. The minimum left subsequence corresponding to the root node is obtained when the sum of the probabilities of the selected symbols exceeds 0.8 and the total number of symbols is minimized. The total probability of the smallest left subsequence The absolute error of selecting the minimum left subsequence corresponding to the root node Compare the absolute errors in the selection of the two candidate partitions. Therefore, the source coding terminal can choose the maximum left subsequence corresponding to the root node. The optimal left subsequence of the root node The source coding terminal can construct the optimal right subsequence corresponding to the root node from the remaining source symbols in the target ordered partition sequence that are not included in the optimal left subsequence. The source coding terminal can create the left subtree root node of the root node based on the optimal left subsequence of the root node, and create the right subtree root node of the root node based on the optimal right subsequence of the root node. Then, it can recursively call the left subtree root node and the right subtree root node of the root node based on the optimal left subsequence and the optimal right subsequence, respectively, to execute the subtree construction process.

[0102] Schematic: After the binary prefix code tree is constructed, the source coding device can start from the root node of the binary prefix code tree and traverse it using a depth-first traversal. During the traversal, it is agreed that: each time a left branch of an internal node is traversed, a bit '0' is added to the codeword of the current path; each time a right branch of an internal node is traversed, a bit '1' is added to the codeword of the current path. When the traversal reaches a leaf node, the complete bit sequence generated for the current path is used as the binary prefix code corresponding to the source symbol bound to that leaf node. Finally, after the traversal is completed, the source symbol... The corresponding binary prefix code can be '000', source symbol The corresponding binary prefix code can be '001', source symbol The corresponding binary prefix code can be '01', source symbol The corresponding binary prefix code can be '100', source symbol The corresponding binary prefix code can be '101', source symbol The corresponding binary prefix code can be '11000', source symbol The corresponding binary prefix code can be '11010', source symbol The corresponding binary prefix code can be '111'.

[0103] In the aforementioned source coding method, the actual probability of bit '0' appearing in the final output compressed binary bitstream is approximately 0.787, which closely matches the target bit probability of 0.8. The calculated average code length is 2.926 bits / symbol, and the source entropy is approximately 2.789 bits / symbol based on the source entropy calculation formula. The final coding efficiency is approximately 95.3%, which is highly close to the compression performance of traditional Huffman coding.

[0104] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.

[0105] Based on the same inventive concept, this application also provides a source coding apparatus for implementing the source coding method described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method; therefore, the specific limitations of one or more source coding apparatus embodiments provided below can be found in the limitations of the source coding method described above, and will not be repeated here.

[0106] In one exemplary embodiment, such as Figure 4 As shown, a source coding apparatus 300 is provided, comprising:

[0107] The probability parameter acquisition module 301 can be used to acquire the target bit probability and the source symbol probability of each source symbol.

[0108] The prefix code tree construction module 302 can be used to construct a binary prefix code tree by recursively dividing the Huffman algorithm based on the target bit probability and the probability of each source symbol.

[0109] The prefix codebook construction module 303 can be used to traverse the binary prefix code tree, obtain the binary prefix code of each source symbol, and construct the Huffman codebook based on the binary prefix code of each source symbol.

[0110] The bitstream mapping module 304 can be used to map a sequence of source symbols into a compressed binary bitstream based on a Huffman codebook.

[0111] In an optional embodiment of this application, the prefix code tree construction module 302 can also be used for:

[0112] The source symbols are sorted in descending order of probability to generate an ordered source symbol sequence, and the root node of the binary prefix code tree is created based on the ordered source symbol sequence.

[0113] A binary prefix code tree is constructed by recursively iterating through subtrees based on an ordered source symbol sequence and the root node.

[0114] In an optional embodiment of this application, the prefix code tree construction module 302 can also be used for:

[0115] The target ordered partition sequence is initialized based on the ordered source symbol sequence, and nodes are constructed based on the target subtree initialized based on the root node.

[0116] Step S1: Select source symbols from the target ordered partition sequence in descending order of source symbol probability. Set the ordered source symbol subsequence with the largest sum of source symbol probabilities less than or equal to the target bit probability and the largest total number of source symbols as the largest left subsequence of the target ordered partition sequence. Set the ordered source symbol subsequence with the smallest sum of source symbol probabilities greater than the target bit probability and the smallest total number of source symbols as the smallest left subsequence of the target ordered partition sequence.

[0117] Step S2: The sum of the source symbol probabilities of the source symbols in the largest left subsequence is taken as the total probability of the largest left subsequence; the sum of the source symbol probabilities of the source symbols in the smallest left subsequence is taken as the total probability of the smallest left subsequence; the absolute value of the difference between the total probability of the largest left subsequence and the target bit probability is taken as the absolute selection error of the largest left subsequence; and the absolute value of the difference between the total probability of the smallest left subsequence and the target bit probability is taken as the absolute selection error of the smallest left subsequence.

[0118] Step S3: Select the sequence with the smaller absolute selection error between the largest and smallest left subsequences as the optimal left subsequence of the target ordered partition sequence, and construct the optimal right subsequence of the target ordered partition sequence based on the source symbols in the target ordered partition sequence that are not assigned to the optimal left subsequence.

[0119] Step S4: Construct the left subtree root node of the target subtree construction node based on the optimal left subsequence, and construct the right subtree root node of the target subtree construction node based on the optimal right subsequence.

[0120] Using the optimal left subsequence as the target ordered partition sequence and the root node of the left subtree as the target subtree construction node, recursively iterate steps S1 to S4. Then, using the optimal right subsequence as the target ordered partition sequence and the root node of the right subtree as the target subtree construction node, recursively iterate steps S1 to S4 until the target ordered partition sequence contains only a single source symbol. Set the target subtree construction node as the leaf node of the binary prefix code tree corresponding to the source symbol, and complete the recursive iteration construction of the subtree to obtain the binary prefix code tree.

[0121] In an optional embodiment of this application, the prefix codebook construction module 303 can also be used for:

[0122] Starting from the root node, traverse the source symbol by adding 0 to the binary prefix code of the source symbol each time a left branch is traversed, and by adding 1 to the binary prefix code of the source symbol each time a right branch is traversed.

[0123] When traversing to the leaf node corresponding to each source symbol, the binary prefix code of each source symbol is obtained.

[0124] The Huffman codebook is constructed based on the binary prefix codes of each source symbol.

[0125] In one embodiment, a computer device is provided, including a memory and a processor, the memory storing a computer program, the processor executing the computer program to implement the steps of a source coding method as described above.

[0126] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps in the above method embodiments.

[0127] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The components described as separate parts may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this disclosure according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0128] The above-described embodiments are merely illustrative of several implementation methods of the embodiments of this application, and their descriptions are relatively specific and detailed. However, they should not be construed as limiting the scope of the patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the embodiments of this application, and these modifications and improvements all fall within the protection scope of the embodiments of this application.

Claims

1. A source coding method, characterized in that, The method includes: Obtain the target bit probability and the source symbol probability of each source symbol; Based on the target bit probability and the probability of each source symbol, a binary prefix code tree is constructed using the Huffman algorithm with recursive node partitioning. Traverse the binary prefix code tree to obtain the binary prefix code of each source symbol, and construct the Huffman codebook based on the binary prefix code of each source symbol; Based on the Huffman codebook, the source symbol sequence is mapped into a compressed binary bit stream.

2. The method according to claim 1, characterized in that, The step of constructing a binary prefix code tree by using a recursive node partitioning Huffman algorithm based on the target bit probability and the probabilities of each source symbol includes: The source symbols are sorted in descending order of probability to generate an ordered source symbol sequence, and the root node of the binary prefix code tree is created based on the ordered source symbol sequence. The binary prefix code tree is constructed by recursively iterating through the subtrees based on the ordered source symbol sequence and the root node.

3. The method according to claim 2, characterized in that, The recursive iteration of subtree construction based on the ordered source symbol sequence and the root node to construct the binary prefix code tree includes: The target ordered partition sequence is initialized based on the ordered source symbol sequence, and nodes are constructed based on the target subtree initialized based on the root node; Step S1: Select source symbols from the target ordered partition sequence in descending order of source symbol probability. Set the ordered source symbol subsequence with the largest sum of source symbol probabilities less than or equal to the target bit probability and the largest total number of source symbols as the largest left subsequence of the target ordered partition sequence. Set the ordered source symbol subsequence with the smallest sum of source symbol probabilities greater than the target bit probability and the smallest total number of source symbols as the smallest left subsequence of the target ordered partition sequence. Step S2: The sum of the source symbol probabilities of the source symbols in the largest left subsequence is taken as the total probability of the largest left subsequence; the sum of the source symbol probabilities of the source symbols in the smallest left subsequence is taken as the total probability of the smallest left subsequence; the absolute value of the difference between the total probability of the largest left subsequence and the target bit probability is taken as the selection absolute error of the largest left subsequence; the absolute value of the difference between the total probability of the smallest left subsequence and the target bit probability is taken as the selection absolute error of the smallest left subsequence. Step S3: The sequence with the smaller absolute selection error among the largest left subsequence and the smallest left subsequence is set as the optimal left subsequence of the target ordered partition sequence, and the optimal right subsequence of the target ordered partition sequence is constructed based on the source symbols in the target ordered partition sequence that are not assigned to the optimal left subsequence; Step S4: Construct the left subtree root node of the target subtree construction node based on the optimal left subsequence, and construct the right subtree root node of the target subtree construction node based on the optimal right subsequence; Using the optimal left subsequence as the target ordered partition sequence and the root node of the left subtree as the target subtree construction node, recursively iterate steps S1 to S4. Using the optimal right subsequence as the target ordered partition sequence and the root node of the right subtree as the target subtree construction node, recursively iterate steps S1 to S4 until the target ordered partition sequence contains only a single source symbol. Then, set the target subtree construction node as the leaf node of the binary prefix code tree corresponding to the source symbol, complete the recursive iteration construction of the subtree, and construct the binary prefix code tree.

4. The method according to claim 3, characterized in that, The expressions for the total probability of the largest left subsequence and the total probability of the smallest left subsequence are: In the formula, and These are the total probability of the largest left subsequence and the total probability of the smallest left subsequence, respectively. The ordered source symbol sequence is the first one in descending order of the source symbol probabilities. The source symbols mentioned in the item, The ordered source symbol sequence is the first one in descending order of the source symbol probabilities. The probability of the source symbol of the term. The target bit probability, The total number of source symbols in the ordered source symbol sequence. It is the set of positive integers.

5. The method according to any one of claims 3, characterized in that, The process of traversing the binary prefix code tree to obtain the binary prefix code of each source symbol, and constructing a Huffman codebook based on the binary prefix code of each source symbol, includes: Starting from the root node, traverse the source symbol by adding 0 to the binary prefix code of the source symbol each time a left branch is traversed, and add 1 to the binary prefix code of the source symbol each time a right branch is traversed; When traversing to the leaf node corresponding to each of the source symbols, the binary prefix code of each source symbol is obtained; The Huffman codebook is constructed based on the binary prefix codes of each of the aforementioned source symbols.

6. A source coding device, characterized in that, The device includes: The probability parameter acquisition module is used to obtain the target bit probability and the source symbol probability of each source symbol; The prefix code tree construction module is used to construct a binary prefix code tree by using the Huffman algorithm to partition the recursive nodes according to the target bit probability and the probability of each source symbol. The prefix codebook construction module is used to traverse the binary prefix code tree, obtain the binary prefix code of each source symbol, and construct the Huffman codebook based on the binary prefix code of each source symbol. The bitstream mapping module is used to map the source symbol sequence into a compressed binary bitstream based on the Huffman codebook.

7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the method of any one of claims 1 to 5.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 5.