如何在播放wav文件时在matlab上绘制波形文件。我想绘制幅度与时间的关系。我尝试使用以下代码尝试此操作:
[y,Fs] = audioread('test.wav');
sound(y,Fs);
clear y Fs
答案 0 :(得分:2)
使用sound
您没有真正的机会这样做,但使用audioplayer
课程可以做到这一点:
function syncPlayerDemo()
%some example music
load handel;
%set up audio player
player = audioplayer(y, Fs);
[samples,channels]=size(y);
%calculate timeline
t=linspace(0,1/Fs*(samples-1),samples);
%initialize full plot, update will only move the visible area using xlim
h=plot(t,y);
%set up callback to update every <TimerPeriod> s
player.TimerFcn=@timerFcn;
player.TimerPeriod=0.1;
player.playblocking()
end
function timerFcn(source,data)
%an area of length <area> s will be visible
area=1;
position=(source.CurrentSample-1)/source.SampleRate;
%move visible area, current position is in the center
set(gca,'XLim',[position-area/2,position+area/2]);
%used a waitbar for testing, might be commented in
%waitbar(source.CurrentSample/source.TotalSamples);
end
使用仅timerFcn
重新同步的图表,可以使用自动移动到一侧的绘图进一步提高此绘图的质量。