% This is a MATLAB code to generate Figure 3 of % Vocal development throught morphological computation % Zhang YS, Ghazanfar AA (2018) % YSZ 01/22/2018 % Plot Figure 3B % integrator parameter dt = 0.01; % time increment N = 3000; % scale the time dur = 8; Fs = N/dur; % CPG model parameter b1 = 4; % coupling coef. 2->1 b2 = 0.01; % coupling coef. 1->2 c1 = [3.4 3.1 2.8]; % time constant for x1 c2 = 25; % time constant for x2 % initial conditions x0 = [-0.1;0;-.1;0]; % parameter for pressure conversion p0 = 1; P = 0.1; % ramping, discard the first 2s prct = 0.25; dmin = dur*prct; I = zeros(1,round(N*prct)); % input I = [I linspace(0,1,N-round(N*prct))]; % ramping input parameter to x1 a1min = 0; a1max = 0; % ramping input parameter to x2 a2min = -1; a2max = 1; a1 = I*(a1max-a1min)+a1min; a2 = I*(a2max-a2min)+a2min; figure set(gcf,'position',[-500,100,800,800]) % plot ramping input subplot(411) line([0 dur-dmin],[0 1]) set(gca,'XTick',[]) set(gca,'XTicklabel',[]) box off set(gca,'Fontsize',16) set(gca,'Linewidth',1) ylabel('I (a.u.)') axis tight for i = 1:length(c1) % solve ODE x = coupled_cpg_solver(x0,a1,a2,b1,b2,c1(i),c2,N,dt); x = x(:,round(N*prct)+1:end); % convert to pressure a = tansig((x(1,:)*p0))*P; % smooth factors alpha = 0.16; nwin = alpha*Fs/2+1; gwin = gausswin(nwin,alpha); gwin = gwin/sum(gwin); w = conv(a,gwin,'same'); subplot(4,1,i+1) % plot pressure when c1=2.8 plot((0:length(w)-1)/Fs,w,'k') hold off set(gca,'XTicklabel',[0 1 2 3 4 5 6]) box off set(gca,'Fontsize',16) ylabel('p (a.u.)') set(gca,'Linewidth',1) xlim([dmin dur]) if i==4 xlabel('Time (s)') end axis tight end set(subplot(4,1,1),'Position',[0.15,0.80,0.8,0.18]) set(subplot(4,1,2),'Position',[0.15,0.5883,0.8,0.18]) set(subplot(4,1,3),'Position',[0.15,0.3667,0.8,0.18]) set(subplot(4,1,4),'Position',[0.15,0.15,0.8,0.18]) %% % Plot Figure E,G % Increase N1 and N2 to plot Figure 3D % proportion simulation a1min = 0; a1max = 0; a2min = -1; a2max = 1; b1 = 4; b2 = 0.015; c1min = 2; c1max = 3; c2 = 25; N1 = 100; N2 = 20; I = linspace(0,1,N1); a1 = linspace(a1min,a1max,N1); a2 = linspace(a2min,a2max,N1); c1 = linspace(c1min,c1max,N2); N1 = length(I); N2 = length(c1); L = 2000; dt = 0.01; Fs = 3000/8; f=Fs*(0:L/2)/L; % initial condition x0 = [-0.1;0;-.1;0]; % bifurcation creteria bifur1 = NaN(N1,N2); bifur2 = NaN(N1,N2); parfor l = 1:N2 mat = zeros(N1,L,4); mat1 = []; mat2 = []; for i = 1:N1 for j = 1:L if j == 1 pre = x0; for k = 1:500 % discard the first 500 k1=dt*coupledcpg(pre,a1(i),a2(i),b1,b2,c1(l),c2); k2=dt*coupledcpg(pre+k1/2,a1(i),a2(i),b1,b2,c1(l),c2); k3=dt*coupledcpg(pre+k2/2,a1(i),a2(i),b1,b2,c1(l),c2); k4=dt*coupledcpg(pre+k3,a1(i),a2(i),b1,b2,c1(l),c2); nxt = pre + k1/6+k2/3+k3/3+k4/6; pre = nxt; end end k1=dt*coupledcpg(pre,a1(i),a2(i),b1,b2,c1(l),c2); k2=dt*coupledcpg(pre+k1/2,a1(i),a2(i),b1,b2,c1(l),c2); k3=dt*coupledcpg(pre+k2/2,a1(i),a2(i),b1,b2,c1(l),c2); k4=dt*coupledcpg(pre+k3,a1(i),a2(i),b1,b2,c1(l),c2); nxt = pre + k1/6+k2/3+k3/3+k4/6; mat(i,j,:) = nxt; pre = nxt; end % get spectrum yy = fft(mat(i,:,1)); P = abs(yy/L); P1 = P(1:L/2+1); P1(2:end-1)=2*P1(2:end-1); % get weighted mean of frequency [~,locs]=findpeaks(P1,'minpeakheight',prctile(P1,99.5)); mat1 = [mat1 f(locs)*P1(locs)'/sum(P1(locs))]; flg1 = find(f(locs)<=7); flg2 = find(f(locs)>7); % get the ratio of fast and slow oscillations if (~isempty(flg1))&&(~isempty(flg2)) pp1 = max(P1(locs(flg1))); pp2 = max(P1(locs(flg2))); pratio = pp1/pp2; elseif (~isempty(flg1))&&(isempty(flg2)) pp1 = max(P1(locs(flg1))); pratio = pp1/median(P1); elseif (isempty(flg1))&&(~isempty(flg2)) pp2 = max(P1(locs(flg2))); pratio = median(P1)/pp2; else pratio = NaN; end mat2 = [mat2 10*log10(pratio)]; end bifur1(:,l) = mat1'; bifur2(:,l) = mat2'; end %% xxx={I,c1}; bf1s = csaps(xxx,bifur1,0.9995,xxx); bf2s = csaps(xxx,bifur2,0.9995,xxx); bifur3 = ones(size(bifur1)); bifur3(bf1s<=4&bf2s>5)=0; % very slow oscillations are contact calls bifur3(bf2s<3|bf1s>6)=2; % very fast oscillations are twitters bifur3 = fliplr(bifur3); % to plot bifurcation diagram, increase N1 to 1000 and N2 to 200 % figure % % bifurcation % imagesc(bifur3') % axis xy p1 = zeros(1,N2); p2 = zeros(1,N2); for i = 1:N2 p1(i) = length(find(bifur3(:,i)==2))/N1; p2(i) = length(find(bifur3(:,i)==1))/N1; end p0 = 1-p1-p2; p1s = csaps(c1,p1,0.999,c1); p2s = csaps(c1,p2,0.999,c1); p0s = csaps(c1,p0,0.999,c1); figure(11) subplot(2,1,1) plot(c1,p1,'o') hold on plot(c1,p1s) plot(c1,p2,'o') plot(c1,p2s) hold off xlabel('Time constant') ylabel('Proportion') box off ylim([0 0.4]) title('trill and twitter') subplot(2,1,2) plot(c1,p0,'o') hold on plot(c1,p0s) hold off xlabel('Time constant') ylabel('Proportion') ylim([0.5 1]) box off title('contact call') %% % ode integrator using RK-4 function x = coupled_cpg_solver(x0,a1s,a2s,b1,b2,c1,c2,N,dt) x = zeros(4,N); x(:,1) = x0; for i = 2:N a1 = a1s(i) ; a2 = a2s(i); yy = x(:,i-1); k1=dt*coupledcpg(yy,a1,a2,b1,b2,c1,c2); k2=dt*coupledcpg(yy+k1/2,a1,a2,b1,b2,c1,c2); k3=dt*coupledcpg(yy+k2/2,a1,a2,b1,b2,c1,c2); k4=dt*coupledcpg(yy+k3,a1,a2,b1,b2,c1,c2); x(:,i)=yy+k1/6+k2/3+k3/3+k4/6; end end % odes function r = coupledcpg(x,a1,a2,b1,b2,c1,c2) r1 = x(2); r2 = (a1 - x(1) + x(2)/c1 - x(1)^2*x(2)/c1 + b1*x(4))*c1^2; r3 = x(4); r4 = (a2 - x(3) + x(4)/c2 - x(3)^2*x(4)/c1 + b2*x(2))*c2^2; r = [r1;r2;r3;r4]; end