[summary of the invention]
The invention provides a kind of magnetic card coding/decoding method, can effectively improve the accuracy of reading data on magnetic card.
A magnetic card coding/decoding method,
A1, the pwm value of level signal corresponding to magnetic signal pulse is stored successively;
A2, using the pwm value of the precedence bits of magnetic card 0 correspondence as initial baseline pulsewidth, and give current benchmark pulsewidth by initial baseline pulsewidth assignment, by current benchmark pulsewidth as differentiating the benchmark of pwm value corresponding bit 0 stored or the benchmark of the subluxation of bit 1;
A3, with current benchmark pulsewidth successively to storage pwm value differentiate, if be judged to other current pwm value corresponding bit 0, current benchmark pulsewidth is updated to the weighting of previous benchmark pulsewidth and current pwm value, and next pwm value is differentiated;
Wherein, bit 1 consists of two continuous pulses, and bit 0 consists of a pulse.
Adopt dynamic current benchmark pulsewidth as the benchmark of differentiating bit 0 and bit 1, effectively reduced the probability of the reading out data mistake causing because magnetic card translational speed is inhomogeneous, the pulsewidth that adopts bit 0 correspondence is the twice left and right of the pulsewidth of bit 1 correspondence, and the wherein claim using the pulsewidth of bit 0 correspondence as current benchmark pulsewidth can make current benchmark pulsewidth more accurate.
Preferably, in steps A 2, after the pwm value of the precedence bits of at least two 0 correspondence is averaged as described initial baseline pulsewidth.
Employing averages rear as initial baseline pulsewidth to precedence bits 0, reduced because the probability that extremely discriminating data is made mistakes appears in the corresponding pulsewidth of certain bit 0, makes initial baseline pulsewidth more accurate.
Preferably, in steps A 3, if current pwm value is greater than doubly current benchmark pulsewidth of k1, be less than doubly current benchmark pulsewidth of k2, wherein, 0<k1<k2<1, carries out following steps:
If the previous pwm value of B1 and a rear pwm value be corresponding bit 0 all, current pwm value is differentiated for corresponding bit 0;
If the rear pwm value corresponding bit 0 of B2, and the first two pwm value corresponding bit 1 altogether, differentiate current pwm value for corresponding bit 0;
If the previous pwm value corresponding bit 0 of B3, and latter two pwm value corresponding bit 1 altogether, differentiate current pwm value for corresponding bit 0;
If the subluxation of the previous pwm value corresponding bit 1 of B4, and a rear pwm value corresponding bit 0, differentiate current pwm value and previous pwm value for corresponding bit 1 altogether;
If the previous pwm value corresponding bit 0 of B5, and the subluxation of a rear pwm value corresponding bit 1, differentiate current pwm value and a rear pwm value for corresponding bit 1 altogether.
When occurring the situation of the data bit loss that magnetic bias causes, adopt technique scheme, can effectively the data bit of loss be recovered, and then improve the accuracy rate of magnetic card identification.
Preferably, if current pwm value does not belong to step B1 to the arbitrary situation in step B5, whether the number of bits that judgement has determined forms a byte, if the bit value of each data bit of described byte is carried out XOR and result and the exclusive or check position of described byte compare, and then differentiate the bit value that current pwm value is corresponding.
Preferably, in steps A 3, current benchmark pulsewidth is updated to 1/2nd of previous benchmark pulsewidth and adds 1/2nd of current pwm value.Preferably, if current pwm value >80% * current benchmark pulsewidth, current pwm value is differentiated for corresponding bit 0, if 20% * current benchmark pulsewidth < current pwm value <60% * current benchmark pulsewidth, current pwm value being differentiated is the subluxation of corresponding bit 1.The present invention also provides a kind of magnetic card reading device, comprises decoder module, and described decoder module is for carrying out the processing of magnetic-pulse signal decoding according to arbitrary described magnetic card coding/decoding method;
Also comprise induction amplifying circuit, bandwidth-limited circuit and threshold value shaping circuit;
Described induction amplifying circuit is for being converted to magnetic signal electric signal and amplifying;
Described bandwidth-limited circuit carries out bandpass filtering to the electric signal of induction amplifying circuit output;
Described threshold value shaping circuit carries out offering described decoder module after shaping to the electric signal of bandwidth-limited circuit output.
Preferably, described induction amplifying circuit comprises coil, the first resistance, the second resistance, the 3rd resistance, the first electric capacity, the second electric capacity, the first amplifier, one end of described coil is connected with the negative input end of described the first amplifier by the first resistance, the other end is connected with the positive input terminal of the first amplifier by described the second resistance, described first electric capacity one end is connected with the positive input terminal of described the first amplifier, the other end is connected with the common port of described the first resistance and coil, described coil is connected with reference voltage with the common port of the second resistance, after described the 3rd resistance and the second Capacitance parallel connection, be connected across negative input end and the output terminal of described the first amplifier.
Preferably, described bandwidth-limited circuit comprises the 3rd electric capacity, the 4th electric capacity, the 4th resistance, the 5th resistance, the 6th resistance, the 7th resistance, the second amplifier, the first diode and the second diode, the negative input end of described the second amplifier is connected with the output terminal of described the first amplifier with the 3rd electric capacity by the 4th resistance respectively, the positive input terminal of described the second amplifier is connected with reference voltage by the 5th resistance, after described the 4th electric capacity is in parallel with the 6th resistance, be connected across negative input end and the output terminal of the second amplifier, the negative electrode of the first diode is connected with the negative input end of described the second amplifier by the 7th resistance, anode is connected with the output terminal of described the second amplifier, the anode of described the second diode and negative electrode respectively with negative electrode and the anodic bonding of described the first diode,
Described threshold value shaping circuit comprises the 8th resistance, the 9th resistance, the tenth resistance and the 3rd amplifier, the negative input end of described the 3rd amplifier is connected with the output terminal of described the second amplifier by the 8th resistance, the positive input terminal of described the 3rd amplifier is connected with the output terminal of described the 3rd amplifier with reference voltage with the tenth resistance by the 9th resistance respectively, and the output terminal of described the 3rd amplifier is connected with described decoder module.
The present invention adopts the algorithm of dynamic current benchmark pulsewidth and fuzzy error correction, has greatly improved the accuracy rate that reads data on magnetic card.
[embodiment]
Below with reference to accompanying drawing, preferred embodiment of the present invention is described in further detail.
As shown in Figures 2 to 5, a kind of magnetic card reading device, comprises induction amplifying circuit, bandwidth-limited circuit, threshold value shaping circuit and decoder module;
Described induction amplifying circuit is for being converted to magnetic signal electric signal and amplifying;
Described bandwidth-limited circuit carries out bandpass filtering to the electric signal of induction amplifying circuit output;
Described threshold value shaping circuit carries out shaping to the electric signal of bandpass filtering filtering circuit output;
Described decoder module is connected with described threshold value shaping circuit, for being implemented as follows magnetic card coding/decoding method, as shown in Figure 2:
S001, the pwm value of level signal corresponding to magnetic signal pulse is stored successively;
S002, using the pwm value of the precedence bits of magnetic card 0 correspondence as initial baseline pulsewidth, by current benchmark pulsewidth as the benchmark of differentiating the pwm value corresponding bit 0 of storage or the subluxation of bit 1;
S003, with current benchmark pulsewidth successively to storage pwm value differentiate, if be judged to other current pwm value corresponding bit 0, current benchmark pulsewidth is updated to the weighting of previous benchmark pulsewidth and current pwm value, and next pwm value is differentiated;
Wherein, bit 1 consists of two continuous pulses, and bit 0 consists of a pulse.
Preferably, as shown in Figure 4, described induction amplifying circuit comprises coil L, the first resistance R 1, the second resistance R 2, the 3rd resistance R 3, the first capacitor C 1, the second capacitor C 2, the first amplifier U1, one end of described coil L is connected with the negative input end of described the first amplifier U1 by the first resistance R 1, the other end is connected with the positive input terminal of the first amplifier U1 by described the second resistance R 2, described first capacitor C 1 one end is connected with the positive input terminal of described the first amplifier U1, the other end is connected with the common port of coil L with described the first resistance R 1, described coil L is connected with reference voltage V REF with the common port of the second resistance R 2, after described the 3rd resistance R 3 and the second capacitor C 2 parallel connections, be connected across negative input end and the output terminal of described the first amplifier U1.
The magnetic head of magnetic card reading device can convert the magnetic signal of magnetic card record to electric signal, when magnetic card passes through magnetic head with certain speed, in magnetic head coil, can induce corresponding electric signal, the in the situation that of impedance matching, the signal that magnetic head induces, voltage is conventionally below 10mV, and some cards are even lower than 1mV, and this induction amplifying circuit also has low pass (20dB), rectifys equal function.
Preferably, as shown in Figure 5, described bandwidth-limited circuit comprises the 3rd capacitor C 3, the 4th capacitor C 4, the 4th resistance R 4, the 5th resistance R 5, the 6th resistance R 6, the 7th resistance R 7, the second amplifier U2, the first diode D1 and the second diode D2; Described the 3rd capacitor C 3 is connected with the negative input end of the second amplifier U2 by the 4th resistance R 4, and described the 3rd capacitor C 3 is connected with the output terminal of the first amplifier U1 by interface TP2; The positive input terminal of described the second amplifier U2 is connected with reference voltage V REF by the 5th resistance R 5, after described the 4th capacitor C 4 is in parallel with the 6th resistance R 6, be connected across negative input end and the output terminal of the second amplifier U2, the negative electrode of the first diode D1 is connected with the negative input end of described the second amplifier U2 by the 7th resistance R 7, anode is connected with the output terminal of described the second amplifier U2, the anode of described the second diode D2 and negative electrode respectively with negative electrode and the anodic bonding of described the first diode D1.T5, T8 are signal testing port.
Preferably, described shaping circuit comprises the 8th resistance R 8, the 9th resistance R 9, the tenth resistance R 10 and the 3rd amplifier U3, the negative input end of described the 3rd amplifier U3 is connected with the output terminal of described the second amplifier U2 by the 8th resistance R 8, the positive input terminal of described the 3rd amplifier U3 is connected with the output terminal of described the 3rd amplifier U3 with reference voltage with the tenth resistance R 10 by the 9th resistance R 9 respectively, the output terminal of described the 3rd amplifier U3 with by decoder module described in interface MIG2, be connected.
The magnetic head of magnetic card reading device is a sensitive element, has at work various undesired signals, thereby need suppress interference such as noises, and this bandwidth-limited circuit has the function of signal being carried out to linear amplification, shaping, and can filtering interfering and clutter.
Adjustable during the threshold value of this threshold value shaping circuit, signal is restored to after state easy to identify, and the signal of MIG2 interface enters timing microprocessor device counter controls mouth, by microprocessor (single-chip microcomputer), carries out software decode.
Below another embodiment more specifically of magnetic card coding/decoding method:
The counting of the timer by single-chip microcomputer is measured the pwm value of level signal corresponding to magnetic signal pulse, in counting process, each pwm value is directly stored in timer counter register, then reads the pwm value in timer counter register and is stored in successively magnetic signal pulse width count buffer district TK1TimeBuf[1024] (being called for short pulsewidth buffer zone).In preferred embodiment, because magnetic signal bandwidth is 5K, timer timing pulse frequency F is set
cshould be greater than 100K, that is to say a minimum counting of signal period 20 times, the size of pulsewidth buffer zone is 1Kbyte, each bytes store pulse width, i.e. a pwm value.For example: the clock frequency of single-chip microcomputer is 11.0592M, do 64 frequency divisions and can obtain F
cthe count frequency of=172.8K, timer counter register TCNT is the counter register of 16.
As shown in Figure 6, in pulsewidth buffer zone, read magnetic card magnetic track and start namely initial baseline position of one section of uniform magnetic recording signal precedence bits 0() corresponding one group of pulsewidth of beginning, carrying out arithmetic mean must the pulsewidth of falling initial baseline, by initial baseline pulsewidth assignment, give current benchmark pulsewidth TK1CLK, as the standard scale of initial differentiation pulsewidth corresponding bit 0 or 1.Preferably, the pwm value of choosing 20 precedence bits 0 correspondences carries out arithmetic mean and obtains initial baseline pulsewidth; Then receive start byte, reception data and end byte, reception check byte; In above-mentioned steps, the whether corresponding complete byte of pulsewidth TK1Time that needs judgement to read continuously, if not, continues from pulsewidth buffer zone TK1TimeBuf[1024] read pulsewidth.Whether the complete byte that judgement is obtained is data byte opening flag (start byte), if so, carries out byte count, and complete byte of later every reception, adds 1 by the byte number receiving; And judge whether this byte is data byte end mark (end byte), if so, obtains a check byte again, then all data bytes that get (is comprised to start byte, data byte and end byte.Do not comprise check byte) carry out LRC verification calculating, if result of calculation and check byte are inconsistent, the data that receive are carried out to error flag, otherwise, store data into buffer zone ByteBuff[] in.
Current benchmark pulsewidth TK1CLK is a dynamic benchmark pulsewidth, current benchmark pulsewidth TK1CLK=TK1CLK*50%+TK1Time*50%,, if what current pwm value TK1Time was corresponding is bit 0, current benchmark pulsewidth TK1CLK is updated to: 50% of previous current benchmark pulsewidth add current bit 0 correspondence current pwm value 50%, as shown in Figure 7.
The pwm value that magnetic signal is corresponding changes with magnetic card gait of march, and the inhomogeneous meeting of speed that magnetic card moves is fluctuateed magnetic signal frequency within the specific limits, if adopt fixed reference pulsewidth to carry out distinguishing signal, can cause magnetic card reading device to differentiate error in data.Because magnetic card translational speed can not suddenlyd change, velocity variations has continuity, i.e. the velocity correlation of current translational speed and previous moment, and current benchmark pulsewidth (dynamic benchmark pulsewidth) is associated with the pulsewidth at data-signal.Thereby the velocity variations that the size of current benchmark pulsewidth is advanced along with magnetic card and changing, is dynamic, to change data, can effectively reduce the inhomogeneous probability that causes discriminating data to be made mistakes because of magnetic card translational speed.
Preferably, to from pulsewidth buffer zone TK1TimeBuf[1024] the pulsewidth TK1Time that reads out, proceed as follows:
Calculate peak pulse duration RB=TK1Time/TK1CLK*100%;
Peak pulse duration RB is greater than to 80% data bit corresponding to pulsewidth and is considered as bit " 0 ".Peak pulse duration RB is considered as to " half " or " subluxation " of bit " 1 " between 20% to 60% data bit, continuous two " half " are configured to a complete bit " 1 ".Peak pulse duration RB is considered as to uncertain position between 60% to 80% data bit.
In another specific embodiment, for uncertain position, adopt fuzzy error correction algorithm further to determine, as shown in Figure 8:
If the previous pwm value of B1 and a rear pwm value be corresponding bit 0 all, current pwm value is differentiated for corresponding bit 0;
If the rear pwm value corresponding bit 0 of B2, and the first two pwm value corresponding bit 1 altogether, differentiate current pwm value for corresponding bit 0;
If the previous pwm value corresponding bit 0 of B3, and latter two pwm value corresponding bit 1, differentiate current pwm value for corresponding bit 0;
If the subluxation of the previous pwm value corresponding bit 1 of B4, and a rear pwm value corresponding bit 0, differentiate current pwm value and previous pwm value for corresponding bit 1 altogether;
If the previous pwm value corresponding bit 0 of B5, and the subluxation of a rear pwm value corresponding bit 1, differentiate current pwm value and a rear pwm value for corresponding bit 1 altogether.
If current pwm value does not belong to step B1 to the arbitrary situation in step B5, whether the number of bits that judgement has determined forms a byte, if, the bit value of each data bit of described byte is carried out XOR and result and the exclusive or check position of described byte compare, and then differentiate the bit value that current pwm value is corresponding.
Because magnetic bias causes the loss of data bit, can recover the data of losing by fuzzy algorithm, improve magnetic card signal identification rate.
Due to the start bit of the start byte after precedence bits 0 first be bit 1, so need to detect first bit 1 after precedence bits 0, to judge the beginning of start byte.The method of discrimination of start bit 1 is as shown in Figure 9:
1, from pulsewidth buffer zone, read pulse-width data TK1Time;
2, calculate the peak pulse duration RB that this pulse-width data TK1Time is corresponding;
3, judge that this pulse-width data TK1Time is corresponding bit 0, bit 1 or uncertain position;
If 4 uncertain positions are differentiated bit corresponding to this pulse-width data TK1Time by fuzzy error correction algorithm, if not uncertain position differentiate this pulse-width data TK1Time corresponding whether be the front subluxation of bit 1, if not the front subluxation of bit 1 carries out from 1 step again since 1, if the front subluxation of bit 1 continues to perform step 5;
5, continue to read next pulse-width data TK1Time;
6 and calculate corresponding peak pulse duration RB;
7, definite correspondence is subluxation or the uncertain position of bit 0 or bit 1, if corresponding bit is differentiated by fuzzy error correction algorithm again in uncertain position;
If the subluxation of 8 bits 1, receiving of whole start bit 1, re-executes from step 1 if not.
As shown in Figure 10,11 and 12, it is respectively the reception process flow diagram of start byte, ED byte, check byte, wherein need to differentiate forming the pulse-width data TK1Time corresponding to each bit of byte, before its discriminant approach, be described in detail, those skilled in the art, being expressly understood corresponding process in conjunction with Figure 10,11 and 12, do not repeat them here.