The coding/decoding method of a kind of FM0 and FM1 code and device
Technical field
The present invention relates to wireless communication technology, relate in particular to coding/decoding method and the device of a kind of FM0 and FM1 code in wireless communication technology.
Background technology
FM0 coding and FM1 coding all belong to coded biphase.The coding principle of FM0 is that any edge in half bit period represents Binary Zero, and does not have edge to represent binary one, and in addition, in the time of the beginning of each bit period, level all will carry out anti-phase.For example, the level of supposing preceding state is " 1 ", if this bit is Binary Zero, while carrying out so FM0 coding, first in the time that this bit period starts, make level state jump to " 1 " by " 1 ", then in the time of the half-bit cycle, make again level jump to " 1 " by " 1 ", if this bit is binary one, while carrying out so FM0 coding, first in the time that this bit period starts, make level state jump to " 1 " by " 1 ", and state " 1 " is lasted till to this bit period finishes; Suppose that preceding state is for " 1 ", if this bit is Binary Zero, while carrying out so FM0 coding, first in the time that this bit period starts, make level state jump to " 1 " by " 1 ", then in the time of the half-bit cycle, then make level jump to " 1 " by " 1 "; If this bit is binary one, while carrying out so FM0 coding, first, in the time that this bit period starts, makes level state jump to " 1 " by " 1 ", and state " 1 " is lasted till to this bit period finishes.The pattern schematic diagram of FM0 as shown in Figure 1.
The coding principle of FM1 is similar to FM0, and just any edge in half bit period represents binary one, and does not have edge to represent Binary Zero, and meanwhile, in the time of the beginning of each bit period, level is also all anti-phase.The pattern schematic diagram of FM1 as shown in Figure 2.
In FM0 and FM1 code, contain more level and jump, therefore contain abundant timing information, for receiver, position beat ratio is easier to rebuild, and is widely used in short-range radio communication.
At present, receiving system is in the time carrying out the decoding of FM0 and FM1, first according to known data rate, high level correspondence 1, low level correspondence 0, by the rule of corresponding 2 bits of a symbol period, the pulse train receiving is reverted to 0,1 bit stream, then this bit stream is sent into decoder module and recovered data 0 and data 1 according to the state transition diagram of coded system, a kind of for the state transition diagram of decoding as shown in Figure 3, wherein, in the time using FM0 coding rule, S
1=11, S
2=10, S
3=01, S
4=00.
Present inventor finds, because decode procedure is divided into two steps by prior art, in the time there is wrong or glitch that occur originally not having due to the impact of noise in the pulse train that receives, in the step of recovering bit stream, still can recover according to normal mode, in follow-up decoder module, could judge whether to occur wrong baseband signal according to whether meeting coding rule, as shown in Figure 4, there is mistake in the period 6, but or need to become bit stream by adding the pulse train full recovery of receiving, then in decode procedure, just can note abnormalities.Can bring certain time delay to decode procedure like this, the efficiency of impact communication, and in the application scenarios that has strict sequential to require the information receiving and transmitting between Receiver And Transmitter, such time delay meeting increases the mortality of communication.
Summary of the invention
The embodiment of the present invention provides coding/decoding method and the device of a kind of FM0 and FM1 code, to reduce the time delay of decoding, improves communication efficiency, reduces communication failure rate.
A coding/decoding method for FM0 code and FM1 code, comprising:
Obtain the width of current pulse to be decoded in pulse train;
Width taking half-bit Cycle Length as benchmark to described current pulse to be decoded quantizes, determine current acquired pulse duration quantized value to be decoded and; And
Described acquired pulse duration quantized value to be decoded and equal at 2 o'clock, determine the data of current bit according to described current pulse duration quantized value to be decoded and the pattern of decoding, and determine after by described acquired pulse duration quantized value to be decoded and be set to 0, described pattern comprises: FM0 code and FM1 code;
Described acquired pulse duration quantized value to be decoded and be greater than at 2 o'clock, finish decoding.
Further, describedly determine that according to described current pulse duration quantized value to be decoded and the pattern of decoding the data of current bit specifically comprise:
When described current pulse duration quantized value to be decoded is 1, and the pattern of decoding is while being FM0, and the data of determining this bit are 0;
When described current pulse duration quantized value to be decoded is 1, and the pattern of decoding is while being FM1, and the data of determining this bit are 1;
When described current pulse duration quantized value to be decoded is 2, and the pattern of decoding is while being FM0, and the data of determining this bit are 1;
When described current pulse duration quantized value to be decoded is 2, and the pattern of decoding is while being FM1, and the data of determining this bit are 0.
Preferably, in described acquisition pulse train, the width of current pulse to be decoded specifically comprises:
Determine the time that in pulse train, current decode pulses edge arrives;
The width of determining current decode pulses in pulse train is, the difference of the time of the time porch arrival previous with it that described current decode pulses edge arrives.
Further, described taking half-bit Cycle Length as benchmark, the width of described current pulse to be decoded is quantized after, also comprise:
Judge whether described current pulse duration quantized value to be decoded is greater than 2, and finish decoding when being in judged result.
Preferably, after described end decoding, also comprise: prompting user institute received pulse sequence variation.
The decoding device of corresponding a kind of FM0 code and FM1 code, comprising:
Be used for the unit of the width that obtains the current pulse to be decoded of pulse train;
For taking half-bit Cycle Length as benchmark, the width to described current pulse to be decoded quantizes, determine current acquired pulse duration quantized value to be decoded and unit;
For described acquired pulse duration quantized value to be decoded and equal at 2 o'clock, determine the data of current bit according to described current pulse duration quantized value to be decoded and the pattern of decoding, and determine after by described acquired pulse duration quantized value to be decoded and be set to 0 unit, described pattern comprises: FM0 code and FM1 code;
For described acquired pulse duration quantized value to be decoded and be greater than at 2 o'clock, finish decoding unit.
Further, the described unit for the width that obtains the current pulse to be decoded of pulse train specifically comprises:
The subelement of the time arriving for definite current decode pulses of pulse train edge;
For the width of determining the current decode pulses of pulse train be the subelement of the difference of the time that the time porch previous with it that described current decode pulses edge arrives arrives.
Further, in described device, also comprise:
For taking half-bit Cycle Length as benchmark, the width to described current pulse to be decoded judges after quantizing whether described current pulse duration quantized value to be decoded is greater than 2, and be to finish the subelement of decoding while being in judged result.
Preferably, described for described acquired pulse duration quantized value to be decoded and be greater than at 2 o'clock, the unit that finishes decoding is also for prompting user institute received pulse sequence variation.
The embodiment of the present invention provides coding/decoding method and the device of a kind of FM0 and FM1 code, by obtaining pulse duration and decoding according to different rule in FM0 and FM1 code, decode because received pulse sequence one side in one side can obtain pulse duration, instead of first full recovery becomes bit stream to carry out decoding again, so when pulse train occurs when abnormal, can find very soon and finish decoding, thereby reduce the time delay that rub-out signal is brought, improve communication efficiency, reduce communication failure rate.
Brief description of the drawings
Fig. 1 is the pattern schematic diagram of FM0 code in prior art;
Fig. 2 is the pattern schematic diagram of FM1 code in prior art;
Fig. 3 is the state transition diagram for decoding in prior art;
Fig. 4 is when the process that the notes abnormalities schematic diagram when abnormal appears in pulse train in prior art;
Fig. 5 is coding/decoding method flow chart in the embodiment of the present invention;
Fig. 6 is when the process that the notes abnormalities schematic diagram when abnormal appears in pulse train in the embodiment of the present invention.
Embodiment
The embodiment of the present invention provides coding/decoding method and the device of a kind of FM0 code and FM1 code, decode according to pulse duration, and in the time that not meeting coding rule, obtained pulse duration finishes immediately to decode, due in FM0 code and FM1 code under normal circumstances, the beginning of each bit period is anti-phase, so its pulse duration is all no more than 2, in the time decoding according to pulse duration, carry out owing to judging pulse duration and decoding simultaneously, so when pulse train occurs when abnormal, can find very soon and finish decoding, thereby reduce the time delay that rub-out signal is brought, improve communication efficiency, reduce communication failure rate.
As shown in Figure 5, the FM0 code that the embodiment of the present invention provides and the coding/decoding method of FM1 code comprise the steps:
The width of current pulse to be decoded in step S501, acquisition pulse train;
Step S502, width taking half-bit Cycle Length as benchmark to described current pulse to be decoded quantize, and determine current acquired pulse duration quantized value to be decoded and;
Step S503, judge current acquired pulse duration quantized value to be decoded and whether equal 2, if so, execution step S504, if not, execution step S505;
Step S504, according to current pulse duration quantized value to be decoded and the pattern of decoding, determine the data of current bit of decoding, and after determining by acquired pulse duration quantized value to be decoded and be set to 0, continue execution step S501;
If current pulse duration quantized value to be decoded is 1, and the pattern of decoding is FM0, and the data of determining this bit are 0; If current pulse duration quantized value to be decoded is 1, and the pattern of decoding is FM1, and the data of determining this bit are 1; If current pulse duration quantized value to be decoded is 2, and the pattern of decoding is FM0, and the data of determining this bit are 1; If current pulse duration quantized value to be decoded is 2, and the pattern of decoding is FM1, and the data of determining this bit are 0.
Step S505, judge current acquired pulse duration quantized value to be decoded and whether be greater than 2, if so, execution step S506, if not, execution step S501;
Step S506, end decoding.
In step S506, can further notify user, abnormal owing to receiving, decoding finishes.
Anti-phase owing to having carried out when the beginning of each bit period, and each acquired pulse duration quantized value to be decoded and equal at 2 o'clock, just carry out the decoding of current bit, simultaneously by acquired pulse duration quantized value to be decoded and zero clearing, therefore, under normal circumstances, acquired pulse duration quantized value to be decoded and can not be greater than 2, once occur acquired pulse duration quantized value to be decoded and be greater than 2 situation, the pulse train that just explanation receives occurs abnormal, stops immediately decoding.
In step S501, obtain the width of current pulse to be decoded in pulse train and can take following method:
Determine the time that in pulse train, current porch to be decoded arrives, and the width of current pulse to be decoded in pulse train is defined as to the difference of the time of advent of the current porch time of advent to be decoded and previous porch.
Because decoder is in receiving the rising edge and trailing edge of pulse at every turn, all can produce an interruption, therefore, can be directly by the time of interrupting for adjacent twice, calculate the time interval of twice interruption, and then obtain the width of pulse.
Further, due in the time encoding, beginning at each bit period has been carried out anti-phase, so the quantized value of the width of the current pulse to be decoded obtaining under normal circumstances must not can is greater than 2, width that so just can current pulse to be decoded at every turn obtaining pulse train and taking the half-bit cycle after benchmark quantizes, once judge, whether the width quantized value of the current pulse to be decoded that judgement obtains is greater than 2, if be greater than 2, the pulse train that explanation receives occurs abnormal, finishes immediately decoding.
The coding/decoding method with a concrete example, the embodiment of the present invention being provided below describes, as shown in Figure 6, for the FM0 pulse train that is 10100110 to initial data is decoded, as seen from the figure, in this pulse train, the 6th bit occurs abnormal in the time receiving.
When initial acquired pulse duration quantized value to be decoded and be 0, be less than 2, so continue to obtain the width of current pulse to be decoded in pulse train and quantize, the width quantized value of current pulse to be decoded is 1 bit period, now acquired pulse duration quantized value to be decoded and be 2, so directly carry out decoding, be translated into " 1 ", simultaneously by acquired pulse duration quantized value to be decoded and be set to 0;
Continue again to obtain the width of next pulse to be decoded, as shown in Figure 6, the width quantized value of next pulse to be decoded is 1, be less than 2, so continue to obtain the width of next pulse to be decoded, in sequence, the width quantized value of the 3rd pulse is 1, the width quantized value of the pulse to be decoded of once obtaining before adding, now, acquired pulse duration quantized value to be decoded and be 2, so carry out decoding, because the width quantized value of current pulse to be decoded is 1, so be translated into " 0 " according to coding rule, simultaneously by acquired pulse duration quantized value to be decoded and be set to 0,
Continue decoding according to above rule, can normally front four bits be decoded as to " 1010 ", in the time that decoding proceeds to the 5th bit, obtain the width of first pulse in the 5th bit period, its pulse duration quantized value is 1, continue to obtain the width of current pulse to be decoded, its quantized value is 2, now, acquired pulse duration quantized value to be decoded and be 3, be greater than 2, illustrate that pulse train occurs abnormal, can finish immediately decoding.
The embodiment of the present invention provides coding/decoding method and the device of a kind of FM0 and FM1 code, by obtaining pulse duration and according in FM0 and FM1 code, the different different rules of code value pulse duration are decoded, decode because received pulse sequence one side in one side can obtain pulse duration, instead of first full recovery becomes bit stream to carry out decoding again, so when pulse train occurs when abnormal, can find very soon and finish decoding, thereby reduce the time delay that rub-out signal is brought, improve communication efficiency, reduce communication failure rate.
Obviously, those skilled in the art can carry out various changes and modification and not depart from the spirit and scope of the present invention the embodiment of the present invention.Like this, if these amendments of the present invention and within modification belongs to the scope of the claims in the present invention and equivalent technologies thereof, the present invention is also intended to comprise these changes and modification interior.