getting the delay/lag of Ultrasonic pulse velocity matlab -


i doing thesis needs ultrasonic pulse velocity(upv). upv can attained via machines data acquired didn't have upv tasked manually.

essentially in data have 2 channels, 1 transmitter transducer , receiver transducer.

we need time wave transmitter emitted , time arrives receiver.

using matlab, i've tried finddelay , xcorr doesnt quite right result.

here picture of points want get. plot of transmitter(blue) , receiver(red)

example input

so trying find 2 points in picture aid of matlab. 2 determine time , further upv. relatively new matlab user of great assistance.

here code have tried

[cc, lags] = xcorr(signal1,signal2);  d2 = -(lags(cc == max(cc))) / fs; 

@xenoclast hi there! far code used these.

close clc fs = input('input fs = '); t = 1/fs; l = input('input l = '); t = (0:l-1)*t; time = transpose(t); = input('input number of steploads = '); % construct test sequences %dataupv signal1 & datathesis signal2 m=1:i y1 = (dataupv(:,m) - mean(dataupv(:,m))) / std(dataupv(:,m)); y2 = (datathesis(:,m) - mean(datathesis(:,m))) / std(datathesis(:,m)); offset = 166; tt = time; % correlate 2 sequences [cc, lags] = xcorr(y2, y1,); % find in4dex of maximum [maxval, maxi] = max(cc); [minval, mini] = min(cc); % use index obtain lag in samples lagsamples(m,1) = lags(maxi); lagsamples2(m,1) = lags(mini); % plot again without timebase verify visually end      

the resulting value off 70 samples compared when visually inspect waves. lag resulted in 244 visually should 176 here data(there 19 sets of data used 1st column) https://www.dropbox.com/s/ng5uq8f7oyap0tq/datatrans-dec-2014.xlsx?dl=0 https://www.dropbox.com/s/1x7en0x7elnbg42/datarec-dec-2014.xlsx?dl=0

your example code doesn't specify fs don't know sure i'm guessing it's issue of sample rate(s). examples of cross correlation start out constructing test sequences according specific sample rate call fs, not confused frequency of test tone, may see called fc.

if construct test signals in terms of fs , fc works fine when real data instrument give data , timebase 2 vectors, have work out sample rate timebase. may not same operating frequency or components of signal, confusion easy here.

but sample rate required in second part of problem, work out offset in time. first have offset in samples , that's lot easier verify.

your example give offset in samples if remove '/ fs' term , can verify plotting 2 signals without timebase , inspecting sample positions.

i'm sure you've looked @ dozens of examples here's 1 attempts not confuse issue tying sample rates - you'll note specified 'sample rate' is, it's tied samples (although if treat 5 in y1 definition frequency in hz able infer one).

% construct test sequences offset = 23; tt = 0:0.01:1; y1 = sin(2*pi*5*tt); y2 = 0.8 * [zeros(1, offset) y1];  figure(1); clf; hold on plot(tt, y1) plot(tt, y2(1:numel(tt)), 'r')  % correlate 2 sequences [cc, lags] = xcorr(y2, y1);  figure(2); clf; plot(cc)  % find index of maximum [maxval, maxi] = max(cc);  % use index obtain lag in samples lagsamples = lags(maxi);  % plot again without timebase verify visually figure(3); clf; hold on plot(y1) plot(y2, 'r') plot([offset offset], [-1 1], 'k:') 

once you've got offset in samples can deduce required conversion factor, if have timebase data instrument inverse of diff of 2 consecutive entries give you.

update

when correlate 2 signals can visualise overlaying them , summing product of corresponding elements. gives single value. move 1 signal sample , again. continue until have done @ every possible arrangement of 2 signals.

the value obtained @ each step correlation, 'lag' computed starting 1 signal way on left , other overlapping 1 sample. slide second signal way on until it's overlapping other end sample. hence number of values returned correlation related length of both original signals, , relating given point in correlation output, such max value, arrangement of 2 signals produced requires calculation involving lengths. xcorr function makes easier outputting lags variable, tracks alignment of 2 signals. people may talk offset watch out that.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -