Commit a5c2df5a authored by sstucker's avatar sstucker
Browse files

Power spectrum callback

parent 2941bed6
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -1542,6 +1542,44 @@ cfg.Save();
cfg.Close();


function menuItemPowerSpectrum_Callback(hObject, eventdata, handles)
% hObject    handle to menuItemPowerSpectrum (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global maingui;
iCh = maingui.axesSDG.iCh;
n_channels = length(iCh);
if n_channels > 0
    iSrcDet = maingui.axesSDG.iSrcDet;
    colors = maingui.axesSDG.linecolor;
    d = maingui.dataTree.currElem.acquired.data.dataTimeSeries;
    sf = maingui.dataTree.currElem.acquired.data.time(2) - maingui.dataTree.currElem.acquired.data.time(1);
    fs = 1/sf;
    try
       close(maingui.spectrumFigureHandle);
    catch
    end
    maingui.spectrumFigureHandle = figure('NumberTitle', 'off', 'Name', 'PSD of selected channels');
    n = 3;
    m = ceil(n_channels / n);
    for i = 1:n_channels
        % 100 sec window with 50% overlap
        window = floor(100 / sf);
        overlap = window / 2;
        bins = 2048;
        [pxx,f] = pwelch(d(:,iCh(i)), window, overlap, bins, fs);
        subplot(m,n,i);
        plot(f, 10*log10(pxx), 'Color', colors(i,:));
        title([num2str(iSrcDet(i,1)), ' \rightarrow ', num2str(iSrcDet(i,2))]);
        xlim([0,fs/2]);
        xlabel(sprintf('Frequency (Hz)'));
        ylabel(sprintf('PSD (dB)\n'));
    end
else
    errordlg('Cannot calculate power spectra with no channels selected.', 'No channels selected'); 
end


% --------------------------------------------------------------------
function SettingsMenu_Callback(hObject, eventdata, handles)
% hObject    handle to SettingsMenu (see GCBO)