CN104463057B - A kind of magnetic card coding/decoding method and device - Google Patents

A kind of magnetic card coding/decoding method and device Download PDF

Info

Publication number
CN104463057B
CN104463057B CN201410843802.9A CN201410843802A CN104463057B CN 104463057 B CN104463057 B CN 104463057B CN 201410843802 A CN201410843802 A CN 201410843802A CN 104463057 B CN104463057 B CN 104463057B
Authority
CN
China
Prior art keywords
comparison window
pulsewidth
sequence
converted
magnetic card
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201410843802.9A
Other languages
Chinese (zh)
Other versions
CN104463057A (en
Inventor
刘文灿
张乾伍
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fujian Landi Commercial Equipment Co Ltd
Original Assignee
Fujian Landi Commercial Equipment Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fujian Landi Commercial Equipment Co Ltd filed Critical Fujian Landi Commercial Equipment Co Ltd
Priority to CN201410843802.9A priority Critical patent/CN104463057B/en
Publication of CN104463057A publication Critical patent/CN104463057A/en
Application granted granted Critical
Publication of CN104463057B publication Critical patent/CN104463057B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Signal Processing For Digital Recording And Reproducing (AREA)

Abstract

The present invention discloses a kind of magnetic card coding/decoding method and device, and the magnetic card coding/decoding method comprises the following steps:S1, the analog waveform of swiping the card sampled is converted into by pulsewidth sequence using mobile comparison window peak detection;S2, pulsewidth sequence is converted into binary sequence code, 1;S3, binary sequence code is converted into by character string according to decoding standard;Wherein, in step S1:S102, current sampling point is judged whether in the present scope of comparison window, whether current sampling point is more than the current high threshold of comparison window, the window is moved up, if it is not, then moving down the window;If after comparison window is moved up and moving down, judge sampled point corresponding when comparison window is moved up as positive peak;If after comparison window is moved down and moving up, judge sampled point corresponding when comparison window is moved down as negative peak;The pulsewidth of current sampling point is recorded according to the positive peak or negative peak, the pulsewidth sequence of analog waveform is obtained.Real-time of the present invention is high, and noise immunity is strong.

Description

A kind of magnetic card coding/decoding method and device
Technical field
The present invention relates to decoding field, more particularly to a kind of magnetic card coding/decoding method and device.
Background technology
The soft decoding scheme of traditional magnetic card is that mainly have two classes:One class is to use magnetic card special chip, is known by special chip Do not swipe the card signal, logical data is then issued into MCU;Another kind of is to use some universal circuits, and magnetic card primary signal is amplified Shaping, is then converted into binary data by MCU to the soft decoding of data on magnetic card after shaping.
There is following technical problem in above-mentioned prior art:
1st, the hardware cost of amplification and rectification circuit or special magnetic card decoding chip is of a relatively high;
2nd, universal circuit is restricted to the speed of swiping the card of magnetic card, too fast or can all influence success rate of swiping the card slowly excessively, and MCU is low to the efficiency of the soft decoding of data on magnetic card, and poor real, anti-noise ability is low.
The content of the invention
The technical problems to be solved by the invention are:A kind of real-time performance height and the strong magnetic card decoding side of anti-noise ability are provided Method and device.
In order to solve the above-mentioned technical problem, the technical solution adopted by the present invention is:A kind of magnetic card coding/decoding method is provided, including Following steps:
S1, the analog waveform of swiping the card sampled is converted into by pulsewidth sequence using mobile comparison window peak detection;
S2, the pulsewidth sequence is converted into binary sequence code, wherein long pulsewidth is converted into logical zero, two continuous Short pulse duration is converted into logic 1;
S3, binary sequence code is converted into by character string according to decoding standard;
Wherein, step S1 is specifically included:
S101, the comparison window initial Low threshold lt and high threshold ht, the size delta of the comparison window is set to be ht-lt;
S102, current sampling point is judged whether in the present scope of comparison window, if it is not, S103 is then gone to step, if so, Then gather next sampled point and repeat step S102 is until end of swiping the card;
S103, judge current sampling point whether be more than current comparison window high threshold, if so, then moving up the window Mouthful, mobile distance is the high threshold of current sampling point-current comparison window, if it is not, the window is then moved down, mobile Distance is Low threshold-current sampling point of preceding comparison window;
S104, the analysis comparison window moving process, if moving down after comparison window is moved up and in succession, judgement is compared Corresponding sampled point is positive peak when window is moved up;If moving up after comparison window is moved down and in succession, judge under comparison window Corresponding sampled point is negative peak during shifting;
S105, the pulsewidth according to the positive peak or negative peak record current sampling point, the pulsewidth is two adjacent Width between peak value, gathers next sampled point and repeat step S102 is until last sampled point, obtains the arteries and veins of analog waveform Wide sequence.
In order to solve the above technical problems, another technical scheme that the present invention is provided is:
A kind of magnetic card decoding apparatus, including waveform converting unit, pulse width conversion unit and decoding unit;
The waveform converting unit is used to use mobile comparison window peak detection by the analog waveform of swiping the card sampled It is converted into pulsewidth sequence;
The pulse width conversion unit is used to the pulsewidth sequence being converted into binary sequence code, wherein long pulsewidth is converted into Logical zero, two continuous short pulse durations are converted into logic 1;
The decoding unit is used to binary sequence code is converted into character string according to decoding standard;
Wherein, the decoding unit includes setup module, the first judge module, the second judge module, analysis module and note Record module;
The setup module is used to set comparison window initial Low threshold lt and high threshold ht, the comparison window it is big Small delta is ht-lt;
First judge module is used to judge current sampling point whether in the present scope of comparison window, if it is not, then The second judge module is called, if so, then gathering next sampled point and repeating the first judge module until end of swiping the card;
Second judge module is used for the high threshold for judging whether current sampling point is more than current comparison window, if so, Then move up the window, mobile distance for current sampling point-current comparison window high threshold, if it is not, then to moving down The window is moved, mobile distance is Low threshold-current sampling point of preceding comparison window;
The analysis module is used to analyze the moving process of the comparison window, if under after comparison window is moved up and in succession Move, then judge sampled point corresponding when comparison window is moved up as positive peak;If moving up after comparison window is moved down and in succession, sentence Sampled point corresponding when comparison window is moved down is determined for negative peak;
The logging modle is used for the pulsewidth that current sampling point is recorded according to the positive peak or negative peak, and the pulsewidth is Width between two adjacent peak values, gathers next sampled point and lays equal stress on dynamic first judge module of polyphony until last is sampled Point, obtains the pulsewidth sequence of analog waveform.
The beneficial effects of the present invention are:It is different from magnetic card coding/decoding method hardware cost in the prior art high, universal circuit Speed of swiping the card to magnetic card is restricted, and MCU is low to the efficiency of the soft decoding of data on magnetic card, and poor real, anti-noise ability is low, the present invention A kind of magnetic card coding/decoding method is provided, collection be discrete time magnetic card analog waveform, and using mobile comparison window peak value inspection The analog waveform of swiping the card sampled is converted into pulsewidth sequence by survey method, so as to substantially reduce the calculating complexity for obtaining pulsewidth sequence Degree, hence it is evident that improve efficiency of the MCU to the soft decoding of data on magnetic card, this method real-time is good, and anti-noise ability is strong.
In addition, the present invention is to be followed by onto MCU ADC being sampled by magnetic head amplification, ADC is the module that MCU is carried, So largely solving the problem of hardware cost is higher.There are some MCU to carry difference ADC, it is possible to further not With amplification, it is directly connected on MCU difference ADC, further reduces hardware cost.
Brief description of the drawings
Fig. 1 be the present invention relates to magnetic card decoding detection circuit;
Fig. 2 is the flow chart of magnetic card coding/decoding method of the present invention;
Fig. 3 is the flow chart of mobile comparison window peak detection in the present invention;
Fig. 4 is the flow chart of an embodiment of the present invention;
Magnetic card analogue data is is converted into pulsewidth sequence by Fig. 5 in the present invention using mobile comparison window peak detection Schematic diagram;
Fig. 6 is the module frame chart of magnetic card decoding apparatus of the present invention.
Label declaration:
1st, swipe the card analogue data;2nd, comparison window Low threshold lt change curve;
3rd, comparison window high threshold ht change curve;10th, pulse width conversion unit;
20th, decoding unit;30th, waveform converting unit;31st, setup module;
32nd, the first judge module;33rd, the second judge module;34th, analysis module;
35th, logging modle.
Embodiment
To describe technology contents, the objects and the effects of the present invention in detail, below in conjunction with embodiment and coordinate attached Figure is explained.
The design of most critical of the present invention is:The pulsewidth sequence of analog waveform is obtained by mobile comparison window peak detection Row, it is positive peak to move down after comparison window is moved up and in succession corresponding sampled point, when comparison window is moved down after but it is successive on It is negative peak to move corresponding sampled point, substantially reduces the amount of calculation and computation complexity of conversion pulsewidth sequence, improves this The real-time and noise immunity of invention.
Fig. 1 Fig. 2 and Fig. 3 are refer to, a kind of magnetic card coding/decoding method comprises the following steps:
S1, the analog waveform of swiping the card sampled is converted into by pulsewidth sequence using mobile comparison window peak detection;
Analog waveform of swiping the card in step sl is enterprising by the difference ADC that magnetic head is connected into MCU by amplifying circuit Row sampling;
S2, the pulsewidth sequence is converted into binary sequence code, wherein long pulsewidth is converted into logical zero, two continuous Short pulse duration is converted into logic 1;
S3, binary sequence code is converted into by character string according to decoding standard;
Wherein, step S1 is specifically included:
S101, the comparison window initial Low threshold lt and high threshold ht, the size delta of the comparison window is set to be ht-lt;
S102, current sampling point is judged whether in the present scope of comparison window, if it is not, S103 is then gone to step, if so, Then gather next sampled point and repeat step S102 is until end of swiping the card;
S103, judge current sampling point whether be more than current comparison window high threshold, if so, then moving up the window Mouthful, mobile distance is the high threshold of current sampling point-current comparison window, if it is not, the window is then moved down, mobile Distance is Low threshold-current sampling point of preceding comparison window;The high threshold of comparison window=move up preceding comparison window after moving up High threshold values+move up distance, the low valve valve of comparison window after moving down=low valve valve of comparison window before moving down-moves down distance, I.e. comparison window is entirely moved up or moved down, the high threshold and Low threshold of comparison window synchronously increase or reduction when mobile;
S104, the analysis comparison window moving process, if moving down after comparison window is moved up and in succession, judgement is compared Corresponding sampled point is positive peak when window is moved up;If moving up after comparison window is moved down and in succession, judge under comparison window Corresponding sampled point is negative peak during shifting;
S105, the pulsewidth according to the positive peak or negative peak record current sampling point, the pulsewidth is two adjacent Width between peak value, gathers next sampled point and repeat step S102 is until last sampled point, obtains the arteries and veins of analog waveform Wide sequence.
Wherein, current sampling point position and the time span of previous peak value are more than 50ms, then judge end of swiping the card.
It was found from foregoing description, the beneficial effects of the present invention are:What is gathered is the magnetic card analog waveform of discrete time, and The analog waveform of swiping the card sampled is converted into by pulsewidth sequence using mobile comparison window peak detection, so as to substantially reduce The computation complexity of pulsewidth sequence is obtained, and sampled point one is sampled and can immediately treated, it is not necessary to before or after Sampled point is together calculated, and algorithmic procedure only has and simply compares and calculate, and ensure that just complete before next point sampling Into calculating.Other prior arts are required to preserve a number of sampled point, while the processing to sampled point may be considerably complicated, held The row time is longer, for adapt at a high speed swipe the card (0.8~1m/s), sample frequency highest can reach more than 100KBPS, if calculate compared with For complexity, then sampled point can be caused to lose, so as to be easily caused decoding failure.MCU is significantly improved to the soft decoding of data on magnetic card Efficiency, this method real-time is good, and anti-noise ability is strong.
The present invention is to be followed by onto MCU ADC being sampled by magnetic head amplification, and ADC is the module that MCU is carried, so Largely solve the problem of hardware cost is higher.There are some MCU to carry difference ADC, it is possible to further without putting Greatly, it is directly connected on MCU difference ADC, further reduces hardware cost.
Further, also comprise determining whether to detect brushing card data before step S1, if so, S1 is then gone to step, if It is no, then persistently judge whether to detect brushing card data.
Further, the binary sequence code is modified when the step S2 carries out binary sequence code, wrapped Include step:
S201, judge whether current pulsewidth sequence P (n-1), P (n), P (n+1) are LSL, and wherein S represents short pulse duration, L Long pulsewidth is represented, if it is not, then without amendment;If so, then analyzing the pulsewidth sequence P (n-1), P (n), P (n+1) and cycle T Relation, wherein, cycle T is that, in the cycle as obtained by calculating leading 0, n is integer more than or equal to 1;
If P (n-1) is less than P (n+1) and (P (n-1)+P (n))/T is less than 150%, the pulsewidth sequence LSL is repaiied Just into SSL;
If P (n-1) is more than P (n+1) and (P (n+1)+P (n))/T is less than 150%, the pulsewidth sequence LSL is repaiied Just into LSS;
Otherwise, the pulsewidth sequence LSL is modified to LLL;
S202, judge whether current pulse width sequence the continuous S of odd number occurs, if it is not, then without amendment, if so, then Analyze the continuous S of odd number pulsewidth;
If occur odd number (>=3) continuous short pulse duration, P (n-2m-2), P (n-2m-1), to P (n), P (n+1) common 2m+3 Individual pulsewidth, its arteries and veins is classified as sequence LSS (2m-1) SL, wherein S (2m-1) and indicates 2m-1 S, has more an isolated S, actual Several situations of LSS (2m-1) SS, SSS (2m-1) SL, LLS (2m-1) SL or LSS (2m-1) LL may be modified to.
If P (n)+P (n+1)<=P (n-2m-2)+P (n-2m-1), and (P (n)+P (n+1))/T is less than 150%, then corrects For LLS (2m-1) SS;
Otherwise, it is modified to LSS (2m-1) LL.
If P (n)+P (n+1)>P (n-2m-2)+P (n-2m-1), and (P (n-2m-2)+P (n-2m-1))/T is less than 150%, Then it is modified to SSS (2m-1) SL;
Otherwise it is modified to LLS (2m-1) SL.
Seen from the above description, it is modified and can correct in real time due to speed of swiping the card by the binary sequence code Not equal reason caused by pulsewidth sequence transcription error, improve binary sequence code conversion accuracy, so as to improve magnetic The noise immunity of card coding/decoding method.
According to ISO7811 standard, track data, logical zero is represented with a long pulsewidth, and logic 1 is with two short pulse duration tables Show, long pulsewidth here refers to the level signal of a cycle, short pulse duration refers to the level signal of half period.Track data by Leading 0+ real data+after lead 0 composition, leading 0 and after lead 0 and typically respectively have between 20~50.
In decoding, due to the difference for speed of swiping the card, it is impossible to be known a priori by T size, it is necessary to calculate T's by leading 0 Value.
Therefore, further, the average pulse that the pulsewidth sequence start bit starts continuous two or more leading 0 is calculated, It is track data pulsewidth T to take the average pulse.
Seen from the above description, by taking the average pulse to be that track data pulsewidth T can effectively solve speed of swiping the card The different interference to binary sequence code transfer admittance.
Because less comparison window is capable of the magnetic card signal of effective detection low amplitude, but believe for the magnetic card of high-amplitude Number anti-noise ability is very weak;Big comparison window has stronger anti-noise ability, but the magnetic card signal of low amplitude often can not recognized Come.
Further, to solve this problem, often find after a peak value, initial value be set to small comparison window, Then during swiping the card, according to the size of the intensity adjust automatically comparison window of magnetic card signal, so that low amplitude can be recognized Magnetic card signal, and can provide in stronger anti-noise ability, present embodiment be using the method for weighted moving average adjustment compare window Mouthful size, formula is:
The new old delta*7+abs of delta=(present peak value voltage-bias voltage)/3/8;
Wherein, abs represents to take absolute value.
Further, because resulting pulsewidth vessles length and preferable pulsewidth width have certain error, in step s 2, if Current pulse width is then converted to logical zero by current pulse width sequence P (n) pulsewidth within [0.75T, 1.50T], if current pulse width Current pulse width sequence P (n) and P (n+1) are then converted to logic 1 by sequence P (n) and P (n+1) in [0,0.75T].So as to Ensure that pulsewidth sequence can be accurately converted into binary sequence.
Another technical scheme that the present invention is provided is:
A kind of magnetic card decoding apparatus, including waveform converting unit 30, pulse width conversion unit 10 and decoding unit 20;
The waveform converting unit 30 is used to use mobile comparison window peak detection by the analog wave of swiping the card sampled Shape is converted into pulsewidth sequence;
The pulse width conversion unit 10 is used to the pulsewidth sequence being converted into binary sequence code, wherein long pulse width conversion Into logical zero, two continuous short pulse durations are converted into logic 1;
The decoding unit 20 is used to binary sequence code is converted into character string according to decoding standard;
Wherein, the decoding unit includes setup module 31, the first judge module 32, the second judge module 33, analysis mould Block 34 and logging modle 35;
The setup module 31 is used to set comparison window initial Low threshold lt and high threshold ht, the comparison window Size delta is ht-lt;
First judge module 32 is used to judge current sampling point whether in the present scope of comparison window, if it is not, The second judge module 33 is then called, if so, then gathering next sampled point and repeating the first judge module until end of swiping the card;
Second judge module 33 is used for the high threshold for judging whether current sampling point is more than current comparison window, if It is then to move up the window, mobile distance is the high threshold of current sampling point-current comparison window, if it is not, then downward The mobile window, mobile distance is Low threshold-current sampling point of preceding comparison window;
The analysis module 34 is used to analyze the moving process of the comparison window, if under after comparison window is moved up and in succession Move, then judge sampled point corresponding when comparison window is moved up as positive peak;If moving up after comparison window is moved down and in succession, sentence Sampled point corresponding when comparison window is moved down is determined for negative peak;
The logging modle 35 is used for the pulsewidth that current sampling point is recorded according to the positive peak or negative peak, the pulsewidth For the width between two adjacent peak values, gather next sampled point and lay equal stress on dynamic first judge module of polyphony until last is sampled Point, obtains the pulsewidth sequence of analog waveform.
It was found from foregoing description, the beneficial effects of the present invention are:What is gathered is the magnetic card analog waveform of discrete time, and The analog waveform of swiping the card sampled is converted into by pulsewidth sequence using mobile comparison window peak detection, so as to substantially reduce The computation complexity of pulsewidth sequence is obtained, and sampled point one is sampled and can immediately treated, it is not necessary to before or after Sampled point is together calculated, and algorithmic procedure only has and simply compares and calculate, and ensure that just complete before next point sampling Into calculating.Other prior arts are required to preserve a number of sampled point, while the processing to sampled point may be considerably complicated, held The row time is longer, for adapt at a high speed swipe the card (0.8~1m/s), sample frequency highest can reach more than 100KBPS, if calculate compared with For complexity, then sampled point can be caused to lose, so as to be easily caused decoding failure.MCU is significantly improved to the soft decoding of data on magnetic card Efficiency, this method real-time is good, and anti-noise ability is strong.
Fig. 4 is refer to, embodiments of the invention one are:A kind of magnetic card coding/decoding method, this method is using the hardware shown in Fig. 1 Circuit, simple in construction, this method comprises the following steps:
S100:Detect whether to swipe the card, if do not swiped the card, the step of constantly repeating S100, otherwise into S201. When not swiping the card, the magnitude of voltage sampled is always close to DC offset voltage (for convenience of describing, calling Vb in the following text);When swiping the card, sampling Value will have acute variation.When n magnitude of voltage of continuous sampling is all outside [Vl, Vh], it is believed that swipe the card beginning, wherein Vl<Vb, Vh >Vb, wherein n are general between 4 to 16.ADC is general all directly to set scope Trigger Function, in the stage, only samples Point is outside [Vl, Vh], and ability proactive notification MCU is processed, so that MCU is without reduction load during swiping the card.
Accuracy of detection of being swiped the card when n is smaller is high, but easily noise has been mistakenly considered to swipe the card;It is not easy erroneous judgement when n is big, but can Can cause at a high speed swipe the card identification less than.
Vl, Vh and Vb difference are general between 200mV~800mV, difference hour, and the magnetic card signal of low amplitude can be just General knowledge is other, but anti-noise ability is poor;When difference is big, anti-noise ability is strong, but the card of low amplitude may not brushed not come out.
S201:A sampled point is obtained every time, and the peakvalue's checking based on adaptive mobile comparison window is used at once Method does peakvalue's checking, if peak value, then into S202, otherwise into S203.
Referring to Fig. 5,1 to swipe the card analogue data in Fig. 5,2 be comparison window Low threshold lt change curve, and 3 is compare Window high threshold ht change curve, wherein, the specific embodiment party of the peak-value detection method of the adaptive mobile comparison window Method is as follows,
The 1st, initial comparison window Low threshold lt and high threshold ht and positive peak detection mark flag, comparison window are set Size delta be ht-lt.To support the signal of low amplitude normally to decode, initial delta values should not set too big, and one As be 150mV~300mV, ht=Vb+delta/2, lt=Vb+delta/2, what flag set represented currently to be detected is negative peak Value, is otherwise positive peak;
If the 2, sampled point is in window ranges, it is not necessarily peak value to illustrate sampled point, then into S203;
If the 3, sampled point is outside window ranges, divide following two situations:
If 1) sampled point is bigger than ht, comparison window is moved up, makes the value of ht=sampled points, lt=ht-delta, such as What fruit was now looked for is positive peak, and the sampled point is probably positive peak, and peak is updated into sampling point position, into S203; If what is looked for is negative peak, illustrate there is negative peak, into S202.
2) sampled point is smaller than lt, then moves comparison window, makes the value of lt=sampled points, ht=lt+delta.If now What is looked for is negative peak, and the sampled point is probably negative peak, and peak is updated into sampling point position, into S203;If looked for Be positive peak, illustrate there is positive peak, into S202.
Wherein, if comparison window move up after and move down in succession, judge sampled point corresponding when comparison window is moved up as Positive peak;If moving up after comparison window is moved down and in succession, judge sampled point corresponding when comparison window is moved down as negative peak;
S202:A peak value is often found, a pulsewidth is just calculated, records the pulsewidth, while updating comparison window Size, subsequently into S203.Pulsewidth sequence will calculate the basis of binary sequence as S300.
The computational methods of pulsewidth:Current peak position-previous peak (initial peak position is 0).
Small comparison window is capable of the magnetic card signal of effective detection low amplitude, but for the magnetic card signal anti-noise of high-amplitude Ability is very weak;Big comparison window has stronger anti-noise ability, but often identification does not come out the magnetic card signal of low amplitude.For solution Certainly this problem, initial value is set to small comparison window by this method, then during swiping the card, according to the strong of magnetic card signal The size of adjust automatically comparison window is spent, so that the magnetic card signal of low amplitude can be recognized, and stronger anti-noise ability can be provided.
The adjustment of comparison window has a variety of methods, but all too busy to get away associated with peak strength, and this method, which is used, to be added The size that the method for moving average adjusts comparison window is weighed, formula is as follows:
The new old delta*7+abs of delta=(present peak value voltage-bias voltage)/3/8
Wherein, abs represents to take absolute value.
Ht and lt needs are synchronous with new delta, if positive peak, update the new delta of lt=ht-, if negative peak, Update the new delta of ht=lt+.
S203:Current sampling point position and the distance of previous peak value are calculated, if greater than 50ms, it is believed that end of swiping the card, Into S300;Otherwise S201 is entered.
From Fig. 5 in " the height fiducial value of initial data and moving window " subgraph, the moving direction of moving window is reverse When, be detected by peak value presence, pulsewidth obtained after conversion, finally give as " pulsewidth and binary sequence " the pulsewidth sequence in subgraph Row, it is 000110100 that the pulsewidth sequence, which is converted into binary sequence,.
S300:End of swiping the card obtains pulsewidth sequence later, and pulsewidth sequence is converted into binary sequence.
According to ISO7811 standard, track data, logical zero is represented with a long pulsewidth, and logic 1 is with two short pulse duration tables Show, long pulsewidth here refers to the level signal of a cycle, short pulse duration refers to the level signal of half period.Track data by Leading 0+ real data+after lead 0 composition, leading 0 and after lead 0 and typically respectively have between 20~50.For convenience of description, the cycle Represented with T, pulsewidth sequence P1, P2 ..., Pn represent that Pn represents n-th of pulsewidth.
In decoding, due to the difference for speed of swiping the card, it is impossible to be known a priori by the size of cycle T, it is necessary to be calculated by leading 0 T value.
S301:Pulsewidth since P1 all should be leading 0, therefore each pulsewidth and T are close.Continuously take several pulsewidths (practical application typically takes 8~12, very little low precision, some too many cards without it is not enough it is leading 0), remove maximum and Minimum value, takes average as T size, wherein, cycle T is in the cycle as obtained by calculating leading 0, into S302.
S302:Next pulsewidth is taken, is compared with T, if long pulsewidth, explanation is still leading 0, S302 is repeated, if It is short pulse duration, explanation may find real data, into S303;
S303:Assuming that current short pulse duration is m-th of pulsewidth, if P (m+1) is also short pulse duration, first logic 1 is obtained, Illustrate to find real data, into S304, otherwise into S302;
S304:Next pulsewidth (being represented with P (n)) is taken, is contrasted with T, if within [0.75,1.50], being converted to and patrolling 0 is collected, S304 is repeated;If in [0,0.75], P (n+1) and T contrasted, all [0,0.75) in if, be converted into logic 1, weight Multiple S304, otherwise into S305;If not in the range of [0,150], conversion end, into S306;
S305:P (n) is short pulse duration, and P (n+1) and T is contrasted, if between [0.75,1.50], illustrating transforming mistakes, Finish and enter S304 after error correction;P (n+1) and T contrasts are more than 150%, conversion end, into S306.
For convenience of description error correction procedure, long pulsewidth is represented with L here, S represents short pulse duration.Such as, LSSL represents an arteries and veins Wide sequence is by a long pulsewidth, two short pulse durations, one long pulsewidth composition.
The situation of transforming mistakes is segmented into two major classes:
1) first kind, P (n-1), P (n), P (n+1) sequence are LSL (because being not in single short arteries and veins under normal circumstances It is wide), but should actually be converted into one of SSL, LSS, or LLL these three situations.
If P (n-1) is less than P (n+1) and (P (n-1)+P (n))/T is less than 150%, LSL is converted into SSL, Pn- 1 was converted into logical zero originally, deleted the logical zero, and P (n-1) is converted into logic 1 together with P (n), and P (n+1) is converted into logical zero, entered Enter S304;
If P (n-1) is more than P (n+1) and (P (n+1)+P (n))/T is less than 150%, LSL is converted into LSS, Pn Logic 1 is converted into Pn+1, into S304;
Otherwise, LSL is converted into LLL, Pn is converted into logical zero, and Pn+1 is also converted into logical zero, into S304;
2) Equations of The Second Kind, occur odd number (>=3) continuous short pulse duration, P (n-2m-2), P (n-2m-1) ... P (n), P (n+ 1) common 2m+3 pulsewidth, its arteries and veins is classified as sequence LSS (2m-1) SL, wherein S (2m-1) and represents 2m-1 S, odd number S occurs, i.e., An isolated S is had more, actual capabilities are converted into LSS (2m-1) SS, SSS (2m-1) SL, LLS (2m-1) SL or LSS (2m-1) Several situations of LL.
If P (n)+P (n+1)<=P (n-2m-2)+P (n-2m-1), and (P (n)+P (n+1))/T is less than 150%, then turns Change LLS (2m-1) SS, Pn, Pn+1 into and be converted into logic 1, into S304;
Otherwise LSS (2m-1) LL is converted into, P (n) is converted into logical zero, and P (n+1) is also converted into logical zero, into S304.
If P (n)+P (n+1)>P (n-2m-2)+P (n-2m-1), and (P (n-2m-2)+P (n-2m-1))/T is less than 150%, then it is converted into SSS (2m-1) SL, Pn-2m-2 and is converted into logical zero originally, is substituted for by P (n-2m-2), P (n-2m- 1) logic 1 is converted into, P (n+1) logical zero is converted into, into S304;
Otherwise LLS (2m-1) SL, originally P (n-2m-1) are converted into and is converted into logic 1 with P (n-2m), is replaced with by P (n- Logical zero 2m-1) is converted into, P (n+1) logical zero is converted into, into S304;
S306:Logic sequence will be obtained according to specification, such as the specifications of ISO 7811, JIS II specifications or other specifications, turned Change character string into.Preferably, using the specifications of ISO 7811.
In summary, the hardware that the magnetic card coding/decoding method that the present invention is provided is used is simple, and cost is low, and collection is discrete The magnetic card analog waveform of time, and the analog waveform of swiping the card sampled is converted into by arteries and veins using mobile comparison window peak detection Wide sequence, so as to substantially reduce the computation complexity for obtaining pulsewidth sequence, hence it is evident that improve MCU to the soft decoding of data on magnetic card Efficiency and real-time, and the present invention carries out two step amendments when pulse width conversion is into binary sequence, and this method has been effectively ensured Noise immunity and real-time.
Embodiments of the invention are the foregoing is only, are not intended to limit the scope of the invention, it is every to utilize this hair The equivalents that bright specification and accompanying drawing content are made, or the technical field of correlation is directly or indirectly used in, similarly include In the scope of patent protection of the present invention.

Claims (10)

1. a kind of magnetic card coding/decoding method, it is characterised in that comprise the following steps:
S1, the analog waveform of swiping the card sampled is converted into by pulsewidth sequence using mobile comparison window peak detection;
S2, the pulsewidth sequence is converted into binary sequence code, wherein long pulsewidth is converted into logical zero, two continuous short arteries and veins It is wide to be converted into logic 1;
S3, binary sequence code is converted into by character string according to decoding standard;
Wherein, step S1 is specifically included:
S101, setting comparison window initial Low threshold lt and high threshold ht, the size delta of the comparison window is ht-lt;
S102, current sampling point is judged whether in the present scope of comparison window, if it is not, S103 is then gone to step, if so, then adopting Collect next sampled point and repeat step S102 is until end of swiping the card;
S103, judge whether current sampling point is more than the high threshold of current comparison window, if so, then move up the window, Mobile distance is the high threshold of current sampling point-current comparison window, if it is not, then move down the window, it is mobile away from From Low threshold-current sampling point for current comparison window;
S104, the analysis comparison window moving process, if moving down after comparison window is moved up and in succession, judge comparison window Corresponding sampled point is positive peak when moving up;If moving up after comparison window is moved down and in succession, when judging that comparison window is moved down Corresponding sampled point is negative peak;
S105, the pulsewidth according to the positive peak or negative peak record current sampling point, the pulsewidth is two adjacent peak values Between width, gather next sampled point and repeat step S102 be until last sampled point, obtains the pulsewidth sequence of analog waveform Row.
2. magnetic card coding/decoding method according to claim 1, it is characterised in that the analog waveform of swiping the card in the step S1 is By the way that magnetic head is connected into what is sampled on MCU ADC by amplifying circuit.
3. magnetic card coding/decoding method according to claim 2, it is characterised in that inspection is also comprised determining whether before step S1 Brushing card data is measured, if so, S1 is then gone to step, if it is not, then persistently judging whether to detect brushing card data.
4. according to any described magnetic card coding/decoding method of claims 1 to 3, it is characterised in that " will be described in the step S2 Pulsewidth sequence is converted into binary sequence code " before, the pulsewidth sequence is modified, including step:
S201, judge whether current pulsewidth sequence P (n-1), P (n), P (n+1) are LSL, wherein S represents short pulse duration, L is represented Long pulsewidth, if it is not, then without amendment;If so, then analyzing the pulsewidth sequence P (n-1), P (n), P (n+1) and the pass of cycle T System, wherein, cycle T is the cycle as obtained by calculating leading 0, and n is the integer more than or equal to 1;
If P (n-1) is less than P (n+1) and (P (n-1)+P (n))/T is less than 150%, the pulsewidth sequence LSL is modified to SSL;
If P (n-1) is more than P (n+1) and (P (n+1)+P (n))/T is less than 150%, the pulsewidth sequence LSL is modified to LSS;
Otherwise, the pulsewidth sequence LSL is modified to LLL;
S202, judge whether current pulse width sequence the continuous S of odd number occurs, if it is not, then without amendment, if so, then analyzing The pulsewidth of the continuous S of odd number and the relation of cycle T;
If there is the continuous short pulse duration P (n-2m-2) of odd number, P (n-2m-1) to P (n), the common 2m+4 pulsewidth of P (n+1), its correspondence Arteries and veins be classified as sequence LSS (2m-1) SL, wherein S (2m-1) and indicate 2m-1 S, analyze the continuous pulsewidth S of odd number with The relation of cycle T;
If P (n)+P (n+1)<=P (n-2m-2)+P (n-2m-1), and (P (n)+P (n+1))/T is less than 150%, then by the sequence Row LSS (2m-1) SL is modified to LLS (2m-1) SS, otherwise, is modified to LSS (2m-1) LL;
If P (n)+P (n+1)>P (n-2m-2)+P (n-2m-1), and (P (n-2m-2)+P (n-2m-1))/T is less than 150%, then will Sequence LSS (2m-1) SL is modified to SSS (2m-1) SL, is otherwise modified to LLS (2m-1) SL, wherein, m is positive integer.
5. magnetic card coding/decoding method according to claim 4, it is characterised in that calculate the pulsewidth sequence start bit and start to connect The average pulse of continuous two or more leading 0, takes the cycle T that the average pulse is track data pulsewidth.
6. magnetic card coding/decoding method according to claim 4, it is characterised in that in step s 2, if current pulse width sequence P (n) current pulse width is then converted to logical zero by pulsewidth within [0.75T, 1.50T], if current pulse width sequence P (n) and P (n+ 1) all [0,0.75T) in, then current pulse width sequence P (n) and P (n+1) are converted into logic 1.
7. magnetic card coding/decoding method according to claim 1, it is characterised in that often find after a peak value, is moved using weighting The dynamic method of average adjusts the size of comparison window, and formula is:
The new old delta*7+abs of delta=(present peak value voltage-bias voltage)/3/8;
Wherein, abs represents to take absolute value.
8. magnetic card coding/decoding method according to claim 1, it is characterised in that often find after a peak value, believed according to magnetic card Number intensity adjust comparison window size, when magnetic card signal is strong increase comparison window size, subtract when magnetic card signal is weak The size of small comparison window.
9. magnetic card coding/decoding method according to claim 1, it is characterised in that in step sl, if current sampling point position It is more than 50ms with the distance of previous peak value, then judges end of swiping the card.
10. a kind of magnetic card decoding apparatus, it is characterised in that including waveform converting unit, pulse width conversion unit and decoding unit;
The waveform converting unit is used to change the analog waveform of swiping the card sampled using mobile comparison window peak detection Into pulsewidth sequence;
The pulse width conversion unit is used to the pulsewidth sequence being converted into binary sequence code, wherein long pulsewidth is converted into logic 0, two continuous short pulse durations are converted into logic 1;
The decoding unit is used to binary sequence code is converted into character string according to decoding standard;
Wherein, the waveform converting unit includes setup module, the first judge module, the second judge module, analysis module and note Record module;
The setup module is used to set comparison window initial Low threshold lt and high threshold ht, the size of the comparison window Delta is ht-lt;
First judge module is used to judge current sampling point whether in the present scope of comparison window, if it is not, then calling Second judge module, if so, then gathering next sampled point and repeating the first judge module until end of swiping the card;
Second judge module be used for judge current sampling point whether be more than current comparison window high threshold, if so, then to The upper movement window, mobile distance is the high threshold of current sampling point-current comparison window, if it is not, then moving down institute Window is stated, mobile distance is Low threshold-current sampling point of current comparison window;
The analysis module is used for the moving process for analyzing the comparison window, if moving down after comparison window is moved up and in succession, Judge sampled point corresponding when comparison window is moved up as positive peak;If moving up after comparison window is moved down and in succession, ratio is judged Corresponding sampled point is negative peak when being moved down compared with window;
The logging modle is used for the pulsewidth that current sampling point is recorded according to the positive peak or negative peak, and the pulsewidth is two Width between adjacent peak value, gathers next sampled point and lays equal stress on dynamic first judge module of polyphony until last sampled point, is obtained To the pulsewidth sequence of analog waveform.
CN201410843802.9A 2014-12-30 2014-12-30 A kind of magnetic card coding/decoding method and device Active CN104463057B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410843802.9A CN104463057B (en) 2014-12-30 2014-12-30 A kind of magnetic card coding/decoding method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410843802.9A CN104463057B (en) 2014-12-30 2014-12-30 A kind of magnetic card coding/decoding method and device

Publications (2)

Publication Number Publication Date
CN104463057A CN104463057A (en) 2015-03-25
CN104463057B true CN104463057B (en) 2017-09-29

Family

ID=52909074

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410843802.9A Active CN104463057B (en) 2014-12-30 2014-12-30 A kind of magnetic card coding/decoding method and device

Country Status (1)

Country Link
CN (1) CN104463057B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107517072B (en) * 2016-06-16 2021-07-23 上海华虹集成电路有限责任公司 Decoding circuit for magnetic medium signal reception in ISO7811 protocol
CN107038397B (en) * 2017-04-10 2019-12-31 上海汇尔通信息技术有限公司 Decoding method and system
CN112395895B (en) * 2019-08-16 2023-08-25 深圳市复恒自控技术有限公司 Magnetic stripe software decoding method and device and computer readable storage medium
CN110838204B (en) * 2019-11-05 2021-04-13 艾体威尔电子技术(北京)有限公司 Decoding method for magnetic stripe card swiping terminal
CN117349632B (en) * 2023-12-05 2024-03-26 北京紫光青藤微系统有限公司 Analysis method and device for magnetic stripe card time sequence and card swiping machine

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2000348444A (en) * 1999-06-04 2000-12-15 Nec Ic Microcomput Syst Ltd Digital variable frequency oscillator
CN102722690A (en) * 2012-05-25 2012-10-10 福建联迪商用设备有限公司 Magcard decoding method
CN103034829A (en) * 2012-12-19 2013-04-10 福建升腾资讯有限公司 Soft decoding method of magcard
CN103888154A (en) * 2014-03-31 2014-06-25 四川九洲空管科技有限责任公司 Multi-channel, anti-interference and anti-aliasing pulse sequence decoding method

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8996952B2 (en) * 2012-01-04 2015-03-31 Marvell World Trade Ltd. High-throughput iterative decoding's defect scan in retry mode of storage system channel

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2000348444A (en) * 1999-06-04 2000-12-15 Nec Ic Microcomput Syst Ltd Digital variable frequency oscillator
CN102722690A (en) * 2012-05-25 2012-10-10 福建联迪商用设备有限公司 Magcard decoding method
CN103034829A (en) * 2012-12-19 2013-04-10 福建升腾资讯有限公司 Soft decoding method of magcard
CN103888154A (en) * 2014-03-31 2014-06-25 四川九洲空管科技有限责任公司 Multi-channel, anti-interference and anti-aliasing pulse sequence decoding method

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
李传伟.一种泥浆脉冲信号识别方法.《测井技术》.2013,第37卷(第2期), *

Also Published As

Publication number Publication date
CN104463057A (en) 2015-03-25

Similar Documents

Publication Publication Date Title
CN104463057B (en) A kind of magnetic card coding/decoding method and device
CN111723329B (en) Seismic phase feature recognition waveform inversion method based on full convolution neural network
CN102028459B (en) Channel pace-making signal detection method of electrocardiogram machine
CN103837891A (en) High-precision pickup method of first arrival of microseism
CN104991687A (en) Method and system for acquiring curve operating track of touch-screen device
CN103487788B (en) The fast automatic extracting method of a kind of train pulse signal
US20130181916A1 (en) Scan method for a touch panel
CN109343118B (en) Abnormal first arrival time correction method
CN104639123B (en) The time point acquisition methods and device of threshold value are crossed in scintillation pulse
CN102722690B (en) magcard decoding method
CN107303177A (en) The detection method and system of a kind of ECG T wave, P ripples
CN105676205A (en) Airborne LiDAR waveform data Gaussian decomposition method
CN105094413B (en) The noise detecting method of touch device, touch control controller and touch panel
CN102722686A (en) Magnetic card decoding method
CN107561420A (en) A kind of cable local discharge signal characteristic vector extracting method based on empirical mode decomposition
WO2004104531A3 (en) Method and system for improved single-ended loop make-up identification
CN102254321B (en) Method for automatically identifying polarity-reversed channel based on first arrival wave
CN1988383A (en) Method for identifying wave form in signal processing
CN108898062B (en) Hand motion recognition method based on improved signal segment extraction algorithm
CN106815801B (en) Median filter circuit structure and median acquisition method
AU2012244118A1 (en) Method and System for Identifying Events of Digital Signal
CN105703850B (en) Based on short-time Fourier transform according to chain signal edge detection method
CN110542927A (en) Variable window weighted seismic data spike noise suppression method
CN103258196B (en) In complex environment, be close to the character separation method of character string
CN114114400A (en) Microseism event effective signal pickup method

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant