%% 3-dB Bandwidth of Chirps
% Generate 1024 samples of a chirp sampled at 1024 kHz. The chirp has an initial frequency of 50 kHz and reaches 100 kHz at the end of the sampling. Add white Gaussian noise such that the signal-to-noise ratio is 40 dB.

nSamp = 1024;
Fs = 1024e3;
SNR = 40;

t = (0:nSamp-1)'/Fs;

x = chirp(t,50e3,nSamp/Fs,100e3);
x = x + randn(size(x))*std(x)/db2mag(SNR);

%
% Estimate the 3-dB bandwidth of the signal and annotate it on a plot of the power spectral density (PSD).

powerbw(x,Fs)

%
% Generate another chirp. Specify an initial frequency of 200 kHz, a final frequency of 300 kHz, and an amplitude that is twice that of the first signal. Add white Gaussian noise.

x2 = 2*chirp(t,200e3,nSamp/Fs,300e3);
x2 = x2 + randn(size(x2))*std(x2)/db2mag(SNR);

%
% Concatenate the chirps to produce a two-channel signal. Estimate the 3-dB bandwidth of each channel.

y = powerbw([x x2],Fs)

%
% Annotate the 3-dB bandwidths of the two channels on a plot of the PSDs.

powerbw([x x2],Fs);

%
% Add the two channels to form a new signal. Plot the PSD and annotate the 3-dB bandwidth.

powerbw(x+x2,Fs)

% Copyright 2015 The MathWorks, Inc.