Hello! How to plot cumulative periodogram in Matlab with 95% confidence interval?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
How to plot cumulative periodogram in Matlab with 95% confidence interval? Similar to one in R
0 comentarios
Respuestas (1)
Dimitris Iliou
el 19 de Mayo de 2017
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 comentarios
Ver también
Categorías
Más información sobre Spectral Estimation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!