%% Bandwidth 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 3-dB occupied bandwidth of the signal. Specify as a reference level the average power in the band between 0.2\pi rad/sample and 0.6\pi rad/sample. Plot the PSD and annotate the bandwidth.

powerbw(d,[],[0.2 0.6]*pi,3);

%
% Output the bandwidth, its lower and upper bounds, and the band power. Specifying a sample rate of 2\pi is equivalent to leaving the rate unset.

[bw,flo,fhi,power] = powerbw(d,2*pi,[0.2 0.6]*pi);

fprintf('bw = %.3f*pi, flo = %.3f*pi, fhi = %.3f*pi \n', ...
    [bw flo fhi]/pi)
fprintf('power = %.1f%% of total',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 6-dB bandwidth of the two-channel signal. Specify as a reference level the maximum power level of the spectrum.

powerbw(d,[],[],6);

%
% Output the 6-dB bandwidth of each channel and the lower and upper bounds.

[bw,flo,fhi] = powerbw(d,[],[],6);
bds = [bw;flo;fhi];

fprintf('One: bw = %.3f*pi, flo = %.3f*pi, fhi = %.3f*pi \n',bds(:,1)/pi)
fprintf('Two: bw = %.3f*pi, flo = %.3f*pi, fhi = %.3f*pi \n',bds(:,2)/pi)

% Copyright 2015 The MathWorks, Inc.