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 ?!
You need to use the cumtrapz function:
t = ...; % Time Vector s = ...; % Signal Vector Fs = 1/mean(diff(t)); % Sampling Frequency Fn = Fs/2; % Nyquist Frequency L = length(t); FTs = fft(s)/L; Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector Iv = 1:length(Fv); % Index Vector CumAmp = cumtrapz(Fv, abs(FTs(Iv))); % Integrate FFT Amplitude MedFreq = interp1(CumAmp, Fv, CumAmp(end)/2); % Use ‘interp1’ To Find ‘MF’ figure(1) plot(Fv, abs(FTs(Iv))*2, '-b') % Plot FFT hold on plot(Fv, CumAmp, '-g') % Plot Cumulative Amplitude Integral plot([MedFreq MedFreq], ylim, '-r', 'LineWidth',1) % Plot Median Frequency hold off grid
I tested this with an archive signal, so the code works. It should work with your signal without modification. You can delete the plotting of the cumulative amplitude integral (green line), since it is there only to illustrate that the median frequency is calculated correctly.
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.