1,先听了一遍testshort.wav,都是格拉格拉的声音,听不出个所以然来。
2,http://zhidao.baidu.com/link?url=hWD9AHfEHm0W7w5UPzK4FILxuzWh-g0UMrs3NE2Kkvjn-R1iLC5qx4yIcUBB9v61Y16_c5AOUNNHDlevYtZnB_
[y,Fs,bits]=wavread('testshort.wav');%读出信号,采样率和采样位数。
sigLength=length(y);
t=(0:sigLength-1)/Fs;
figure;plot(t,y);xlabel('Time(s)');
截取其中任意一个脉冲,展开观察其形状并求包络(请保存图片);
我先取10s~15s
t1=t(t(1,:)<=15);
t2=t1(t1(1,:)>=10);
t3=t(t(1,:)<=10);
y1=y(length(t3):length(t1));
plot(t2,y1);
这是10~15s那一段。
再看11到11.25
t1=t(t(1,:)<=11.25);
t2=t1(t1(1,:)>=11);
t3=t(t(1,:)<=11);
y1=y(length(t3):length(t1));
plot(t2,y1);
放大了看看:
再看11.08到11.1
t1=t(t(1,:)<=11.1);
t2=t1(t1(1,:)>=11.08);
t3=t(t(1,:)<=11.08);
y1=y(length(t3):length(t1));
plot(t2,y1);
再看11.084到11.091
t1=t(t(1,:)<=11.091);
t2=t1(t1(1,:)>=11.084);
t3=t(t(1,:)<=11.084);
y1=y(length(t3):length(t1));
plot(t2,y1);
注意!!!!!
这里开始出问题了,
估计是时间到了精确度的极限了?
差了一位:
往后错一位,应该无伤大雅;
t1=t(t(1,:)<=11.091);
t2=t1(t1(1,:)>=11.084);
t3=t(t(1,:)<=11.084);
y1=y(length(t3):length(t1)-1);
plot(t2,y1);
求包络?
把极值点用光滑曲线连接。
1,怎么求极值点?
检查附近若干个点的增减性
[y,Fs,bits]=wavread('testshort.wav');%读出信号,采样率和采样位数。
sigLength=length(y);
t=(0:sigLength-1)/Fs;
figure;plot(t,y);xlabel('Time(s)');
t1=t(t(1,:)<=11.091);
t2=t1(t1(1,:)>=11.084);
t3=t(t(1,:)<=11.084);
y1=y(length(t3):length(t1)-1);
jizhi1={};
indexcell={};
for i=1:length(y1)
if i>=6&&i<=length(y1)-6
% if (y1(i)>=y1(i-5)&&y1(i)>=y1(i-4)&&y1(i)>=y1(i-3)&&y1(i)>=y1(i-2)...
% &&y1(i)>=y1(i-1)&&y1(i)>=y1(i-1)&&y1(i)>=y1(i+1)&&y1(i)>=y1(i+2)...
% &&y1(i)>=y1(i+3)&&y1(i)>=y1(i+4)&&y1(i)>=y1(i+5))||(y1(i)<=y1(i-5)&&y1(i)<=y1(i-4)&&y1(i)<=y1(i-3)&&y1(i)<=y1(i-2)...
% &&y1(i)<=y1(i-1)&&y1(i)<=y1(i-1)&&y1(i)<=y1(i+1)&&y1(i)<=y1(i+2)...
% &&y1(i)<=y1(i+3)&&y1(i)<=y1(i+4)&&y1(i)<=y1(i+5))
if (y1(i)>=y1(i-2)...
&&y1(i)>=y1(i-1)&&y1(i)>=y1(i-1)&&y1(i)>=y1(i+1)&&y1(i)>=y1(i+2)...
||y1(i)<=y1(i-2)...
&&y1(i)<=y1(i-1)&&y1(i)<=y1(i-1)&&y1(i)<=y1(i+1)&&y1(i)<=y1(i+2)...
)
jizhi1{end+1}=y1(i);
indexcell{end+1}=i;
end
end
end
jizhinum=zeros(1,length(jizhi1));
for i=1:length(jizhi1)
jizhinum(i)=jizhi1{i};
end
indexnum=zeros(1,length(indexcell));
for i=1:length(indexcell)
indexnum(i)=indexcell{i};
end
plot(t2,y1);
hold on
scatter(t2(indexnum),jizhinum);
其实应该把极大值和极小值分开储存。
2,怎么用光滑曲线连接?
插值
利用spline函数
第一个参数是要插值点的横坐标值
第二个参数是要插值点的纵坐标值
第三个参数是全部横坐标值
这个是完整程序:
[y,Fs,bits]=wavread('testshort.wav');%读出信号,采样率和采样位数。
sigLength=length(y);
t=(0:sigLength-1)/Fs;
figure;plot(t,y);xlabel('Time(s)');
t1=t(t(1,:)<=11.091);
t2=t1(t1(1,:)>=11.084);
t3=t(t(1,:)<=11.084);
y1=y(length(t3):length(t1)-1);
jizhi1={};
jizhi2={};
indexcell_1={};
indexcell_2={};
for i=1:length(y1)
if i>=6&&i<=length(y1)-6
% if (y1(i)>=y1(i-5)&&y1(i)>=y1(i-4)&&y1(i)>=y1(i-3)&&y1(i)>=y1(i-2)...
% &&y1(i)>=y1(i-1)&&y1(i)>=y1(i-1)&&y1(i)>=y1(i+1)&&y1(i)>=y1(i+2)...
% &&y1(i)>=y1(i+3)&&y1(i)>=y1(i+4)&&y1(i)>=y1(i+5))||(y1(i)<=y1(i-5)&&y1(i)<=y1(i-4)&&y1(i)<=y1(i-3)&&y1(i)<=y1(i-2)...
% &&y1(i)<=y1(i-1)&&y1(i)<=y1(i-1)&&y1(i)<=y1(i+1)&&y1(i)<=y1(i+2)...
% &&y1(i)<=y1(i+3)&&y1(i)<=y1(i+4)&&y1(i)<=y1(i+5))
if (y1(i)>=y1(i-2)...
&&y1(i)>=y1(i-1)&&y1(i)>=y1(i-1)&&y1(i)>=y1(i+1)&&y1(i)>=y1(i+2))
jizhi1{end+1}=y1(i);
indexcell_1{end+1}=i;
else if (y1(i)<=y1(i-2)...
&&y1(i)<=y1(i-1)&&y1(i)<=y1(i-1)&&y1(i)<=y1(i+1)&&y1(i)<=y1(i+2))
jizhi2{end+1}=y1(i);
indexcell_2{end+1}=i;
end
end
end
end
jizhinum_1=zeros(1,length(jizhi1));
for i=1:length(jizhi1)
jizhinum_1(i)=jizhi1{i};
end
indexnum_1=zeros(1,length(indexcell_1));
for i=1:length(indexcell_1)
indexnum_1(i)=indexcell_1{i};
end
jizhinum_2=zeros(1,length(jizhi2));
for i=1:length(jizhi2)
jizhinum_2(i)=jizhi2{i};
end
indexnum_2=zeros(1,length(indexcell_2));
for i=1:length(indexcell_2)
indexnum_2(i)=indexcell_2{i};
end
BAOLUO1=spline(t2(indexnum_1),jizhinum_1,t2);
plot(t2,y1);
hold on
plot(t2,BAOLUO1,'r');
hold on
BAOLUO2=spline(t2(indexnum_2),jizhinum_2,t2);
plot(t2,BAOLUO2,'k');
与上面的波形比对一下:
还挺好的。