Sonomicrometry is widely applied in biomechanics and physiology to measure precise distances with high temporal resolution. Although commonly used, its usefulness is often limited by the presence of artifacts that require correction. Unfortunately, procedures reported in the literature for artifact correction are often unclear. Furthermore, currently available tools for artifact correction require significant manual manipulations, the consistency of which takes painstaking effort to verify. To improve the efficiency and consistency of sonomicrometry, we have developed a new software tool for the correction of sonomicrometry artifacts. This tool provides a framework for artifact correction requiring fewer and more limited manipulations from the user. We aimed to make this tool more transparent and easier to use than commercially available tools. To facilitate its application, we describe the relevant properties of sonomicrometry artifacts and detail the software's correction algorithm. The software is available for MacOS and Linux with source code and documentation.
Sonomicrometry is a technique for measuring precise distances with high temporal resolution (Rushmer et al., 1956). The distances are measured by the transmission and timing of ultrasound pulses between piezoelectric crystals. Sonomicrometry has been commonly applied to biomechanics (Azizi and Roberts, 2010; Butterfield and Herzog, 2005; Griffiths, 1987; Marsh et al., 1992; Symons et al., 2002; Tobalske et al., 2003) and to various physiological disciplines, including cardiovascular (Dione et al., 1997; Fawzy et al., 2011) and gastrointestinal physiology (Adelson et al., 2004; Armstrong et al., 2006).
Distance traces obtained from sonomicrometry are prone to artifacts that impede further analysis (Adelson and Million, 2004; Ellerby and Askew, 2007; Dione et al., 1997). Fortunately, when using digital sonomicrometry systems, these artifacts are usually easy enough to distinguish from actual data that they can be identified and rectified using heuristics. Indeed, the digital sonomicrometry systems manufactured by Sonometrics (Sonometrics Corporation, London, ON, Canada) are packaged with software (SonoSoft) for the correction of such artifacts, and users of this system have developed or used custom-written software for the same purpose (Adelson et al., 2004; Dione et al., 1997; Ellerby and Askew, 2007).
It is not uncommon, however, to obtain distance traces of poor quality such that the correction of artifacts is non-trivial. In these cases, correction is complicated by the need to judge whether or not the artifacts are correctable and just how they should be corrected. Hinging on our decision are the expenditure of time and labour (if we are overly careful), but also, more crucially, the integrity of the data (if we are not careful).
So, how best should we decide what corrections to make and how to make them? The answer to this question is unclear from the literature. Criteria for the inclusion and exclusion of data, as well as procedures for correcting artifacts, are not reported in detail. This includes the procedures used by programs designed for artifact correction, as the source codes are not publicly available.
Furthermore, poor-quality distance traces typically require manual user input to address the artifacts that are mishandled by automated procedures. This can make artifact correction time consuming and painstaking, especially for applications generating large volumes of sonomicrometry data – for instance, by the use of many crystals (Dione et al., 1997) or long recording times (Adelson and Million, 2004).
Ideally, there should be a procedure that one could apply uniformly to data in order to characterize and address artifacts in a manner justified by knowledge of the underlying sources of error, alongside a tool that automates as much of that procedure as possible. Though we attempted to reach this ideal, we cannot claim to have attained it. However, we suggest that what we have produced represents a step towards this ideal goal.
Here, we introduce a software tool (SonoCleaner) and accompanying guidelines for the correction of sonomicrometry artifacts. Our main aim was to document at least one procedure for the correction of sonomicrometry artifacts. Furthermore, we find that the software tool is more autonomous and generally easier to use than SonoSoft.
In this paper, we describe the software tool from a user's perspective, the nature of sonomicrometry artifacts and the key procedure implemented by the software tool. Separately, we discuss guidelines for the correction of sonomicrometry artifacts in the documentation of the software tool.
MATERIALS AND METHODS
Overall aims and structure of the software tool
SonoCleaner is an open source, Creative Commons licensed software tool for the (1) efficient and (2) controlled correction of sonomicrometry artifacts.
Because sonomicrometry can generate large volumes of data that can be tedious to correct manually, we aimed to handle sonomicrometry artifacts efficiently and, as much as possible, automatically. While the majority of sonomicrometry artifacts are easy to detect and correct, there are usually some artifacts for which correction is more subtle, or even ambiguous, and thus ill advised. Thus, artifact correction in general requires judgement and precise control; our aim was to provide the latter in order to empower the former.
Accordingly, the software tool is composed of two complementary parts: (1) an automated procedure for the efficient removal of easy, unambiguous artifacts, and (2) several tools to manually address the difficult or ambiguous artifacts.
The automated procedure is not expected to correct all traces completely; it will inevitably encounter artifacts that it handles erroneously. In these cases, the user is expected to step in to remove the stumbling block (either by performing the correction manually or by deciding to reject the trace) so that the procedure can continue. This collaboration between the user and the automated procedure is enabled by the ability to apply (and reverse) the automated procedure in fine-grained, progressive steps. In this way, the user has control over the correction of artifacts but also has responsibility for the validity of the corrections.
Description of the user interface and features of the software tool
Users interact with the tool through a graphical user interface. The interface displays the sonomicrometry distance trace being ‘cleaned’ and highlights the artifacts automatically. Using the mouse, the user can zoom in and inspect portions of a trace, and can select artifacts either individually or in groups for manual correction. Manual operations are selected from a small number of pre-set procedures for efficiency and reproducibility. The automated procedure can be applied at any time and can be restricted to a selected time interval.
The tool allows for the superposition of other traces on the trace under consideration in order to (a) compare them for internal consistency and (b) facilitate the standard practice of comparing the raw and corrected traces to ensure that corrections do not introduce new errors.
For convenience, the tool also includes functionality for (1) cropping traces, in order to focus on or export only a portion of a trace and (2) the annotation of trace qualities, which are simply collected into a comma-separated value (csv) file that is exported in addition to the file of distance traces.
A demonstration of the tool on physiological data can be found below, in Results and Discussion.
Where can the software tool be obtained?
The source code and binary executables for MacOS and Linux can be downloaded from https://github.com/awjchen/SonoCleaner/releases. The executables are bundled with documentation that describes the features of the software tool and explains how they should be used.
Software tool limitations and future plans
Windows operating systems are not currently supported.
Sonometrics .ssa files are currently the only format in which distance traces can be imported into or exported from the software tool. Consequently, the outputs generated by this software tool cannot be fed back into Sonometrics' SonoSoft as, to our knowledge, SonoSoft cannot read .ssa files.
This tool requires traces with sufficiently high sampling rates in order to reliably identify artifacts and estimate slopes. In general, recordings of movements that are faster and more abrupt will require higher sampling rates.
This tool may not be suitable for precise kinematics because (1) it uses a linear interpolation procedure and (2) it causes the uncertainties and errors in the correction of artifacts to manifest as small but abrupt changes in the distance trace.
We plan to update the software tool to try to address shortcomings as they become clear. In its current state, the software tool has room for improvement, so we would welcome your feedback and suggestions at https://github.com/awjchen/SonoCleaner/issues!
Description of level-shifts and other sonomicrometry artifacts
In order to give a description of the automated procedure, we must first touch upon the nature of sonomicrometry artifacts. Note that the following details may apply only to the sonomicrometers manufactured by Sonometrics, as data acquired with these devices were used to develop the artifact-removal procedures. Moreover, we stress that the following is merely our own explanation of sonomicrometry artifacts based on empirical observations using the sonomicrometer's built-in support for viewing raw ultrasound signals with an oscilloscope.
The basic principle of sonomicrometry
Sonomicrometry measures the time it takes for ultrasound pulses to travel between piezoelectric crystals through a medium. Given a known, constant speed of sound through the medium, a distance can be recovered.
Electrical excitation of a piezoelectric crystal produces ultrasonic vibrations that propagate outwards and can be detected at another crystal. A typical signal observed by the receiving crystal (Fig. 1A) is as follows: in chronological order, there is a excitation artifact (a consequence of the electronics), followed by a period of silence (as the ultrasound pulse propagates), followed by an oscillation of increasing intensity (when the ultrasound pulse arrives). The arrival time of the ultrasound pulse (Fig. 1B) is defined to be the earliest time at which the intensity of the signal meets a user-defined threshold (Fig. 2, top). [In reality, while such thresholds were used in older sonomicrometers to determine arrival times, the Sonometrics sonomicrometers use a more sophisticated triggering protocol (Vesely and Smith, 1998). However, as these thresholds are sufficient to explain the basic sonomicrometry principles we require, we will continue to use them for their simplicity.]
Mechanism and correction of ‘level-shift’ artifacts
However, as the magnitude of the ultrasonic vibrations can change over a recording period (as a result of changes in crystal orientation, for instance), it is possible to obtain one of several arrival times: the threshold may be met by the first, smallest ‘ridge’ of the oscillation; if not, it may be met by the second, slightly larger ridge; if not, perhaps the third, and so on. Thus, the arrival times may be delayed by a multiple of the oscillation period of the piezoelectric crystals. A recording that always ‘tracks’ the same ridge produces a distance trace that is smooth and continuous. But when there is a shift in the ‘tracking’ of the ultrasound pulse from one ridge to another, the result is a jump discontinuity in the trace, where the measured distances are suddenly displaced by some constant distance but otherwise continue to accurately mirror changes in the distance signal (Fig. 2, bottom).
These discontinuity artifacts have been termed level-shifts, and are the only type of artifact addressed by the automated procedure. The idea is that, because a level-shift only introduces a constant displacement to the trace, the true distances can be recovered simply by shifting back the affected portion of the trace in order to recover a smooth, continuous trace. We use the term level-shift to refer to the discontinuities, and not the displaced portions of the trace they cause.
Complications to the correction of level-shift artifacts
There are several caveats to the simple correction of level-shifts we have just described. Caveat 1: in the presence of random noise, the displacement by which a level-shift should be corrected has some uncertainty. Therefore, every correction of a level-shift may introduce some error. Caveat 2: data displaced by level-shifts may not precisely mirror the original. One reason for this is that there is a range of times at which a ridge could meet the detection threshold. Caveat 3: there are other discontinuity artifacts distinct from level-shifts in the sense that the data following these discontinuities are completely unrelated to the ‘true’ data. This produces nonsensical data, which we view as a gap in the recording that contains no distance information. Suitably, these artifacts have been termed ‘dropouts’. The discontinuities associated with dropout artifacts must be distinguished from level-shifts, because correcting dropouts as if they were level-shifts introduces nonsense into the trace.
Methods of the automated procedure used to correct level-shifts in the software tool
Assumptions and scope of the automated procedure
The automated procedure operates under the assumption that the only artifacts in the distance trace are discontinuities produced by level-shifts; that is, we assume that the trace is broken into segments by level-shifts, where each segment is associated with a constant distance by which it has been (uniformly) displaced from its ‘true’ value. To address random noise (caveat 1) and, at least partially, the inexactness of level-shifts (caveat 2), we require a tolerance level to be defined (in mm) by the user. Nonsensical artifacts (caveat 3), and other artifacts (see the software's documentation), are not accounted for by the automated procedure; the user must identify them and remove them manually, or must otherwise verify that they have not adversely affected the procedure.
The distance trace data are assumed to be a time series; that is, a sequence of distances spaced evenly in time. From this time series, we may form the series of differences: the slopes of the lines joining the points of the original series.
The automated procedure requires as input a list of level-shifts describing the times at which the level-shifts occurred and their associated displacements. In the software tool, this list is produced by a separate level-shift labelling procedure. Like previous methods (Dione et al., 1997), the level-shifts are ‘detected by the first and second order derivatives’. More details on the labelling procedure can be found in the software's documentation.
The main method used to mitigate errors while correcting level-shifts
The main idea of the automated procedure is that there are only a finite number of ‘levels’ to which level-shifts may jump (in reasonable data, at least). Thus, a sequence of level-shifts will eventually return to a previously visited level. Under the aforementioned assumptions, this occurs exactly when the displacements of the level-shifts sum to zero, or, more practically, when they sum to within the user-specified tolerance of zero. The automated procedure searches for and acts on such groups of level-shifts, which we will call ‘zero-sum groups’. The process of correcting zero-sum groups is illustrated in Fig. 3, in which the representation of level-shifts has been simplified so that their displacements match exactly with one another, without error.
But why bother to search for these groups of level-shifts? Why not simply handle each level-shift individually, e.g. by recovering its slope from interpolation of the surrounding trace? Because the correction of each level-shift introduces some error that affects the relative positioning of the halves of the trace that lie before and after the level-shift; as a result, traces with more noise or many level-shifts will probably drift over time, in a random walk, from the accumulation of these small errors.
To correct this zero-sum group, we assign the level-shifts new displacements: we set the displacement of the first level-shift equal to the error () and set the displacement of the second level-shift to zero (). This ‘redistribution’ operation has the effect of taking the portion of the trace lying between the two level-shifts and then shifting it downwards to a new position such that the second level-shift is completely eliminated. Because of the error , the new position of this intermediary region may not be precisely correct.
However, the total change in displacement brought about by this operation is zero: we have added a displacement of −1.00 mm to the first level-shift and another equal but opposite displacement of +1.00 mm to the second. Therefore, the operation changes the position of only the intermediary region, and leaves the rest of the trace untouched. Thus, any inaccuracies caused by the error are confined to this intermediary region. This approach helps to reduce the aforementioned accumulation of error.
We can apply the same procedure to handle zero-sum groups containing more than two level-shifts. Let a zero-sum group contain n level-shifts with displacements d1, d2, … , dn. We assign the first level shift a displacement of , while the others are assigned displacements of zero; that is, . As before, because the total change in displacement caused by this operation is zero, the operation only affects the portion of the trace within the span of the level-shifts, thereby reducing the accumulation of error.
Additional aspects of level-shift correction
Of course, the ‘true’ displacement of a level-shift might not be zero, e.g. when a level-shift occurs during a period of quick movement. Therefore, we do not act on the ‘raw’ displacement of a level-shift but on the difference of its displacement from a target slope estimated from the surrounding trace. To compute this target slope, we take several slope segments on each side of the level-shift (4 each, for 8 total), exclude other level-shifts, and take the median of the remaining slopes to be the target slope, but only if a Wilcoxon signed-rank matched-pair test (where the slopes of the segments are paired with zeros) rejects its null hypothesis at α=0.10; otherwise, the target slope is set to zero. This method is intended to be conservative so that it avoids estimating slopes in noisy data (where it may make inaccurate estimates).
Furthermore, we would like to constrain zero-sum groups to be more ‘natural’. Level-shifts that occur in close time proximity, and follow after each other directly, are intuitively more likely to form a proper ‘match’ than those that do not. Therefore, we constrain zero-sum groups of level-shifts to be contiguous sub-sequences of level-shifts (that is, a zero-sum group must not ‘skip over’ any level-shifts), and stipulate that zero-sum groups spanning shorter intervals of time are considered before those that span longer intervals. Additionally, as reasonable data should only contain a finite number of ‘levels’, there should be a maximum number of back-to-back level-shifts that do not form a zero-sum group; accordingly, we place an upper limit to the size of a zero-sum group (8 level-shifts).
Note, however, that we are not able to completely eliminate the uncertainty and error associated with the correction of level-shifts (caveats 1 and 2) because the ‘redistribution’ of displacements merely restricts the error to a smaller portion of the trace. Therefore, traces requiring more frequent and difficult corrections should generally be less accurate, and thus this artifact correction procedure should not be considered a substitute for clean, artifact-free traces obtained from a superior experimental technique.
RESULTS AND DISCUSSION
Here, we demonstrate the use of the software tool to correct small portions of two distance traces. The correction of the first trace (Fig. 4) is unambiguous and is representative of the typical process of correction using the software tool. The correction of the second trace (Fig. 5) is performed merely to showcase the capabilities of the software tool; in practice, traces as poor as the second example should probably not be corrected because of the risk of unknowingly introducing errors.
Demonstration of the software tool on a typical artifact-laden trace
The first trace (Fig. 4) records distances between two crystals embedded in the medial gastrocnemius muscle of a rabbit. The trace records the active contraction of the medial gastrocnemius (induced by electrical stimulation). Fig. 4A shows the raw trace (as seen through the software tool's user interface) with level-shifts highlighted in alternating yellow and magenta. While there are many level-shifts, the correction of this trace is unambiguous: we can see that the trace merely switches back and forth between two ‘levels’.
We begin correction with the application of the automatic procedure, which handles all but two level-shifts (Fig. 4B). The modified segments of the trace have been highlighted in alternating white and cyan. To complete the corrections, we manually translate the portion of the trace between the two remaining level-shifts according to our judgement (Fig. 4C). This operation leaves the first level-shift with significant residual error. It is this large error that prevented the automated procedure from processing the last two level-shifts. (In this case, we have opted to perform the correction ourselves, judging this error to be tolerable for our purposes.) We then compare our corrections with the uncorrected version of the trace, superimposed in magenta, and with the artifact-free ‘twin trace’ (the distance trace obtained by swapping the transmitting and receiving roles of the crystal pair), superimposed in green (Fig. 4C). Our corrections are shown to be consistent with the twin trace.
Demonstration of the software tool on a very low-quality trace
The second trace (Fig. 5) is taken from a dry-run experiment in which crystals were embedded into a false vertebral artery (tubing filled with ultrasound gel), which was stretched in response to chiropractic manipulation of a model head and neck. We selected a portion of the worst salvageable trace so that the raw trace (Fig. 5A) is riddled with artifacts. The worst portions of the distance trace traverse six different ‘levels’ and have level-shifts between almost every data point.
Because of the unusually poor quality of this trace, we begin by adjusting the level-shift labelling parameters (not shown). We then apply the automated procedure, which leaves three level-shifts (Fig. 5B). These three level-shifts are corrected manually by setting their displacements to estimates of the slope of the surrounding trace (Fig. 5C). Finally, we compare our corrections with the uncorrected version of the trace, superimposed in magenta (also Fig. 5C).
While the corrected trace is compatible with the other (artifact-free) traces from its recording, we cannot directly verify the accuracy of our corrections because of the absence of signal on the twin trace. In this case, it is not feasible to guarantee that no errors were introduced in the correction of this poor-quality trace.
Processing of sonomicrometry data often requires the correction of artifacts, but the procedures for such corrections are not reported in detail in the literature. To address this issue, we have developed, and made publicly available, a software tool and guidelines for performing such corrections. We hope that the materials we have provided will help to improve the reproducibility of sonomicrometry data processing by providing a point of reference.
Thanks to T. R. Leonard, B. R. MacIntosh, S. Sibole and I. C. Smith for their critical reading of the manuscript, to L. Gorrell and C. Waters-Banker for the use of their data, to A. Sawatsky for his technical assistance, and to L. Gorrell and R. Madden for their assistance in testing the software tool.
Conceptualization: A.W.C.; Software: A.W.C.; Writing - original draft: A.W.C.; Writing - review & editing: A.W.C., W.H.; Supervision: W.H.; Funding acquisition: W.H.
This work was supported by grants from Natural Sciences and Engineering Research Council of Canada, the Canada Research Chair Program, and the Killam Foundation.
The authors declare no competing or financial interests.