what is the median frequency matlab code?
Show older comments
hello everybody,, my question what is the median frequency(MF) mat-lab code ,if the median frequency defined as the frequency that divides the magnitude-spectrum in two parts of equal size(the area under the curve for lower frequencies than MF equals the area under the curve for the frequencies higher than MF. first of all i've got the plot of the magnitude spectrum then i used trapz(x,y) to get the whole area under the curve, now i need a code to know what is the frequency that divides the total area into 2 equal parts ?!
12 Comments
haya alawneh
on 3 Mar 2016
Star Strider
on 3 Mar 2016
Your unformatted code makes absolutely no sense to me.
I gave you code that will calculate the median frequency, as you requested.
haya alawneh
on 3 Mar 2016
Star Strider
on 3 Mar 2016
My pleasure.
If my Answer solved your problem, please Accept it.
What is your question?
haya alawneh
on 3 Mar 2016
Star Strider
on 3 Mar 2016
For relative power, use the find function to find the indices corresponding to your frequencies of interest, then use trapz to integrate the 100-500 range and the total power.
To calculate the power spectral density, see the documentation on Power Spectral Density Estimates Using FFT.
I do not know what you mean by ’zero crossing’. There should be no zero-crossing in the power spectral density.
haya alawneh
on 3 Mar 2016
Star Strider
on 3 Mar 2016
I am still not certain what you are doing the zero-crossings on. You can use this little function to get their approximate indices:
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Zero-Crossing Indices Of Argument Vector
Use trapz. (The cumtrapz function is also an option.)
haya alawneh
on 3 Mar 2016
Star Strider
on 3 Mar 2016
My pleasure.
I don’t mind answering questions in my areas of expertise!
haya alawneh
on 3 Mar 2016
Star Strider
on 3 Mar 2016
In the code in my Answer, the time vector (actually, deriving the sampling interval from it) is used to calculate the sampling frequency, and from the sampling frequency, the frequency vector.
The sampling interval, ‘Ts’ is defined in my code as:
Ts = mean(diff(t));
and the sampling frequency as:
Fs = 1/Ts;
I combined them in one statement in the code in my Answer.
Accepted Answer
More Answers (0)
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!