www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/PSDOfPinkNoiseRealizationExample.m

    %% PSD of Pink Noise Realization
%%
% *Note*: This example runs only in R2016b or later. If you are using an
% earlier release, replace each call to the function with the equivalent
% |step| syntax. For example, myObject() becomes step(myObject).

%%
% Generate a pink noise signal 2048 samples in length.
% Assume a sampling rate of 1 Hz. Obtain an estimate of the power spectral
% density using Welch's overlapped segment averaging.
hcn = dsp.ColoredNoise('Color','pink','SamplesPerFrame',2048);
x = hcn();
Fs = 1;
[Pxx,F] = pwelch(x,hamming(128),[],[],Fs,'psd');
%%
% Construct the theoretical PSD of the pink noise process.
PSDPink = 1./F(2:end);
%%
% Display the Welch PSD estimate of the noise along with the
% theoretical PSD on a log-log plot. Plot the frequency axis as the
% logarithm to the base 2 to clearly show the octaves. Plot the PSD
% estimate in dB, $10\log_{10}$.
plot(log2(F(2:end)),10*log10(Pxx(2:end)));
hold on;
plot(log2(F(2:end)),10*log10(PSDPink),'r','linewidth',2)
xlabel('log_2(Hz)'); ylabel('dB');
title('Pink Noise');
grid on;
legend('PSD Estimate','Theoretical Pink Noise PSD');