![]() |
如何从MATLAB中的自动相关数据中提取峰值?
我有关于音频轨道的信息(20,000帧数据),我使用以下信息进行了自动关联:
[r,lags] = xcorr(XX,XX,'biased'); 它看起来像这样: [URL="https://i.stack.imgur.com/u5gWs.jpg"][IMG]https://i.stack.imgur.com/u5gWs.jpg[/IMG][/URL] 希望到目前为止一切都很好。理想情况下,我希望能够获取与第二个峰值的最高部分相对应的帧号。我已经阅读并尝试了许多不同的方法,但似乎无法为我检索信息。 有人能阐明我的工作吗? 非常感谢! [B]edit1:[/B]我尝试使用findpeaks ,但它似乎对我不起作用。我不确定这是否是因为我使用的数据不正确。 [B]edit2:[/B]我目前正在测试一种仅可用于此音轨的方法,但是不久之后我想对其进行扩展,以便可以在整个文件目录中执行此方法,因此我需要一个脚本来检测峰值而不是自己寻找信息。 [B]edit3:[/B]我的.M文件: [y, fs, nb] = wavread('Three.wav'); %# Load the signal into variable y frameWidth = 441; %# 10ms numSamples = length(y); %# Number of samples in y numFrames = floor(numSamples/frameWidth); %# Number of full frames in y energy = zeros(1,numFrames); %# Initialize energy startSample = zeros(1,numFrames); %# Initialize start indices endSample = zeros(1,numFrames); %# Initialize end indices for frame = 1:numFrames %# Loop over frames startSample(frame) = (frame-1)*frameWidth+1; %# Starting index of frame endSample(frame) = frame*frameWidth; %# Ending index of frame frameIndex = startSample(frame):endSample(frame); %# Indices of frame samples energy(frame) = sum(y(frameIndex).^2); %# Calculate frame energy end %# End loop XX = filtfilt(ones(1,10)/10, 1, energy); %# Smooths signal [r,lags] = xcorr(XX,XX,'biased'); %# Auto-correlates the data plot(lags,r), xlabel('lag'), ylabel('xcorr') %# Plots data [B]回答:[/B] [B]编辑[/B] : %# load the signal [y, fs, nb] = wavread('Three.wav'); y = mean(y,2); %# stereo, take avrg of 2 channels %# Calculate frame energy fWidth = round(fs*10e-3); %# 10ms numFrames = floor(length(y)/fWidth); energy = zeros(1,numFrames); for f=1:numFrames energy(f) = sum( y((f-1)*fWidth+1:f*fWidth).^2 ); end %# smooth the signal (moving average with window size = 1% * length of data) WINDOW_SIZE = round(length(energy) * 0.01); %# 200 XX = filtfilt(ones(1,WINDOW_SIZE)/WINDOW_SIZE, 1, energy); %# auto-correlation [r,lags] = xcorr(XX, 'biased'); %# find extrema points dr = diff(r); eIdx = find(dr(1:end-1) .* dr(2:end) > lags( eIdx(loc) ) ans = 0 -6316 6316 请注意,我们在计算自相关函数的导数之前先对信号进行平滑处理,以找到[URL="http://en.wikipedia.org/wiki/Maxima_and_minima"]极值点[/URL] [url=https://stackoverflow.com/questions/3495892]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 01:06。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.