Skip to content. | Skip to navigation

Personal tools
Log in
Sections
You are here: Home Resources Behavior Matlab functions track_vocal_changes

track_vocal_changes

The script was originally developed to track significant vocal changes across the developing syllable, where syllables were rows in the matrix (called 'm_tot_pm2') and columns corresponded to milliseconds. It could be used to identify any significant changes that occur over a user-specified frame (number of rows in any particular millisecond). To identify the changes, all rows in the matrix must be locally realigned. The script calls function 'local_realignment' to perform local realignment using best cross-correlation method (see 'local_realignment' comments).

track_vocal_changes.m — Objective-C source code, 7 kB (7925 bytes)

File contents

% track_vocal_changes

% Written by Primoz Ravbar Sep 2011

% The script was originally developed to track significant vocal changes
% across the developing syllable, where syllables were rows in the matrix (called 'm_tot_pm2') and columns corresponded to milliseconds.
% It could be used to identify any significant changes that occur over a user-specified frame (number of
% rows in any particular millisecond). To identify the changes, all rows in
% the matrix must be locally realigned. 
% The script calls function 'local_realignment' to perform local realignment using best
% cross-correlation method (see 'local_realignment' comments). 

% input: load a matrix called 'm_tot_pm2' (for example, aligned acoustic features
% of syllables should be rows in the matrix)
% output: R_plot -- matrix of significant changes with coef r-values.

% Functiones called: smooth2_function, local_realignment


get_ms=1; % get_ms=1 if local alignment is to be computed. This should be chosen if the matrix output of 'local_realignment' called 'ms1' does not exist (Default setting)
get_frame_matrix=1; % get_frame_matrix=1 if the following outputs of 'local_realignment' do not exist: 'frame', 'slice_realigned' (default setting) Time consuming!

% if matrix 'ms1' exists select get_ms=0;
% if matrix 'frame' exists but not 'ms1' select get_ms=1 and
% get_frame_matrix=0

% for local realignment select tracking frame 5 milliseconds before the
% beginning of the segments and 5 milliseconds before the end of the
% rows you wish to realign:
tracking_frame=[5,230];tracking_frame_width=30;tracking_frame_step=1;window_x=20;window_y=20;% g93_standard
% tracking_frame_width is the length of a window on which
% cross-correlations will be performed. tracking_frame_step should equal 1;
% window_x, window_y are hunning somoothing filter settings (use 10-30 ms)

corss_correlate=0;

%set the threshold coef of regression R_threshold; window -- size of data
%to correlate; step_correlation should be 1 to compute correlations for
%each millisecond; last slice should equal the number of rows in the raw
%data matrix.
R_threshold=0.96;window=30;step_correlations=1;last_slice=250;%g93_standard

clear Px;
clear r_metrix;
clear P_plot;
clear R_plot;
clear Dir_plot;

if get_ms==0;
    corss_correlate=0;
   data=ms1;
   size_s=size(data);
   tracking_frame=[1,size_s(2)];
   
   step=1;
end

if get_ms==1;

    raw_data=m_tot_pm2;
    [data]=smooth2_function(raw_data, window_x, window_y); 
    size_s=size(data);
    step=tracking_frame_step;


    
    clear ms1;
    clear ms2;
    clear slice_realinged_cell;
    clear slice_realigned;
    clear r_metrix;

    
   if get_frame_matrix==1; 
       clear frame_matrix;
    for n=tracking_frame(1):step:tracking_frame(2);
    
         [slice_realigned, max_r, frame]=local_realignment(n, n+tracking_frame_width, data);
         frame_matrix(:,n)=frame(:,1);
         
         slice_realinged_cell{2,n}=slice_realigned; 
         str=['Computing local alignments....' num2str(round(n/tracking_frame(2)*100)) ' % complete'];
         disp(str)
    
    end



        for si=tracking_frame(1):step:tracking_frame(2);
            si
             for sj=tracking_frame(1):step:tracking_frame(2);
                slice_realigned_si=slice_realinged_cell{2,si};
                ms1(:,si)=slice_realigned_si(:,tracking_frame_width/2);
                slice_realigned_sj=slice_realinged_cell{2,sj};
                ms2(:,sj)=slice_realigned_sj(:,tracking_frame_width/2);
             end
        end

   end
     
   if get_frame_matrix==0;  
       size_f=size(frame_matrix);
        for si=tracking_frame(1):step:tracking_frame(2);
            si
             for fr=1:size_f(1);
                
                ms1(fr,si)=data(fr,frame_matrix(fr,si)+tracking_frame_width/2);
               
                
             end
        end
   end
       
       
       

end

x=zeros(1,window+1);for n=1:window+1;x(n)=i+n;end

size_s=size(ms1); %change the size (!!!)

for i=1:step_correlations:size_s(1)-window-1

   for si=tracking_frame(1):step:tracking_frame(2);
       [R,P] = corrcoef(x(1:window),ms1((i:i+window-1),si));
       Px(i+window,si)=P(1,2);
       Rx(i+window,si)=R(1,2);
      if Px(i+window,si)<0.00005; P_plot(i+window,si)=0.25; else P_plot(i+window,si)=0;end
      if Px(i+window,si)<0.000005; P_plot(i+window,si)=0.5;end
      if Px(i+window,si)<0.0000005; P_plot(i+window,si)=1;end
      
      if Rx(i+window,si)< (-1)*R_threshold; R_plot(i+window,si)=-abs(Rx(i+window,si)^2); else R_plot(i+window,si)=0;end
      %if Rx(i+window,si)< 0.000005; R_plot(i+window,si)=0.5;end
      if Rx(i+window,si)> R_threshold; R_plot(i+window,si)=abs(Rx(i+window,si)^2);end
      
      %if ms1(i+window,si) < ms1(size_s(1)-40,si) && R_plot(i+window,si)==1; Dir_plot(i+window,si)=1;else Dir_plot(i+window,si)=0;end
      %if ms1(i+window,si) > ms1(size_s(1)-40,si) && R_plot(i+window,si)==1; Dir_plot(i+window,si)=-1;end
      %if ms1(i+window,si) > ms1(size_s(1)-40,si) && R_plot(i+window,si)==-1; Dir_plot(i+window,si)=1;end
      %if ms1(i+window,si) < ms1(size_s(1)-40,si) && R_plot(i+window,si)==-1; Dir_plot(i+window,si)=-1;end
      
      if ms1(i+window,si) < ms1(last_slice,si) && R_plot(i+window,si)>0; Dir_plot(i:i+window,si)=abs(Rx(i+window,si)^2);else Dir_plot(i+window,si)=0;end
      if ms1(i+window,si) > ms1(last_slice,si) && R_plot(i+window,si)>0; Dir_plot(i:i+window,si)=-abs(Rx(i+window,si)^2);end
      if ms1(i+window,si) > ms1(last_slice,si) && R_plot(i+window,si)<0; Dir_plot(i:i+window,si)=abs(Rx(i+window,si)^2);end
      if ms1(i+window,si) < ms1(last_slice,si) && R_plot(i+window,si)<0; Dir_plot(i:i+window,si)=-abs(Rx(i+window,si)^2);end %0;end %
      
      if R_plot(i+window,si)~=9999; Diff_all_plot(i+window,si)= abs(ms1(last_slice,si) - ms1(i+window,si));else Diff_all_plot(i+window,si)=0;end % diff form target
      if R_plot(i+window,si)~=0; Diff_plot(i+window,si)= abs(ms1(last_slice,si) - ms1(i+window,si));else Diff_plot(i+window,si)=0;end % diff form target
      
      %R_plot(i+window,si)=Rx(i+window,si);
       Rsq_plot(i+window,si)=Rx(i+window,si)^2;
     
      %P_plot(i+window,si)=1-Px(i+window,si);
      
      if corss_correlate==1;
      
             if Px(i+window,si)<0.00005;
                         for sj=tracking_frame(1):step:tracking_frame(2);
          
           
           
                                 [Rd,Pd] = corrcoef(ms1(i:i+window-1,si),ms1(i:i+window-1,sj));Py=Pd(1,2);Ry=Rd(1,2);
           
                                      if Ry>0.50;r_metrix(si,sj,i)=0.50; else r_metrix(si,sj,i)=0.25; end;
                                      if Ry>0.75;r_metrix(si,sj,i)=0.75;end
                                      if Ry>0.95;r_metrix(si,sj,i)=1;end
           
             
                 
                             end
       
       
       
          
           
             end
           
                   
      
             if Px(i+window,si)>=0.00005;
                 for sj=tracking_frame(1):step:tracking_frame(2);
          
           
           
                         [Rd,Pd] = corrcoef(ms1(i:i+window-1,si),ms1(i:i+window-1,sj));Py=Pd(1,2);Ry=Rd(1,2);
           
                             if Ry>0.50;r_metrix_d(si,sj,i)=0.50; else r_metrix_d(si,sj,i)=0.25; end;
                             if Ry>0.75;r_metrix_d(si,sj,i)=0.75;end
                             if Ry>0.95;r_metrix_d(si,sj,i)=1;end
                           
                 end
              end
       
       
       
       
      end
      
      
      
   end
   
    str=['Computing correlations....' num2str(round((i/(size_s(1)-window-1))*100)) ' % complete'];
    disp(str)

end