a=arduino('COM9');
servoAttach(a,7);
servoAttach(a,8);
%servoAttach(a,9);
servoWrite(a,7,45);
servoWrite(a,8,45);
song=audioread('booyah2.wav');
play=audioread('booyah.wav');
song=abs(song);
song=song*(1/0.5);
music=song(1:312033);
%plot(music);
j=1;
while(j<100)
for i=(1+j):(312033-j)
    if music(i-j,1)<music(i,1)&&music(i,1)>music(i+j,1)
        nusic(i,1)=music(i,1);
    else 
        nusic(i,1)=0;
    end
end
j=j+1;
music=nusic;
end
plot(music);
sound(play,44100);
p=1;
while p<312033
    if music(p,1)>0.6
        s=30*music(p,1);
        s=round(s*10);
        s=s/10;
        servoWrite(a,8,45+s);
        servoWrite(a,7,45+(s*3));
        pause(0.001);
        p=p+1;
    else
        m=90*music(p,1);
        m=round(m*10);
        m=m/10;
        servoWrite(a,7,45+m);
        servoWrite(a,8,45);
        pause(0.001);
        p=p+1;
    end
end

