clear all

data = sign(wavread('Pulswav-Demo.wav'));

l=0;
prev_l=0;
r=0;
prev_r=0;
tdata = zeros(size(data));

for k = 2:size(data, 1)
    
   l = l + 1;
   tdata(k, 1) = prev_l;
   if (data(k-1,1) == -1) * (data(k,1) == 1)
       prev_l = l;
       l = 0;
       k
   end
   
   r = r + 1;
   tdata(k, 2) = prev_r;
   if (data(k-1,2) == -1) * (data(k,2) == 1)
       prev_r = r;
       r = 0;
   end
   
end

plot(tdata(:, 1), tdata(:, 2))