Align Wave
% Time-align two wave signals by shifting wav2 to be aligned with wav1, using cross correlation.
% The inputs 'wav1' and 'wav2' can be either a string of filename or a
% struct in a format such that : 'wav1.s' contains the wave signal in a nSample x 1 vector and 'wav1.sr' is the sampling rate.
%
% All channels in input wav1, wav2 will be averaged before cross correlation comparison.
% The output 'y', 'sr' are modified signals for time-aligned wav2.
% The time of wav1 is alway preserved.
% 'delayT': "Delay" of wav2 with respect to wav1, which means wav2 was "sampled later" (i.e., signals of interest appear "earlier") than wav1 in 'delayT' sec,
% or earlier (if delayT is negative. i.e., signals of interest appear "later") than wav1 in '- delayT' sec.
% 'ifplot': if you want to plot the aligned results. Default = 0.
% 'SaveAsFName' : save the time-aligned wav2 to a specified file. Set to 0 if you don't want to save a file.
% 'resampleSR' : resampling the signals to a common resampling rate. Set to 0 to use the lower sampling rate in wav1 and wav2. Default = 8000;
% 'StartCompareTimeInWav1' : time point (sec.) in wav1 at which the CC comparison starts. {default = 0 sec.}
% 'corr_coeffs' : correlation coefficients.
%
% DEMO:
% StartCompareTimeInWav1 =1.9; % comparing starts from 1.9 sec in wav1;
% [y, sr, delayT] = AlignWave('1.wav', '2.wav', 1, 'alignedwav2.wav', [], StartCompareTimeInWav1);
%
% Weirong Chen 03-23-2014
% Modified Feb-23-2017
Cite As
Wei-Rong Chen (2024). Align Wave (https://www.mathworks.com/matlabcentral/fileexchange/50473-align-wave), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- Signal Processing > Signal Processing Toolbox > Transforms, Correlation, and Modeling > Correlation and Convolution >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.