I have been working on extracting the peak values from a graph (see previous question) which looks like this:
but I have noticed that for some of the xcorr graphs I have been working on the values do not turn out as expected and they normally turn out looking more like this:
and this:
Instead of trying to pick the peak values like the code was doing in the first figure, how would I go about trying to pick the values where the downward slope momentarily evens itself out (as shown in Figure 3)?
When I try and run the code in its current state on data like the ones shown in Figure 2 & 3, I do not get any useful data back in return.
I think I need an if statement or similar in the 'find extrema points' section but I'm not sure whether that is correct or not. My .M code for the function looks like this so far:
[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);
Sorry that it all looks so messy, but I wanted to get some visual examples in!