3 Analyzing algorithms
Clyne edited this page 2 years ago

stmdspgui provides multiple utilities that will help you study and understand your algorithm better.

Hardware configuration

Sample rate

Sample rates from 8kS/s (kilo-samples per second) to 96kS/s are supported, and can be selected using the drop-down box next to the Upload button while the device is connected.

Changing to a higher sampling rate provides more accurate input data to your algorithm, at the most apparent cost of execution time since the sampling buffer is filled faster. Some algorithms may behave differently depending on the sampling rate too, such as with frequency-sensitive filters.

Buffer size

The size of the input sample buffer that your algorithm works is at the maximum of 4,096 by default. This size can be decreased all the way down to just 100 samples.

Using a smaller buffer can reduce algorithm memory usage, since there are less samples to work with. Again, a smaller buffer is more quickly filled by the ADC, so execution time must be kept in mind.

Algorithm performance

Execution time

An algorithm's performance can be measured by the number of processor clock cycles it takes to execute through the code. This metric can inform you on general algorithm complexity or level of code optimization; it can also be used to compare performance between algorithm implementations.

While an algorithm is running, the "Measure Code Time" option under the Device menu can be clicked to time the next execution of the loaded algorithm. This measurement is not exact, so multiple measurements should be averaged when recording results.

Disassembly

It can be useful to view the list of processor instructions that your algorithm compiles into; for example, this may reveal possible optimizations that would make your algorithm more efficient. Disassembly is the transformation of a compiled program (like your algorithm) into a list of human-readable processor instructions.

Once you have compiled your algorithm, the "Disassemble code" option under the Code menu can be used to view your algorithm's disassembly.

Here is one optimization example: processor instructions are required to convert integer values to floating-point (decimal) and vice versa. By studying where these conversions take place, you can determine if a conversion should be eliminated or moved (perhaps outside of a loop) to reduce the number of times the conversion takes place.

Input signal generation

A custom signal can be generated using either a table of values, a mathematical formula, or a wave (.wav) audio file. The signal can be routed to SIGNAL IN on the add-on board to allow complete control over your algorithm's input.

Output analysis

Sample visualization

When the "Draw samples" option under the Device menu is checked, a graph window will appear. Once the algorithm is started, the output signal will be visualized here. A checkbox allows the input signal to be overlayed, and buttons allow scaling of both the X- (time) and Y- (voltage) axes. The mouse cursor can also indicate the voltage of either signal at a specific point.

After stopping the algorithm, the visualization will freeze.

Sample logging

The "Log results..." option under the Device menu allows for output sample data to be recorded to a comma-delimited (.csv) file. The logging begins on algorithm start, and ends on algorithm stop. The resulting file can be opened by another program, such as a spreadsheet application, to closely study the output.