matlab观察输出波形,对给定音频文件“testshort.wav”,用matlab输出它的波形【学生创新实验室联合纳新测试题】...

本文详细介绍了如何使用MATLAB分析音频信号,通过提取10s到15s区间内的信号,逐步放大观察,并找出极值点。作者使用了spline函数进行插值以得到平滑的包络线。该过程适用于信号处理和音频分析,展示了从数据读取到极值检测再到曲线拟合的完整流程。
摘要由CSDN通过智能技术生成

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)');

0818b9ca8b590ca3270a3433284dd417.png

截取其中任意一个脉冲,展开观察其形状并求包络(请保存图片);

我先取10s~15s

t1=t(t(1,:)<=15);

t2=t1(t1(1,:)>=10);

t3=t(t(1,:)<=10);

0818b9ca8b590ca3270a3433284dd417.png

y1=y(length(t3):length(t1));

plot(t2,y1);

0818b9ca8b590ca3270a3433284dd417.png

这是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);

0818b9ca8b590ca3270a3433284dd417.png

放大了看看:

0818b9ca8b590ca3270a3433284dd417.png

再看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);

0818b9ca8b590ca3270a3433284dd417.png

再看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);

注意!!!!!

这里开始出问题了,

0818b9ca8b590ca3270a3433284dd417.png

估计是时间到了精确度的极限了?

差了一位:

0818b9ca8b590ca3270a3433284dd417.png

往后错一位,应该无伤大雅;

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);

0818b9ca8b590ca3270a3433284dd417.png

求包络?

把极值点用光滑曲线连接。

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);

0818b9ca8b590ca3270a3433284dd417.png

其实应该把极大值和极小值分开储存。

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');

0818b9ca8b590ca3270a3433284dd417.png

0818b9ca8b590ca3270a3433284dd417.png

与上面的波形比对一下:

0818b9ca8b590ca3270a3433284dd417.png

0818b9ca8b590ca3270a3433284dd417.png

还挺好的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值