⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewedf.m

📁 matlab数字信号处理工具箱
💻 M
📖 第 1 页 / 共 5 页
字号:
function viewedf(Action, ActOption)
% viewedf
% Display EDF (European Data Format) files
% This program requires Matlab Version >= 5.2 and should work with Matlab 6.x
%
% Command line functionality (note: all commands are case sensitive):
% viewedf : start program
% viewedf('OpenEDFFile', FILENAME) : open FILENAME
% viewedf('Goto', RECORD) : move to RECORD
% viewedf('GotoSecond', SECOND) : move to a certain SECOND
% viewedf('Prev') : move back one screen
% viewedf('Next') : move forward one screen
% viewedf('PrevFast') : move back 5 screens
% viewedf('NextFast') : move forward 5 screens
% viewedf('Close') : close viewer
%
% Keyboard shortcuts:
% '+' : move to next screen
% '-' : move to previous screen
% 'U' : scale all channels up
% 'D' : scale all channels down
%
% Version 3.04Alpha, 10/22/01
% (c) Herbert Ramoser (herbert.ramoser@arcs.ac.at)
%
% This Software is subject to the GNU public license.

% Changes:
% 01/27/98 Ramoser: Plugins may replace EDF data, optional parameter string
%   is passed to the plugin
% 01/30/98 Ramoser: plotting of EDF.Valid information
% 02/02/98 Ramoser: print option added
% 02/18/98 Ramoser: Stairplot-feature added, bug for hypnograms removed
% 06/16/98 Ramoser: bugs of Matlab 5.2 fixed (return, inputdlg)
%          display multiple EDF files
%          fixed order of channels
%          export of matrices to workspace
%          increase in plotting speed
% 09/18/98 Ramoser: new EDF open and read functions included
%          upside down display of plots
%          use of cell arrays to store EDF data
%          data passed to plugins has changed
% 11/01/98 Woertz: reset display after calls of plugin menus
% 11/23/98 Ramoser: give only one file to plugin
%          handling of plugins when EDF files are closed
% 11/30/98 Ramoser: GDF functionality added
% 12/02/98 Ramoser: optionally display plot Y tick-labels
% 12/03/98 Ramoser: fixed dialog boxes under X (drawnow added)
%          upside-down plotting bug removed
% 12/07/98 Ramoser: scaling buttons added
% 12/09/98 Ramoser: physical dimension added to Y-label
% 02/18/99 Ramoser: problems with multiple files, multiple record lengths
%          and scrollbar removed
% 03/04/99 Ramoser: Assign matrix - plugin bug removed
% 03/26/99 Ramoser: GDF 0.12 added, set properties of all channels
%          simultaneusly ('Apply to all' button)
% 03/31/99 Ramoser: time tracking line added
% 04/01/99 Ramoser: print problems resolved
% 04/29/99 Ramoser: do not reset display properties after a call to
%          plugin-menu
% 05/04/99 Ramoser: time tracking line bugs removed
% 05/12/99 Ramoser: file positioning information added (EDFHead.AS.startrec
%          & numrec)
% 03/17/00 Ramoser: add command line functionality, add 'Goto second'
% 10/22/01 Ramoser: some updates for Matlab 6

FastPageIncrement = 5;
PageIncrement = 1;
warning('off');

switch nargin,
 case 0,
  if ~isempty(findobj('Tag', 'ViewEDFFigure'))
    error('Only one copy of VIEWEDF may be run');
  end
  LocalInitWindow;
 case 1,
  switch Action
   case 'OpenEDFFile',
    LocalEDFOpen;
   case 'CloseEDFFile',
    LocalEDFClose;
   case 'Repaint'
    LocalRepaint;
   case 'AddPlugin'
    LocalAddPlugin;
   case 'RemovePlugin'
    LocalRemovePlugin;
   case 'PluginMenu'
    LocalPluginMenu;
   case 'PrevFast'
    LocalChangeRecord(-FastPageIncrement,0);
   case 'Prev'
    LocalChangeRecord(-PageIncrement,0);
   case 'NextFast'
    LocalChangeRecord(FastPageIncrement,0);
   case 'Next'
    LocalChangeRecord(PageIncrement,0);
   case 'HScroll'
    LocalHScroll;
   case 'ToggleUpdatePlugin'
    LocalToggleUpdatePlugin;
   case 'ToggleShowRange'
    LocalToggleShowRange;
   case 'ToggleShowCursor'
    LocalToggleShowCursor;
   case 'RecordProp'
    LocalRecordProp;
   case 'Goto'
    LocalGotoRecord;
   case 'GotoSecond'
    LocalGotoSecond;
   case 'Records'
    LocalNumRecords;
   case 'FileInfo'
    LocalFileInfo;
   case 'Channels'
    LocalSelectChannels;
   case 'About'
    LocalAbout;
   case 'Help'
    LocalHelp;
   case 'KeyPress'
    LocalKeyPress;
   case 'Print'
    LocalPrint;
   case 'AssignMat'
    LocalAssignMat;
   case 'ScaleUp'
    LocalRescale('up');
   case 'ScaleDown'
    LocalRescale('down');
   case 'Close'
    LocalCloseViewEDF;
   otherwise
    error('VIEWEDF must be called without parameters');
  end
 case 2,
  switch Action
   case 'OpenEDFFile',
    LocalEDFOpen(ActOption);
   case 'FileInfo'
    LocalFileInfo(ActOption);
   case 'Channels'
    LocalSelectChannels(ActOption);
   case 'MoveCursor'
    LocalMoveCursor(ActOption);
   case 'Goto'
    LocalGotoRecord(ActOption);
   case 'GotoSecond'
    LocalGotoSecond(ActOption);
   otherwise
    error('Unknown argument!');
  end
 otherwise
  error('Unknown argument!');
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% LocalInitWindow
% initializes the window (display buttons, ...)
function LocalInitWindow()
fig=figure( ...
    'NumberTitle', 'off', ...
    'CloseRequestFcn', 'viewedf Close', ...
    'IntegerHandle', 'off', ...
    'KeyPressFcn', 'viewedf KeyPress', ...
    'MenuBar', 'none', ...
    'Units', 'Normalized', ...
    'Color', [0.9, 0.9, 0.9], ...
    'ResizeFcn', 'viewedf Repaint', ...
    'PaperPositionMode', 'Auto', ...
    'PaperType', 'A4', ...
    'PaperUnits', 'Normalized', ...
    'Tag', 'ViewEDFFigure', ...
    'Name', 'EDF File Viewer - (C) 1998-2001 DPMI, Graz University of Technology');
Data=get(fig,'UserData');

% Menus
mh = uimenu('Label', '&File');
uimenu(mh, ...
    'Label', '&Open EDF', ...
    'Callback', 'viewedf OpenEDFFile');
uimenu(mh, ...
    'Label', '&Close EDF', ...
    'Callback', 'viewedf CloseEDFFile');
uimenu(mh, ...
    'Label', '&Add Plugin', ...
    'Callback', 'viewedf AddPlugin');
uimenu(mh, ...
    'Label', '&Remove Plugin', ...
    'Callback', 'viewedf RemovePlugin');
uimenu(mh, ...
    'Label', '&Print', ...
    'Separator', 'on', ...
    'Callback', 'viewedf Print');
uimenu(mh, ...
    'Label', 'Assign &Matrix', ...
    'Callback', 'viewedf AssignMat');
uimenu(mh, ...
    'Label', 'E&xit', ...
    'Separator', 'on', ...
    'Callback', 'viewedf Close');

mh = uimenu('Label', '&Display');
uimenu(mh, ...
    'Label', 'File &info', ...
    'Callback', 'viewedf FileInfo');
uimenu(mh, ...
    'Label', '&Goto Record', ...
    'Callback', 'viewedf Goto');
uimenu(mh, ...
    'Label', '&Goto Second', ...
    'Callback', 'viewedf GotoSecond');
uimenu(mh, ...
    'Label', '&Records on Screen', ...
    'Callback', 'viewedf Records');
uimenu(mh, ...
    'Label', '&Channels', ...
    'Callback', 'viewedf Channels');

mh = uimenu('Label', '&Options');
uimenu(mh, ...
    'Label', '&Update Plugin', ...
    'Checked', 'on', ...
    'Callback', 'viewedf ToggleUpdatePlugin');
uimenu(mh, ...
    'Label', 'Show &Range', ...
    'Checked', 'off', ...
    'Callback', 'viewedf ToggleShowRange');
uimenu(mh, ...
    'Label', 'Show &Cursor', ...
    'Checked', 'off', ...
    'Callback', 'viewedf ToggleShowCursor');
Data.Display.PluginMenu.Main = uimenu(mh, ...
    'Label', '&Plugin');

mh = uimenu('Label', '&?');
uimenu(mh, ...
    'Label', '&Help', ...
    'CallBack', 'viewedf Help');
uimenu(mh, ...
    'Label', '&About', ...
    'CallBack', 'viewedf About');

% Strings
textx = 0.02;
textheight = LocalGetFontHeight;
texty = 1 - textheight / 4;
Data.Display.Strings.CurrTime = uicontrol(fig, ... % Time string
    'Style', 'Text', ...
    'Units', 'Normalized', ...
    'String', '', ...
    'HorizontalAlignment', 'left', ...
    'FontUnits', 'normalized', ...
    'Position', [textx, texty - textheight, 0.2, ...
      textheight]);
Data.Display.Strings.TotTime = uicontrol(fig, ... % Total time string
    'Style', 'Text', ...
    'Units', 'Normalized', ...
    'String', 'Total length : ', ...
    'HorizontalAlignment', 'left', ...
    'Position', [textx, texty - textheight, 0.2, ...
      textheight]);
Data.Display.Strings.DispTime = uicontrol(fig, ... % Displayed time stretch string
    'Style', 'Text', ...
    'Units', 'Normalized', ...
    'String', 'Displayed : ', ...
    'HorizontalAlignment', 'left', ...
    'Position', [textx + 0.22, texty - textheight, 0.2, ...
      textheight]);
Data.Display.Strings.FileName = uicontrol(fig, ... % File string
    'Style', 'Text', ...
    'Units', 'Normalized', ...
    'String', 'File : ', ...
    'HorizontalAlignment', 'left', ...
    'Position', [textx + 0.44, texty - textheight, 0.2, ...
      textheight]);
Data.Display.Strings.NumString = 4;

% Build data structure
% settings for the display (where to plot things, ...)
Data.Display.Axes = [];       % nothing to display
Data.Display.YSpacing = 0.0025;   % spacing between plots
Data.EDF = [];
Data.Plugin = [];
Data.UpdatePlugin = 1;
Data.ShowRange = 0;
Data.ShowCursor = 0;
Data.Display.Cursor = [];
set(fig,'UserData',Data);
drawnow;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% LocalResetDisplay
% reset display variables
function LocalResetDisplay()
Data = get(findobj('Tag', 'ViewEDFFigure'), 'UserData');
if length(Data.EDF)==0
  return;
end
%EDF data
MaxDur = max(LocalGetEDFInfo('Dur', Data.EDF));
for i=1:length(Data.EDF)
  Data.Display.EDF(i).ShowRecords = [0, round(MaxDur / Data.EDF(i).Head.Dur)];
  [Data.EDF(i).Record, Data.EDF(i).Head] = ...
      LocalEDFRead(Data.EDF(i).Head, Data.Display.EDF(i).ShowRecords);
  Data.Display.EDF(i).ShowSignals = 1:Data.EDF(i).Head.NS;
  Data.Display.EDF(i).DisplayMin = Data.EDF(i).Head.PhysMin;
  Data.Display.EDF(i).DisplayMax = Data.EDF(i).Head.PhysMax;
  Data.Display.EDF(i).StairPlot = zeros(1, Data.EDF(i).Head.NS);
  Data.Display.EDF(i).UpDownPlot = zeros(1, Data.EDF(i).Head.NS);
end

% Plugin data
for i = 1:length(Data.Plugin)
  [Data.Plugin(i).EDF, Data.Plugin(i).UserData] = ...
      feval(Data.Plugin(i).Name, Data.EDF(1), Data.Plugin(i).UserData, ...
      'Reset');
  Data.Display.Plugin(i).ShowRecords = [0, round(MaxDur / Data.Plugin(i).Head.Dur)];
  Data.Display.Plugin(i).ShowSignals = 1:Data.Plugin(i).Head.NS;
  Data.Display.Plugin(i).DisplayMin = Data.Plugin(i).EDF.Head.PhysMin;
  Data.Display.Plugin(i).DisplayMax  = ...
      Data.Plugin(i).EDF.Head.PhysMax;
  Data.Display.Plugin(i).StairPlot = zeros(1, Data.Plugin(i).Head.NS);
  Data.Display.Plugin(i).UpDownPlot = zeros(1, Data.Plugin(i).Head.NS);
end

% update all strings
tsec = max(LocalGetEDFInfo('FileDur', Data.EDF));
tmin = floor(tsec/60);
tsec = rem(tsec,60);
th = floor(tmin/60);
tmin = rem(tmin,60);
set(Data.Display.Strings.TotTime, 'String', ...
  sprintf('Total length : %02d:%02d:%02d', th,tmin,tsec));
fname = 'File : ';
% add '+' for additional files
for i = 1:(length(Data.EDF) - 1)
  fname = [fname Data.EDF(i).Head.FILE.Name '.' Data.EDF(i).Head.FILE.Ext ...
        ' + ']; 
end
fname = [fname Data.EDF(end).Head.FILE.Name '.' Data.EDF(end).Head.FILE.Ext];
set(Data.Display.Strings.FileName, 'String', fname);
set(findobj('Tag', 'ViewEDFFigure'), 'UserData', Data);
LocalRepaint(0);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% LocalRepaint
% initializes the window (display buttons, ...)
function LocalRepaint(KeepOldPlots)
figure(findobj('Tag', 'ViewEDFFigure'));
Data = get(gcf, 'UserData');
fhght = LocalGetFontHeight;
if length(Data.EDF)==0
  return;
end
if nargin < 1
  KeepOldPlots = 0;
end
KeepOldPlots = (KeepOldPlots ~= 0);

% set display size (area left for plots)
Data.Display.DrawRect = [0.005 1.5*fhght 0.85 1-1.5*fhght]; 

% get width of figure
unit = get(gcf, 'Units');
set(gcf, 'Units', 'Pixels');
xpix = get(gcf, 'Position');
set(gcf, 'Units', unit);
xpix = xpix(3);

% calculate total number of plots 
TotPlots = 0;
for i=1:length(Data.EDF)
  TotPlots = TotPlots + length(Data.Display.EDF(i).ShowSignals);
end
for i=1:length(Data.Plugin)
  TotPlots = TotPlots + length(Data.Display.Plugin(i).ShowSignals);
end

% update plugin-data
LocalWatchOn;
if Data.UpdatePlugin | ~KeepOldPlots
  for i = 1:length(Data.Plugin)
    [Data.Plugin(i).EDF, Data.Plugin(i).UserData] = ...
        feval(Data.Plugin(i).Name, Data.EDF(Data.Plugin(i).EDFFile), ...
        Data.Plugin(i).UserData);
  end
end
LocalWatchOff;

Opt.YSpace = Data.Display.YSpacing;
Opt.TxtHeight = fhght;
Opt.TextWidth = 1 - Data.Display.DrawRect(3) - Data.Display.DrawRect(1) - ...
    0.01; 
Opt.TextX = Data.Display.DrawRect(1) + Data.Display.DrawRect(3) + 0.005;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -