Fortune Telling Collection - Comprehensive fortune-telling - What are the characteristics of DSP suitable for digital signal processing?
What are the characteristics of DSP suitable for digital signal processing?
For novices who have never used DSP, the first confusion is what is the difference between other embedded processors of DSP, and what is the difference between DSP and MCU and ARM. In fact, DSP is also an embedded processor, which can completely complete the functions of single chip microcomputer.
The only important difference is that DSP supports the "multiply and add" operation of a single clock cycle. This is a * * * feature of almost all manufacturers' DSP chips. Almost all DSP processors have a MAC instruction in the instruction set. This instruction can take two operands from RAM, multiply them and add them to the accumulator. All these operations are completed in one clock cycle. A processor with such instructions has the function of a DSP.
This instruction is called digital signal processor because the most common arithmetic operation in all digital signal processing algorithms is "multiplication and addition". This is because the inner product or dot product operation is widely used in digital signal processing. Whether it is FIR filtering, FFT, signal correlation, digital mixing, down conversion. All these digital signal processing operations are often to multiply the input signal by a coefficient table or a local reference signal and then integrate (accumulate), which shows the dot product of two vectors (or sequences). Programming becomes to put the input sample into a circular buffer, the local coefficient table or reference signal into a buffer, and then point to the two buffers with two pointers. In this way, MAC instructions can be used to dot product the two in a loop. This dot product operation is the fastest for AND processor, because it only takes a constant period to complete multiplication and addition.
After understanding this feature of DSP, when designing an embedded system, we should first consider whether there is a dot product operation in the algorithm implemented by the processor, that is, whether to multiply and add two arrays frequently (remember digital filtering, correlation, etc.). Both display the dot product of two arrays), if so, how many times per second, so that we can decide whether to use DSP or not and how high-performance DSP to use.
Floating point and fixed point
Floating point and fixed point are also problems that beginners often confuse. When choosing a DSP device, do you use a floating point or a fixed point? Is the fixed point 16 bit or 32 bit? In fact, this problem is related to the signal dynamic range required by your algorithm.
Fixed-point calculation just treats a data as an integer. Usually AD samples all integers, and this number has a scale factor relative to the real analog signal. As we all know, if a signal is sampled from 0 to 5V with a 16 bit AD, then the integer output by the AD divided by 2 16 and multiplied by 5V is the corresponding voltage. In the fixed-point DSP, this sampling of 16 bits is directly processed, and it is not converted into a voltage expressed in decimal, because the fixed-point DSP cannot express a decimal with enough precision, and it can only calculate an integer.
The advantage of floating-point DSP is that it can convert the sampled integer into decimal voltage without losing accuracy (this decimal is expressed by scientific notation), because scientific notation can represent a signal with a large dynamic range. Take IEEE754 floating-point number as an example.
Single-precision floating-point format: [3 1] 1 sign [30-23]8-bit exponent [22-00]23-bit decimal.
The minimum number that can be expressed is +-2- 149, and the maximum number is +-(2-2 23) * 2 127. The dynamic range is 20 * log (max/min) =1667.6 db, because the signal dynamic range of fixed-point processing is limited. For example, a 16-bit fixed-point DSP can represent the integer range of 1-65536, and its dynamic range is 20*log(65536/ 1)=96dB. For 32-bit fixed-point DSP, the dynamic range is 20 * log (2 32/0). It is far less than 1667.6dB of 32-bit ieee floating-point numbers, but in fact 192dB is enough for most applications.
Generally, the dynamic range of the input signal is relatively small due to the limitation of the number of bits of the AD converter. However, in the signal processing of DSP, because the dot product operation will increase the dynamic range of the intermediate node signal, the dynamic range of the intermediate result in the signal processing flow and the accuracy requirements of the algorithm are mainly considered to select the corresponding DSP. In addition, floating-point DSP is easier to program. In fixed-point DSP programming, programmers need to constantly adjust the P and Q values of the intermediate results, which is actually to shift and round the intermediate results.
DSP and RTOS
TI's CCS provides BIOS, and ADI's VDSP provides VDK, both of which are embedded multitasking cores based on their respective DSP. DSP programming can use C alone, assembly or both, and general software compilation tools provide good support. I don't want to talk more about BIOS and how to use VDK here, which are described in detail in the corresponding documents. I want to tell beginners about the RTOS principle of DSP. In just a few paragraphs, this complex thing is also a challenge!
In fact, the RTOS of DSP is not much different from that based on other processors. Now, the almost well-known uCOSii can be easily transplanted to DSP, as long as the register storage and recovery part and the stack part are changed. Generally, before using BIOS and VDK, it is best to read books on operating system principles. UCOS is also a good book.
BIOS and VDK are actually a set of RTOS kernel functions, and applications of DSP will be connected with these functions into an executable file. In fact, it is not complicated to implement a simple multitasking kernel. Firstly, define various data structures of the kernel, and then write a scheduler function, whose function is to find the task with the highest priority from all ready tasks (by looking up the ready task queue or ready task table) and resume its execution. Then on this basis, write several functions for communication between tasks, such as events, message boxes and so on.
RTOS usually adopts preemptive task scheduling. For example, when the resources that task A is waiting for are available, DSP will execute a task scheduler function, which will check whether the priority of the current task is lower than that of task A, if so, it will pause at present, and then save all the register values of task A in the stack and pop them into the DSP processor (this is called task bit recovery). Then the scheduler will pop the address of the program execution when task A is suspended from the stack to the PC, so that task A can continue to execute. In this way, the current task is preempted by task A.
After using RTOS, each task will have a main function, and the starting address of this function is the entrance of the task. Generally, there is an infinite loop in the main function of each task, which makes the task execute periodically and completes some functions of the algorithm module. In fact, this function is no different from ordinary functions, similar to the main function in C language. When a task is created, RTOS will push the function entry address onto the task stack as if the function (task) had just been interrupted. Once the newly created task has the highest priority in the ready queue, RTOS will pop its entry address from the stack and start execution.
One problem is that the scheduled execution of the software can be realized only by using a main loop to call each functional module in the program without using RTOS. So, what is the difference between this common method and using RTOS? In fact, the method of using the main loop is just a scheduling strategy of sequential execution without priority. The disadvantage of this method is that the functions called in the main loop are executed in sequence, so even an insignificant function (such as flashing an led) will be executed until the end as long as it does not return actively. At this time, if an important event (such as DMA buffer full interrupt) occurs, you will not get timely response and processing, and you can only wait until the function with flashing LED is executed. This makes the priority of the whole DSP processing very unreasonable. After using RTOS, when an important event occurs, interrupt processing will enter RTOS and call the scheduler. At this time, the scheduler will let the task handling the event preempt the DSP processor (because of its high priority). And it doesn't matter which flashing LED task is executed after a few milliseconds. So the scheduling strategy of the whole DSP is very reasonable.
RTOS has too much to say, so I can only talk about my own experience.
DSP and sine wave
In the application of DSP, we often use trigonometric function or synthesize a sine wave. This is because we like to map the signal to trigonometric function space through Fourier transform to understand the frequency characteristics of the signal. Some calculation skills of signal processing need trigonometric function calculation in DSP software. But trigonometric function calculation is nonlinear calculation, and DSP has no special instruction to find the sine or cosine of a number. So we need to use linear method to approximate the solution.
A direct idea is to use polynomial fitting, which is also the method used by most DSP C compilers to provide sine and cosine library functions. Its principle is to project trigonometric function into function space {1, x, x 2, x 3...}, so as to get a series of coefficients, which can be used to fit trigonometric function. For example, if we fit sin in the interval of [0, pi/2], we only need to enter the following command in matlab:
x = 0:0.05:pi/2;
p=polyfit(x,sin(x),5)
You get a polynomial coefficient of order 5:
p =
0.0058 1052047605 0.005809632 16 172 -0. 17 193865685360
0.002090027 16293 0.999692700873 12 0.00000809543448
So in the interval of [0, pi/2]:
sin(x)= 0.00000809543448+0.999692700873 12 * x+0.002090027 16293*x^2-0. 17 193865685360*x^3+
0.005809632 16 172*x^4+0.0058 1052047605*x^5
Therefore, in the DSP program, we can approximate sin(x) by using the multiply-add (MAC) instruction to calculate this polynomial.
Of course, if a fixed-point DSP is used, the polynomial coefficient table P will be rewritten into a fixed number of points with a certain Q value.
Such trigonometric function calculation generally takes dozens of cycles. This is unbearable on some occasions.
Another faster way is to look up the table. For example, we divide [0, pi/2] into 32 intervals, and the length of each interval is pi/64. In each interval, we use a straight line segment to fit the sine curve. The sine value and slope of the line segment at the beginning of each interval are pre-calculated and stored in RAM, so it is necessary to store 64 in RAM.
Constant:
Exact sine values of 32 starting points (pre-calculated): S [32] = {0, SIN (PI/64), SIN (PI/32), SIN (PI/ 16). ...
Slope of 32 line segments: f [32] = {0.049, ...}
For each input x, the interval I is first obtained according to its size. Usually, x is represented by a fixed point. Generally, the coefficient I is taken as its higher order. Then, sin(x) can be obtained by the following formula:
sin(x)= s[i]*f[i]
In this way, it usually takes only a few cycles to calculate the sine value. If higher precision is needed, the interval can be divided into finer intervals. Of course, more RAM is needed to store the constant table.
In fact, not only trigonometric functions, but also various other nonlinear functions are calculated approximately in this way.
- Previous article:Dreaming of a man's long hair is a sign.
- Next article:Tell my fortune for my luck and life.
- Related articles
- Learn fortune telling _ fortune telling is easy to learn.
- What fortune-telling temples are there in Zhangzhou?
- Blue Sky Fortune _ Who is Blue Sky?
- How to measure constellations
- A detailed introduction of playing cards? (Color and case introduction)
- 159 Free fortune telling
- Tell God's Destiny _ God's Destiny
- The original singing of Buguo's ancient painting drama
- Fortune telling is a joke _ Fortune telling is a joke.
- What are the omens of dreaming that the earth is black? What do you mean?