Dan Ellis : Resources: Matlab:

SKEWVIEW - Tool to visualize timing skew between files

skewview is a Matlab script that can be used to visualize the timing skew between two sound files. It breaks both files up into a set of short pieces (by default 4 seconds long) performs a normalized cross-correlation between corresponding pieces, then plots the time of the peak of this correlation as a function of time within the file. If the files contain versions of the same signal, the peak of the correlation will usually indicate the relative timing skew (delay) between the two files. This can be used to check for such a skew/delay.

skewview supports a range of input sound file formats, including WAV and FLAC (the latter provided via an external flac binary).

Contents

Example usage

In the code below, we plot the timing skew between the two excerpted files, 20110221_1452+60.xr_lre.xxx.clean.flac (which is a clean source signal), and 20110221_1452+60.xr_lre.xxx.tsx300_tsx300.flac (which is the signal recorded after transmission across a radio link). The piecewise-constant time skew between the recordings is clearly shown. The (optional) later arguments in this case set the start and end times (in seconds) for the analysis.

skewview('20110221_1452+60.xr_lre.xxx.clean.flac','20110221_1452+60.xr_lre.xxx.tsx300_tsx300.flac','-start',0,'-end',60);
Reading 20110221_1452+60.xr_lre.xxx.clean.flac ...
Reading 20110221_1452+60.xr_lre.xxx.tsx300_tsx300.flac ...
Calculating short-time cross-correlation...
Plotting...
+++ SkewView v0.82 for 20110221_1452+60.xr_lre.xxx.tsx300_tsx300.flac
 ref=20110221_1452+60.xr_lre.xxx.clean.flac
 times start=0 end=60
 win=4 hop=0.5 maxlag=2 peakth=0.1
 Lin fit: t_targ = 0.980057 t_ref + 0.612
 MEDIAN LAG = -0.131 s, STDDEV = 0.256 s,  ABVTHRESH = 0.823

Optional arguments

Behavior is controlled by optional arguments specified as param/value pairs:

skewview -help
skewview v0.82 of 20130515
usage: skewview REFFILE TARGFILE [param value ...]
 where the param and value pairs can be:
-start <time>  start analysis at this point in the files (0)
-end   <time>  end analysis at this point in the files (end)
-disp  <0/1>   generate graphical representation (1)
-win   <time>  window length for xcorr analysis in sec (4.0)
-hop   <time>  hop between successive windows in sec (0.5)
-maxlag <time> largest lag time to consider (2.0)
-peakth <val>  xcorr threshold to be considered a match (0.1)
-initialdelay <time>  Center skew estimation around this delay (0.0)
-estinitialdelay <0/1> Estimate initial delay by xcorr (0)
-samplerate <rate_hz> Downsample signals before correlation (0 = none)
-fitthresh <factor>   Controls inclusion of outliers in lin fit (2.0)
-alignout <name> Name for time-warped output audio file ()
-pngout <name> Make a PNG-format screen dump of the plot (none)
-textout <name> Write a text file of <time skew> pairs (none)
-minspread <val>  Minimum spread of Y axis in plot, in sec (0.1)

Compiled target usage

Invoking the compiled target is the same as above, except without the punctuation e.g.

./run_skewview_prj.sh 20110221_1452+60.xr_lre.xxx.clean.flac 20110221_1452+60.xr_lre.xxx.tsx300_tsx300.flac -start 0 -end 60

Installation

This package has been compiled for several targets using the Matlab compiler. You will also need to download and install the Matlab Compiler Runtime (MCR) Installer. Please see the table below:

ArchitectureCompiled packageMCR Installer
32 bit Linux skewview_GLNX86.zip Linux MCR Installer
64 bit Linux skewview_GLNXA64.zip Linux 64 bit MCR Installer
64 bit MacOS skewview_MACI64.zip MACI64 MCR Installer

The original Matlab code used to build this compiled target is available at

 <http://labrosa.ee.columbia.edu/projects/skewview/>

All sources are in the package skewview-v0.82.zip.

Feel free to contact me with any problems.

Changelog

% 2013-05-15 v0.82  - fixed bug where maxlag > win caused crash.
%                   - took out check where mac version used slower xcorr.
%
% 2013-05-14 v0.81  - fixed bug where perfect time alignment caused crash
%                   - -initialxcorr renamed -estinitialdelay
%                   - fixed bug that gave incorrect offsets when
%                     new initialdelay was positive (with -estinitialdelay 1)
%
% 2013-05-05 v0.8   - Now STDDEV is reported relative to the best-fit
%                     line, so it can be very small even for tracks
%                     with a significant (but systematic) clock
%                     skew.
%                   - New flag -initialxcorr 1 will estimate a
%                     global time skew for the whole track,
%                     obviating the need for -initialdelay.
%
% 2013-04-08 v0.75  Added -minspread option to force a minimum
%                   y-axis range (rather than having it collapse to
%                   very small range for near-synchronous fits).
%
% 2013-03-07 v0.74  Interactive fixup of best-fit line!  Grab
%                   points at end to adjust the line; reports new
%                   lin fit parameters & sox command on mouse-up.
%
% 2013-01-24 v0.73  -alignout now works for both advance (via trim)
%                   and delay of output.  Shell script now handles
%                   filenames with spaces and special characters.
%                   Linear fitting in linfit.m now also excludes
%                   points with the top and bottom 10% of slopes to
%                   adjacent points (i.e., aiming for
%                   middle-80%-median slope).
%
% 2012-09-26 v0.72  Added -alignout, which causes it to report a
%                   sox command that generates a version of TARG
%                   that aligns to REF.
%
% 2012-09-24 v0.71  Added linear fit to report best offset and skew.
%                   Optimized calculcation of cross-correlation.
%
% 2011-09-09 v0.7 Incorporated new audioread to allow efficient
% access to parts of very large files; added help message in program.
%
% 2011-09-06 v0.6 Modified audio reading code to better handle
% large/high SR files.
%
% 2011-08-03 v0.5 Added version number in text report output.
%
% 2011-07-19 v0.4 Added -textout option to allow raw text file dump
% of local skew times.
%
% 2011-05-03 v0.3 Added -initialdelay to handle files with large
% default skews, and -samplerate to specify an optional lower
% sampling rate at which to perform analysis, to accommodate much
% larger maximum lags and total file durations without exhausting
% memory.
%
% 2011-04-19 v0.2 Added text report of mean and SD of skew, and
% multiple command-line options to control the various internal
% parameters
%
% 2011-03-15 v0.1 Initial release
%

Acknowledgment

This work was supported by DARPA under the RATS program via a subcontract from the SRI-led team SCENIC. My work was on behalf of ICSI.

Last updated: $Date: 2011/08/04 01:34:37 $ Dan Ellis dpwe@ee.columbia.edu