%% Averaged Power Spectrum of Pink Noise
% *Note*: If you are using R2016a or an earlier release, replace each call to 
% the object with the equivalent |step| syntax. For example, |obj(x)| becomes 
% |step(obj,x)|.
% 
% Generate two-channels of pink noise and compute the power spectrum based 
% on a running average of 50 PSD estimates.
% 
% Set up the colored noise generator to generate two channels of pink noise 
% with 1024 samples. Set up the spectrum analyzer to compute modified periodograms 
% using a Hamming window and 50% overlap. Obtain a running average of the PSD 
% using 50 spectral averages.

pinkNoise = dsp.ColoredNoise('pink',1024,2);
sa = dsp.SpectrumAnalyzer('SpectrumType','Power density', ...
    'OverlapPercent',50,'Window','Hamming', ...
    'SpectralAverages',50,'PlotAsTwoSidedSpectrum',false, ...
    'FrequencyScale','log','YLimits',[-50 30]);
%% 
% Run the simulation for 30 seconds.
%%
tic
while toc < 30
    pink = pinkNoise();      
    sa(pink);
end

%% 
% Copyright 2012 The MathWorks, Inc.