title('Histogram')
xlabel('Vibration amplitude')
ylabel('Frequency of occurance')
%==============================================================
% Calclation of the rms value of the data using a frame size of 256
%==============================================================
no_of_frames=floor(length(vib)/256);
for i=1:no_of_frames
data=vib((i-1)*256+1:i*256);
rms(i)=sqrt(mean(data.^2));
end
%figure
subplot(223)
plot(rms)
xlabel('Number of frames')
ylabel('RMS value')
%==============================================================
% Calclation of the wavelet transform and then selecting the signal in the
% frequency band of value 32-64Hz (can be further fine tuned)
%==============================================================
[c l]=wavedec(vib,4,'db4');
a = appcoef(c,l,'db4',4);
[cd1,cd2,cd3, cd4] = detcoef(c,l,[1 2 3 4]);
d4 = wrcoef('d',c,l,'db4',4);
%figure
subplot(224)
plot(t,vib)
xlabel('Time (seconds)')
ylabel('Amplitude')
hold on
plot(t,d4,'r')
legend('Original Vibration Amplitude','Vibration Amplitude of most dominant frequency (3264Hz)')
%==============================================================
% Calclation of the rms value of the data using a frame size of 61441
%==============================================================
no_of_frames=floor(length(vib)/61441);
for i=1:no_of_frames
data=vib((i-1)*61441+1:i*61441);
rms(i)=sqrt(mean(data.^2));
end
B=band_power;
m1=max(B);
l1=find(B==m1);
B(l1)=0;
m2=max(B);
l2=find(B==m2);
j=j+1;
PD(j,1)=m1;
if l1<11;
PD(j,2)=1;
elseif l1>10 && l1<21
PD(j,2)=2;
else
PD(j,2)=3;
end
PD(j,3)=m2;
if l2<11
PD(j,4)=1;
elseif l2>10 && l2<21
PD(j,4)=2;
else
PD(j,4)=3;
end
%sprintf('%f %f %f %f %s', PD(j,:), Name)
%pause
end
for i=1:length(PD)
sprintf('%f %f %f %f %s', PD(i,:), Name(i,:))
end
xlswrite('E:\final experiment\Vibration\chain saw\data', PD)