Finding local minima
The following code snippet is something that I put together for a school project some time ago. In this project I was trying to apply some speech processing techniques to alter the pitch of a male speakers voice. At the time I was searching for the formants and trying to move them manually in the frequency domain.
I used this in conjunction with my local maxima code to find the position and the width (using local minima) of the speakers formants. If you give this function a 1-dimensional vector it will return both the indices in which each local minimum is found as well as it's amplitude.
I hope this code can find its way to other fun and exciting applications!
% Finds the local minimum values of the given signal.
% Usage: [IND,AMP] = MINIMA(X, N);
% N is the number of points that need to be evaluated
% (Normally equal to LENGTH(X))
% X is the data
% IND contains the indices of X that contain the minima data
% AMP contains the minima amplitudes
% Author: sparafucile17 10/02/2003
index = 1
prev = signal(1)
local_time = 0
local_amp = 0
prev_slope = 1
; %allow a maxima point at the second sample
%prevent length error
len > length(
len = length(
%Loop through data and find local minimums
cur = signal(
slope = cur - prev;
cur < prev)
prev_slope > 0)) %Positive slope and amplitude dips
index = index+1
prev = cur;
prev_slope = slope;
%After loop assign data to output variables
time = local_time;
amp = local_amp;
Rate this code snippet: