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

    %% Two-Channel Brownian Noise 
%%
% *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 two channels of Brownian noise by setting |Color| to |brown| and
% |NumChannels| to 2.
hcn = dsp.ColoredNoise('Color','brown','SamplesPerFrame',2048,...
    'NumChannels',2);
x = hcn();
subplot(2,1,1)
plot(x(:,1)); title('Channel 1'); axis tight;
subplot(2,1,2)
plot(x(:,2)); title('Channel 2'); axis tight;

%%
% Assume a sampling frequency of 1 Hz. Obtain Welch PSD estimates for both
% channels.
Fs = 1;
for nn = 1:size(x,2)
[Pxx(:,nn),F] = pwelch(x(:,nn),hamming(128),[],[],Fs,'psd');
end
%%
% Construct the theoretical PSD of a Brownian process. Plot the theoretical
% PSD along with both realizations on a log-log plot. Use the logarithm to
% the base 2 for the frequency axis and plot the power spectral densities
% in dB.
PSDBrownian = 1./F(2:end).^2;
figure;
plot(log2(F(2:end)),10*log10(PSDBrownian),'k-.','linewidth',2);
hold on;
plot(log2(F(2:end)),10*log10(Pxx(2:end,:)));
xlabel('log_2(Hz)'); ylabel('dB');
grid on;
legend('Theoretical PSD','Channel 1', 'Channel 2');