Digital oscilloscope mathematical operation processing method based on inverse Polish algorithm

文档序号:1056781 发布日期:2020-10-13 浏览:31次 中文

阅读说明:本技术 基于逆波兰算法的数字示波器数学运算处理方法 (Digital oscilloscope mathematical operation processing method based on inverse Polish algorithm ) 是由 黄武煌 张沁川 帅维维 赵勇 叶芃 田书林 王厚军 于 2020-06-30 设计创作,主要内容包括:本发明公开了一种基于逆波兰算法的数字示波器数学运算处理方法,该方法包括输入字符参数,生成运算表达式;对算术运算表达式进行中缀表达式向逆波兰式转换解析,并检测解析过程中表达式的合法性;逐元素对逆波兰形式表达式进行计算;将计算结果存储至对应的数学通道的数据缓冲区内;将运算结果显示于示波器屏幕上。本发明不仅能提供基本的运算方法,还可以使用户根据自身测试需求构造复杂运算表达式,并完成分析计算,满足更多的测量需求。(The invention discloses a digital oscilloscope mathematical operation processing method based on an inverse Polish algorithm, which comprises the steps of inputting character parameters and generating an operation expression; carrying out conversion and analysis of the infix expression to the inverse wave blue expression on the arithmetic operation expression, and detecting the legality of the expression in the analysis process; calculating the inverse Polish form expression element by element; storing the calculation result into a data buffer area of a corresponding mathematical channel; and displaying the operation result on an oscilloscope screen. The invention not only can provide a basic operation method, but also can enable a user to construct a complex operation expression according to the self test requirement, complete analysis and calculation and meet more measurement requirements.)

1. A mathematical operation processing method of a digital oscilloscope based on an inverse Polish algorithm is characterized by comprising the following steps:

s1, inputting character parameters and generating an operation expression;

s2, carrying out conversion and analysis of the infix expression to the inverse wave blue expression on the arithmetic operation expression, and detecting the legality of the expression in the analysis process;

s3, calculating the inverse Polish form expression element by element;

s4, storing the calculation result into the data buffer area of the corresponding mathematical channel;

and S5, displaying the operation result on an oscilloscope screen.

2. The method for processing the mathematical operation of the digital oscilloscope based on the inverse Polish algorithm as claimed in claim 1, wherein said step S1 further comprises:

and converting the generated operational expression into a half-angle input and a lower case format.

3. The method for processing the mathematical operation of the digital oscilloscope based on the inverse Polish algorithm according to claim 2, further comprising the following substeps after the step S1:

a1, splitting the operation expression according to the measurement item character string and the operation character string;

a2, by way of traversal, "+ -/(), > <! And | & - "is a divider mark, and the operation expression elements are extracted and stored in a queue mode.

4. The method for processing the mathematical operation of the digital oscilloscope based on the inverse Polish algorithm as claimed in claim 3, wherein in step A2, a Token data structure is defined as the data structure, the Token data structure comprises types, units, identifiers, and elements at the positions of expressions, wherein the types comprise operands, operators, functions, and separators, and the operational expression string is set to List < Token >.

5. The method for processing the mathematical operation of the digital oscilloscope based on the inverse Polish algorithm as claimed in claim 4, wherein in the step S2, the step of converting and analyzing the infix expression into the inverse Polish expression for the mathematical operation expression specifically comprises the following sub-steps:

b1, creating a data stack for storing the operational characters, and storing the operational characters according to the priority;

b2, sequentially traversing the infix expression data structure, and judging the type of the current element by checking the type identifier of each Token element until all elements in the whole infix expression are traversed:

if the element is an operand, outputting the element to an inverse wave-blue queue; otherwise, the next judgment is carried out;

if the element is a function, saving the element using a temporary variable; otherwise, the next judgment is carried out;

if the element is an operator, pushing the element to a stack when the operator stack is empty or the top-of-stack operator has higher priority or the top-of-stack operator is left parenthesis; otherwise, popping an element from the stack and outputting the element to the inverse wave form, and repeating the step of judging the operation character stack until the element is pressed into the stack; otherwise, the next judgment is carried out;

if the element is left brackets and the temporary variable is not null, outputting the element to an inverse wave form and simultaneously pressing the element and the temporary variable into a stack, and then setting the temporary variable to null; otherwise, directly pushing the element into the stack; otherwise, the next judgment is carried out;

if the element is a right bracket, when the stack top is a function, outputting the element to an inverse wave blue type queue, and popping one element from the stack top to the inverse wave blue type queue; when the stack top is an operator, popping an element from the stack top to an inverse wave blue type queue, and then repeatedly judging whether the stack is empty at the moment; if the stack top is a left bracket, popping up an element from the stack top; otherwise, the next judgment is carried out;

if the element is a comma, sequentially popping up all the operational characters in the operational character stack, and outputting the operational characters to the inverse wave blue queue until a function source is met; otherwise, acquiring the next element for judgment.

6. The method for processing the mathematical operation of the digital oscilloscope based on the inverse Polish algorithm as claimed in claim 5, wherein said step S2 further comprises a function verification operation, which comprises the following sub-steps:

c1, creating a data stack for storing operands and brackets;

c2, in the process of converting the infix expression into the inverse wave blue expression,

if the function is matched with the left bracket or the operand, the function is pressed into a check stack, and when the operator needs to be output to the inverse wave blue type queue, the operand in the check stack is popped according to the inverse wave blue type calculation rule to check whether the operand quantity is matched with the operator, if the condition is met, the check is successful, the operator is output, and if the condition is not met, an error is reported and the program is ended.

7. The method for processing mathematical operation of a digital oscilloscope based on an inverse Polish algorithm according to claim 6, wherein the step S3 of calculating the inverse Polish form expression element by element specifically comprises the following substeps:

d1, creating a data stack storing the intermediate result;

d2, traversing the inverse wave form data structure in turn, judging the type of the current element by checking the type identification of each Token element until all elements in the whole inverse wave form are traversed:

if the element is an operand or a left bracket and a right bracket, the element is directly pushed into a stack; otherwise, the next judgment is carried out;

if the element is an operator, firstly acquiring the number of operands defined by the current operator, popping out the operands meeting the number from the stack, and pressing result data into the stack after calculation; otherwise, the next judgment is carried out;

if the element is a function, popping an operand in a pair of brackets nearest to the top of the stack from the stack, acting on the function for operation, and pressing an operation result into the stack after calculation; otherwise, the last numerical value is popped from the stack to be output as a data result with a display waveform.

Technical Field

The invention belongs to the technical field of electronic measuring instruments, and particularly relates to a digital oscilloscope mathematical operation processing method based on an inverse Polish algorithm.

Background

In recent years, with the intensive research in the signal and system direction and the gradual maturity of high-speed and high-precision data acquisition and processing technology, more and more functions are implemented in the electronic test technology and related instruments. Under the development background, as a basic electronic measuring instrument, more and more fields and industries complete related testing work by means of a digital oscilloscope, and with the expansion of application fields, various testing environments also appear, so that the testing execution is more difficult. Meanwhile, the test requirements in different fields are different, so that the oscilloscope is required to have more comprehensive waveform analysis functions, such as variable point FFT, area-selectable histogram analysis, tracking diagram analysis and the like, so as to meet the test requirements of users on various waveforms.

Disclosure of Invention

Aiming at the defects in the prior art, the invention provides a digital oscilloscope mathematical operation processing method based on an inverse Polish algorithm, which is used for completing a series of self-defined operation processing on a measured signal, realizing more complex processing on acquired data and greatly improving the data processing capacity of the oscilloscope. .

In order to achieve the purpose of the invention, the invention adopts the technical scheme that:

a mathematical operation processing method of a digital oscilloscope based on an inverse Polish algorithm comprises the following steps:

s1, inputting character parameters and generating an operation expression;

s2, carrying out conversion and analysis of the infix expression to the inverse wave blue expression on the arithmetic operation expression, and detecting the legality of the expression in the analysis process;

s3, calculating the inverse Polish form expression element by element;

s4, storing the calculation result into the data buffer area of the corresponding mathematical channel;

and S5, displaying the operation result on an oscilloscope screen.

Further, the step S1 further includes:

and converting the generated operational expression into a half-angle input and a lower case format.

Further, the step S1 is followed by the following sub-steps:

a1, splitting the operation expression according to the measurement item character string and the operation character string;

a2, by way of traversal, "+ -/(), > <! And | & - "is a divider mark, and the operation expression elements are extracted and stored in a queue mode.

Further, in the step a2, a Token data structure is defined as a data structure body, the Token data structure includes a type, a unit, an identifier, and an element located at a position of an expression, where the type includes an operand, an operator, a function, and a separator, and the operational expression string is set to List < Token >.

Further, in step S2, the inverse-wavelet transform and analysis of the infix expression to the arithmetic operation expression specifically includes the following sub-steps:

b1, creating a data stack for storing the operational characters, and storing the operational characters according to the priority;

b2, sequentially traversing the infix expression data structure, and judging the type of the current element by checking the type identifier of each Token element until all elements in the whole infix expression are traversed:

if the element is an operand, outputting the element to an inverse wave-blue queue; otherwise, the next judgment is carried out;

if the element is a function, saving the element using a temporary variable; otherwise, the next judgment is carried out;

if the element is an operator, pushing the element to a stack when the operator stack is empty or the top-of-stack operator has higher priority or the top-of-stack operator is left parenthesis; otherwise, popping an element from the stack and outputting the element to the inverse wave form, and repeating the step of judging the operation character stack until the element is pressed into the stack; otherwise, the next judgment is carried out;

if the element is left brackets and the temporary variable is not null, outputting the element to an inverse wave form and simultaneously pressing the element and the temporary variable into a stack, and then setting the temporary variable to null; otherwise, directly pushing the element into the stack; otherwise, the next judgment is carried out;

if the element is a right bracket, when the stack top is a function, outputting the element to an inverse wave blue type queue, and popping one element from the stack top to the inverse wave blue type queue; when the stack top is an operator, popping an element from the stack top to an inverse wave blue type queue, and then repeatedly judging whether the stack is empty at the moment; if the stack top is a left bracket, popping up an element from the stack top; otherwise, the next judgment is carried out;

if the element is a comma, sequentially popping up all the operational characters in the operational character stack, and outputting the operational characters to the inverse wave blue queue until a function source is met; otherwise, acquiring the next element for judgment.

Further, the step S2 further includes a function verification operation, which specifically includes the following sub-steps:

c1, creating a data stack for storing operands and brackets;

c2, in the process of converting the infix expression into the inverse wave blue expression,

if the function is matched with the left bracket or the operand, the function is pressed into a check stack, and when the operator needs to be output to the inverse wave blue type queue, the operand in the check stack is popped according to the inverse wave blue type calculation rule to check whether the operand quantity is matched with the operator, if the condition is met, the check is successful, the operator is output, and if the condition is not met, an error is reported and the program is ended.

Further, the step S3 of calculating the inverse-wave form expression element by element specifically includes the following sub-steps:

d1, creating a data stack storing the intermediate result;

d2, traversing the inverse wave form data structure in turn, judging the type of the current element by checking the type identification of each Token element until all elements in the whole inverse wave form are traversed:

if the element is an operand or a left bracket and a right bracket, the element is directly pushed into a stack; otherwise, the next judgment is carried out;

if the element is an operator, firstly acquiring the number of operands defined by the current operator, popping out the operands meeting the number from the stack, and pressing result data into the stack after calculation; otherwise, the next judgment is carried out;

if the element is a function, popping an operand in a pair of brackets nearest to the top of the stack from the stack, acting on the function for operation, and pressing an operation result into the stack after calculation; otherwise, the last numerical value is popped from the stack to be output as a data result with a display waveform.

The invention has the following beneficial effects:

the invention can contain all the measurement items supported by the mathematical operation of the digital oscilloscope into the operation expression character string, and carry out waveform operation through inverse Polish expression conversion, and in the inverse Polish conversion process, an operational character verification step is added to judge whether the number of the operational numbers meets the operation requirements, so that the legality judgment of the expression can be realized more efficiently, the data analysis and processing capability of the oscilloscope is greatly improved, meanwhile, the operation efficiency is improved to a certain extent, and the defect that the conventional instrument cannot carry out the self-defined polynomial structure on the measurement items is solved.

Drawings

FIG. 1 is a flow chart of the mathematical operation processing method of the digital oscilloscope based on the inverse Polish algorithm according to the present invention;

FIG. 2 is a schematic diagram of a reverse-wave-type process of the affix expression of the present invention;

FIG. 3 is a schematic diagram of the reverse Polish-like flow of the present invention;

FIG. 4 is a schematic diagram of a function verification process according to the present invention.

Detailed Description

The following description of the embodiments of the present invention is provided to facilitate the understanding of the present invention by those skilled in the art, but it should be understood that the present invention is not limited to the scope of the embodiments, and it will be apparent to those skilled in the art that various changes may be made without departing from the spirit and scope of the invention as defined and defined in the appended claims, and all matters produced by the invention using the inventive concept are protected.

As shown in fig. 1, an embodiment of the present invention provides a method for processing mathematical operations of a digital oscilloscope based on an inverse polish algorithm, including the following steps S1 to S5:

s1, inputting character parameters and generating an operation expression;

in this embodiment, the present invention inputs at least one mathematical expression string, which may include a measurement string, operators, functions, scalars, and left and right brackets. Specifically, the string of mathematical expression may be entered directly into the oscilloscope by a formula editor software keyboard or from a selected parameter composition, the formula editor including all the elements that make up the mathematical expression, including channel sources, constants, brackets, operators, special symbols, functions, and logical operators. Operators include addition, subtraction, multiplication and division, and functions include calculus, FFT, linear average, logarithm, exponent, and the like.

After the operational expression is generated, the generated operational expression is converted into a half-angle input and lower case format, so that elements in the operational expression can be conveniently searched in a database and an operational character library.

The invention converts the operational expression from character string form to List < Token > form, which comprises the following steps:

a1, splitting the operation expression according to the measurement item character string and the operation character string;

a2, by way of traversal, "+ -/(), > <! And | & - "is a divider mark, and the operation expression elements are extracted and stored in a queue mode.

In step a2, the present invention defines a Token data structure as a data structure, where the Token data structure includes types, units, identifiers, and elements at the positions of expressions, where the types include operands, operators, functions, and separators, and the operational expression string is set to List < Token >.

S2, carrying out conversion and analysis of the infix expression to the inverse wave blue expression on the arithmetic operation expression, and detecting the legality of the expression in the analysis process;

in this embodiment, the method for performing inverse wavelet transform analysis on an arithmetic operation expression by using a infix expression specifically includes the following sub-steps:

b1, creating a data stack for storing the operational characters, and storing the operational characters according to the priority;

specifically, the invention deposits the operators in the operator stack following the principle that the higher the priority the operators are placed on the top of the stack.

B2, sequentially traversing the infix expression data structure from left to right, and determining the type of the current element by checking the type identifier of each Token element until all elements in the whole infix expression are traversed, as shown in fig. 2, the determining process specifically includes:

b21, firstly, judging whether the infix expression is null; if yes, judging whether the operation character stack is empty, if yes, ending the process, and if not, popping up the rest operation characters in the operation character stack one by one and pressing the rest operation characters into a reverse wave blue type queue; otherwise, acquiring an element from the infix expression to perform next judgment;

b22, judging whether the element is an operand, if yes, outputting the element to an inverse wave blue type queue, and returning to the step B21; otherwise, the next judgment is carried out;

b23, judging whether the element is a function, if so, saving the element by using a temporary variable _ function, and returning to the step B21; otherwise, the next judgment is carried out;

b24, judging whether the element is an operator, if so, judging whether the operator stack is empty or the operator at the top of the stack has higher priority or the operator at the top of the stack is a left bracket, if so, pressing the element into the stack, and returning to the step B21; otherwise, popping an element from the stack and outputting the element to the inverse wave form, and repeating the step of judging the operation character stack until the element is pressed into the stack; otherwise, the next judgment is carried out;

b25, judging whether the element is a left bracket or not, if so, judging whether the temporary variable is not empty or not, outputting the element to an inverse wave-blue type, simultaneously pressing the element and the function variable into a stack, and setting the temporary variable _ function to be empty; otherwise, directly pushing the element to the stack and returning to the step B21; otherwise, the next judgment is carried out;

b26, judging whether the element is a comma, if so, sequentially popping all the operational characters in the operational character stack, and outputting the operational characters to the inverse wave-blue queue until a function source is met; otherwise, the next judgment is carried out;

b27, judging whether the operator stack is empty, if so, ending the process, otherwise, performing the next judgment;

b28, judging whether the stack top is a function, if so, outputting the element to an inverse wave blue type queue, popping an element from the stack top to the inverse wave blue type queue, and returning to the step B27; otherwise, the next judgment is carried out;

b29, judging whether the stack top is an operator, if so, popping an element from the stack top to an inverse wave blue queue, and returning to the step B27; otherwise pop an element from the top of the stack and return to step B21.

The method for detecting the legality of the expression in the analytic process specifically comprises the following steps:

c1, creating a data stack for storing operands and brackets;

c2, performing function verification in the process of converting the infix expression into the inverse wave form, as shown in fig. 3, the determining process specifically includes:

c21, judging whether the check stack is empty, if so, indicating that the expression is incomplete, and ending the process; otherwise, outputting the Boolean value doPop as true, and performing the next judgment;

c22, judging whether the check stack is not empty and the Boolean value doPop is true, if so, popping an element from the check stack, and performing the step C26; otherwise, the next judgment is carried out;

c23, judging whether the check stack is empty and the Boolean value doPop is true, if so, carrying out next judgment, otherwise, indicating that the left bracket is lacked, and ending the flow;

c24, judging whether the operand number of the inspection area matches the function requirement number, if so, indicating that the formula is correct, and ending the flow; otherwise, the next judgment is carried out;

c25, judging whether the operand number in the inspection area is less than the function requirement number, if so, indicating that the parameters are too few and ending the process; otherwise, the flow is ended when the parameters are too few;

c26, judging whether the element is an operand, if yes, outputting the element to the region to be checked; otherwise, the next judgment is carried out;

c27, judging whether the element is a left bracket or not, if so, outputting a Boolean value doPop as false, and returning to the step C22; otherwise, the illegal character appears, and the process is ended.

S3, calculating the inverse Polish form expression element by element;

in this embodiment, calculating the inverse-wave form expression element by element specifically includes the following sub-steps:

d1, creating a data stack storing the intermediate result;

d2, sequentially traversing the inverse wave-ring data structures from left to right, and determining the type of the current element by checking the type identifier of each Token element until all elements in the entire inverse wave-ring are traversed, as shown in fig. 4, the determining process specifically includes:

d21, judging whether an element which is not traversed exists in the inverse wave form, if so, reading one element from the inverse wave form, and carrying out next judgment; otherwise, outputting the last numerical value popped from the stack as a result, and ending the process;

d22, judging whether the element is operand or separator, if yes, pushing the element into stack, and returning to step D21; otherwise, the next judgment is carried out;

d23, judging whether the element is an operator, if so, popping the numerical value of the number required by the operator from the stack for calculation to obtain a calculation result, pressing the calculation result into the stack, and returning to the step D21; otherwise, a pair of bracket range parameters is popped from the stack to act on the function, a calculation result is obtained, the calculation result is pushed into the stack, and the step D21 is returned.

And repeatedly executing the steps until all elements of the inverse wave form are traversed.

And finally, popping the last numerical value from the stack to output as a data result with a display waveform.

S4, storing the calculation result into the data buffer area of the corresponding mathematical channel;

and S5, displaying the operation result on an oscilloscope screen.

The invention realizes simple algebraic operation and more than 20 functional operations and logic operations such as FFT, histogram, tracing graph, average, differential, integral and the like on a designated data source, namely waveform data, parameter measurement result and scalar are taken as input sources of a mathematical channel.

It will be appreciated by those of ordinary skill in the art that the embodiments described herein are intended to assist the reader in understanding the principles of the invention and are to be construed as being without limitation to such specifically recited embodiments and examples. Those skilled in the art can make various other specific changes and combinations based on the teachings of the present invention without departing from the spirit of the invention, and these changes and combinations are within the scope of the invention.

12页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:存储器控制方法、存储器存储装置及存储器控制电路单元

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!

技术分类