How to plot a shaded region in pwelch plot from top to bottom
Ältere Kommentare anzeigen
Dear Matlab,
I have a pwelch plot from matlab, for EEG data. I would like to shade in regions from 10-13 hz (on the x axis) from the bottom to the top of the plot, in the color grey.
So far, I can plot only a tiny sliver of grey along the zero line on the Y-axis. (see attached 'pwelchplot' PNG image).
My goal is to have a plot like the other one attached (see 'desiredPWELCHplot' PNG), with grey shaded stripes form top to bottom.
Please help. Code below...(I've deleted other code for simplification)
% load data
eegdata = mean(EEG.data([5,6,15,16],:));
srate = EEG.srate;
% create Hann window
winsize = 2*srate; % 2-second window
hannw = .5 - cos(2*pi*linspace(0,1,winsize))./2;
% number of FFT points (frequency resolution)
nfft = srate*100;
nfft2 = srate*100;
[powspect,hzp] = pwelch(eegdata,hannw,round(winsize/4),nfft,srate,'power');
%% now to extract range-specified power: SIGMA/MU
% boundaries in hz
stimbounds = [ 10 13 ];
% convert to indices
[~,fidx(1)] = min(abs( hzp-stimbounds(1) ));
[~,fidx(2)] = min(abs( hzp-stimbounds(2) ));
figure(5),clf
pwelch(eegdata,hannw,round(winsize/4),nfft,srate,'power');
% shade region in plot
ph = patch([hzp(fidx(1):fidx(2)); hzp(fidx(2)-1:-1:fidx(1))],[powspect(fidx(1):fidx(2)); zeros(diff(fidx),1)],'k');
set(ph,'edgecolor','none','FaceAlpha',.3)
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Spectral Estimation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
