MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply TodayTo resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Asked by Samuel on 4 Jul 2013

Hello all,

I have an x by 2 array- it is a freq vs amplitude graph. The graph is similar in shape to a typical ideal frequency curve (going uphill to a peak point then downhill).

I am trying to write a code that will detect the half power of the amplitude, and display the frequency of the two half power locations(since it goes up and down).

With some research(stackoverflow forums), I was able to devise a code utilizing the minimum difference between the value and half power value, but this code approach only can get me the first half power point- any help in getting the second one as well will be of great help. Thanks!

the code portion is below:

%halfpow is the number I want to be searched for %v1 is the column vector that contains the amplitudes val=abs(v1-halfpow); [ind ind]=min(val); closest=v1(ind)

Answer by Guru on 4 Jul 2013

Accepted answer

The code you have is fine, what you have are two minima values that you are seeking. So by breaking up your search points you can find it easier. What you

va1 = abs(v1-halfpow); % This part is exactly what you want like above [C,ind1] = min(val); point1 = v1(ind1)

% Remove the data points that you just found the minimum of to find another val(ind-2:ind+2) = max(val); [C,ind2] = min(val); point2 = v1(ind2)

This should give you the idea. The concept is min finds the first global minimum of the vector. To find a second minimum, you need to ensure the first minimum is no longer a minimum.

HTH!

Answer by the cyclist on 4 Jul 2013

You could use sort(val) rather than min(val), and you will get the sorted values, and the indices to them.

## 0 Comments