%% Median Frequency of Bandlimited Signals
% Generate a signal whose PSD resembles the frequency response of an 88th-order bandpass FIR filter with normalized cutoff frequencies 0.25\pi rad/sample and 0.45\pi rad/sample.

d = fir1(88,[0.25 0.45]);

%
% Compute the median frequency of the signal between 0.3\pi rad/sample and 0.6\pi rad/sample. Plot the PSD and annotate the median frequency and measurement interval.

medfreq(d,[],[0.3 0.6]*pi);

%
% Output the median frequency and the band power of the measurement interval. Specifying a sample rate of 2\pi is equivalent to leaving the rate unset.

[mdf,power] = medfreq(d,2*pi,[0.3 0.6]*pi);

fprintf('Mean = %.3f*pi, power = %.1f%% of total \n', ...
    mdf/pi,power/bandpower(d)*100)

%
% Add a second channel with normalized cutoff frequencies 0.5\pi rad/sample and 0.8\pi rad/sample and an amplitude that is one-tenth that of the first channel.

d = [d;fir1(88,[0.5 0.8])/10]';

%
% Compute the median frequency of the signal between 0.3\pi rad/sample and 0.9\pi rad/sample. Plot the PSD and annotate the median frequency of each channel and the measurement interval.

medfreq(d,[],[0.3 0.9]*pi);

%
% Output the median frequency of each channel. Divide by \pi.

mdf = medfreq(d,[],[0.3 0.9]*pi)/pi

% Copyright 2015 The MathWorks, Inc.