MATLAB Examples

# Example 8.2.5.a. Barlett's Method - Power Spectrum of White Noise revisited.

## Workspace Initialization.

```clc; clear; close all; ```

## Signal Definition

```N = 512; K = [1 4 8 16] ; % Number of sections. NumOfRuns = 10; PerLength = 2*1024; % This is the fft length used to calculate the periodogram. freq = 0:2/(PerLength-1):2; h1 = figure('NumberTitle', 'off','Name', ... 'Figure 8.14 Spectrum Estimation of unit Variance White Gaussian Noise',... 'Visible','off','Position', [100 0 800 800]); for m=1:length(K) Px = zeros(NumOfRuns,PerLength); for k=1:NumOfRuns x = randn(1,N); Px(k,:) = bart(x,K(m),PerLength); % Periodogram clculation using Barlett's method. end subplot(4,2,2*m-1) plot(freq(1:PerLength/2),10*log10(Px(:,1:PerLength/2)),'k','LineWidth',0.1) if m==1 title(['Overlay plot of ',num2str(NumOfRuns),' periodograms using N = 512 data samples']) else title(['Overlay plot of ',num2str(NumOfRuns),' Bartlett periodograms using K = ', ... num2str(K(m)),' with L = ',num2str(N/K(m))]) end grid on; axis tight; ylim([-30 20]) % xlabel('Frequency (units of pi)'); subplot(4,2,2*m) plot(freq(1:PerLength/2),1/NumOfRuns*sum(10*log10(Px(:,1:PerLength/2))),'r','LineWidth',1) title(['Ensemble Average of ',num2str(NumOfRuns),' Bartlett periodograms' ]) axis tight; % set(gca,'YTick',-5:5:30); % xlabel('Frequency (units of pi)'); ylim([-10 10]) grid on; end % Restore the visibility of the figure. set(h1, 'Visible','on'); ```