MATLAB - 寻找峰谷

MATLAB - Finding Peaks and Valleys

所以我有 2 个记录频率的 .wav 文件。一个是原始音频,另一个是过滤后的音频。两者都是立体声 .wav 文件。

现在,我应该找到这 2 个 .wav 文件的波峰和波谷。 有人告诉我,我必须获取 3 个连续数据并确定 3 个数据中的最大值或最小值。如果中间一个是最大值或最小值,则 peak/valley 已找到。重复此操作,直到没有更多数据。

我应该如何实现以上目标?

我被告知要滑动 window 尺寸 3 并取 3 点乘 3 点。

我用谷歌搜索但找不到如何开始。任何人都可以帮忙吗?谢谢!

首先你必须将你的音频文件制作成单声道,这可以通过以下方式轻松完成:

a = audioread('filename');
b = sum(a,1)./2;

接下来您可以将其分成 3 个帧 - 这可以通过 'reshape' 轻松实现,或者对您来说可能更容易,只需使用 for 循环:

reshapemethod = reshape(b,[floor(size(b,2)/3),3])

或循环:

for t=1:floor(size(b,2)/3)
   firstpoint = b((t-1)*3+1);
   secondpoint = b(firstpoint+1);
   thirdpoint = b(firstpoint+2)
   %//Use if statement to compare 
   %//OR just do
   [peaks(t) locationOfPeaks(t)]= findpeaks([firstpoint,secondpoint,thirdpoint]);
   %//For Valleys, just multiply first second and third point by -1 and then use the findpeaks function.
   [vallys(t) locationOfValleys(t)] = findpeaks([-1*firstpoint,-1*secondpoint,-1*thirdpoint]);
end

接下来您可以使用 findpeaks 找到 3 个数据点中的峰值,或者只是使用 if 子句比较它们​​,这是非常基础的,所以我留给您去做。