我一直在努力從圖中(see previous question)它看起來像這樣提取的峯值:如何從MATLAB中的自動關聯數據中提取特定值?
,但我已經注意到了一些xcorr圖我一直在努力的價值不轉的如預期,他們通常變成看起來更像是這樣的:
這:
alt text http://a.imageshack.us/img836/7236/plotgraphcopy.jpg
而不是像代碼在第一個圖中所做的那樣嘗試挑選峯值,我將如何去嘗試選擇向下傾斜度瞬間增加的值(如圖3所示)?
當我嘗試運行當前狀態下的代碼,如圖2所示的數據時,我沒有收到任何有用的數據。
我想我需要如果語句或類似的「找極值點」部分,但我不知道這是否是正確與否。我對功能.M代碼看起來像這樣至今:
[inputname, pathname] = uigetfile('*.wav', 'Select WAV-file');
thumb1 = inputname; %# Get filename information
fprintf('\n%s is being turned into a 30s thumbnail...\n', thumb1);
fprintf('Please wait..!\n\n');
%# load the signal
[y, fs, nb] = wavread(thumb1);
y = mean(y,2); %# stereo, take avrg of 2 channels
%# Calculate frame energy
fWidth = round(fs*1); %# 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) <= 0) + 1;
[~,loc] = sort(r(eIdx), 'descend');
loc = loc(1:min(3,end)); %# take the highest 3 values
inf=lags(eIdx(loc));
thumb=max(inf);
startrecord=round((thumb/1)*fs);
endrecord=round(((thumb+30)/1)*fs);
wavwrite(y(startrecord:endrecord), fs, nb, 'Temp1');
fprintf('The thumbnail of %s has been created.\n\n', thumb1);
對不起,這一切都看起來那麼亂,但我希望得到一些直觀的例子!
要給予適當的情況下,你或許應該提到你前面的問題(因爲這是一個延續的幾分) – Amro 2010-09-08 21:09:53
@Amro:我已經添加了鏈接。 – Jonas 2010-09-08 21:31:19