Hello! How to plot cumulative periodogram in Matlab with 95% confidence interval?
3 次查看(过去 30 天)
显示 更早的评论
How to plot cumulative periodogram in Matlab with 95% confidence interval? Similar to one in R
0 个评论
回答(1 个)
Dimitris Iliou
2017-5-19
If I understand correctly, you want to have a MATLAB script that resembles the behavior of 'cpgram' in R.
A possible answer to your question is to use the periodogram function that MATLAB provides, and then take the cumulative sum of the power.
You can find more information on the periodogram function in the following link:
I will use an example from that documentation page to illustrate my suggestion.
The periodogram can be calculated using the following:
% This is a documentation example
fs = 1000;
t = 0:0.001:1-0.001;
x = cos(2*pi*100*t)+sin(2*pi*150*t)+randn(size(t));
[pxx,f,pxxc] = periodogram(x,rectwin(length(x)),length(x),fs,...
'ConfidenceLevel', 0.95);
% Plotting
figure()
plot(f,10*log10(pxx))
hold on
plot(f,10*log10(pxxc),'r-.')
hold off
xlim([85 175])
xlabel('Hz')
ylabel('dB')
title('Periodogram with 95%-Confidence Bounds')
and the outcome of that will look something like this:
From the variables calculated by the periodogram function, you can use the pxx variable to calculate the cumulative sum of the power.
You can do this with the following code:
% Calculate the Cumulative Sum
cpxx = cumsum(pxx)./sum(pxx);
% Plotting
figure()
plot(f,cpxx)
hold on
% These two lines correspond to the 95% interval
plot(f,f./max(f)+0.05,'r--')
plot(f+0.05*max(f),f./max(f),'r--')
axis([0 500 0 1])
xlabel('Frequency(Hz)')
ylabel('Cumulative periodogram')
hold off
This code will yield the following result:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Estimation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!