# Sign in

username or email:

password:

Not a member?
Forgot your password?

# Finding local minima

Language: Matlab

Processor: Not Relevant

Submitted by on Sep 26 2011

Licensed under a Creative Commons Attribution 3.0 Unported License

# 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!

function [time,amp] = minima(signal, len)
%
% 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

%Initialize data
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
if(len > length(signal))
len = length(signal)
end

%Loop through data and find local minimums
for loop_i=2:len
cur = signal(loop_i);
slope = cur - prev;
if((cur < prev) & (prev_slope > 0))  %Positive slope and amplitude dips
local_time(index) = loop_i-1;
local_amp(index) = prev;
index = index+1;
end
prev = cur;
prev_slope = slope;
end

%After loop assign data to output variables
time = local_time;
amp = local_amp;

Rate this code snippet:
0
Rating: 0 | Votes: 0

posted by

Comments

# ravitejaelx wrote:

9/29/2011

to plot this properly use this code at the end of the funtion

m=min(signal);
n=max(signal);
plot(signal);
mar=zeros(length(signal));
mar(time)=amp;
hold on
stem(mar,'r')
ylim([m n])

Add a Comment
You need to login before you can post a comment (best way to prevent spam). ( Not a member? )