www.gusucode.com > signal 案例源码程序 matlab代码 > signal/PeriodogramOfASignalWithMissingSamplesExample.m

    %% Power Spectral Density of Signal with Missing Samples
% If you do not have a time vector, use |NaN|'s to specify missing samples
% in a signal.

% Copyright 2015 The MathWorks, Inc.


%%
% Generate 1024 samples of a sinusoid of normalized frequency $2\pi/5$
% rad/sample embedded in white noise of variance 1/100. Estimate the power
% spectral density using the Lomb-Scargle procedure. Use |plomb| with no
% output arguments to plot the estimate.

t = (0:1023)';
x = sin(2*pi*t/5);
x = x + randn(size(x))/10;

[pxx,f] = plomb(x);

plomb(x)

%%
% Remove every other sample by assigning |NaN|'s. Use |plomb| to compute
% and plot the PSD. The periodogram peaks at the same frequency because the
% time axis is unchanged.

xnew = x;
xnew(2:2:end) = NaN;

plomb(xnew)

%%
% Remove every other sample by downsampling. The function now estimates the
% periodicity at twice the original frequency. This is probably not the
% result you want.

xdec = x(1:2:end);

plomb(xdec)