1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
| function ESSAI(varargin)
%%
% Error if an output argument is supplied.
if nargout > 0
error('Too many output arguments.');
end
%%
% Based on the number of input arguments call the appropriate
% local function.
switch nargin
case 0
% Create the analog input object.
data = localInitAI;
% Create the figure.
data = localInitFig(data);
hFig = data.handle.figure;
case 1
error('The ADAPTORNAME, ID and CHANID must be specified.');
case 2
% Initialize variables.
data = [];
action=varargin{1};
hFig=varargin{2};
% This may fail if only the ADAPTORNAME and ID were input. However,
% if the ID was 0, this will work.
try
data=get(hFig,'UserData');
end
% DATA will be empty if CHANID was not specified or if ID = 0.
if isempty(data)
error('The CHANID must be specified.');
end
% Based on the action, call the appropriate local function.
switch action
case 'close'
localClose(data);
case 'stop'
data = localStop(data);
end
case 3
% User specified the input - adaptor, id, chanNum.
% Create the analog input object.
[data, errflag] = localInitAI(varargin{:});
if errflag
error(lasterror)
end
% Create the figure.
data = localInitFig(data);
hFig = data.handle.figure;
end
%%
% Update the figure's UserData.
if ~isempty(hFig)&ishandle(hFig),
set(hFig,'UserData',data);
end
%%
% Update the analog input object's UserData.
if isvalid(data.ai)
set(data.ai, 'UserData', data);
end
%% ***********************************************************************
% Create the object and get the first fft.
function [data, errflag] = localInitAI(varargin)
% Initialize variables.
errflag = 0;
data = [];
%%
% Either no input arguments or all three - ADAPTORNAME, ID and CHANNELID.
switch nargin
case 0
adaptor = 'winsound';
id = 0;
chan = 1;
case 3
adaptor = varargin{1};
id = varargin{2};
chan = varargin{3};
otherwise
lasterr('The ADAPTORNAME, ID and CHANID must be specified.');
errflag = 1;
return;
end
%%
%%
% Object Configuration.
% Create an analog input object with one channel.
ai = analoginput(adaptor, id);
addchannel(ai, [1 2]);
%%
% Configure the analog input object.
set(ai, 'SampleRate', 44100);
timePeriod = 0.01;
%%
% Configure the analog input object to trigger manually twice.
set(ai, 'SamplesPerTrigger', timePeriod*ai.sampleRate);
set(ai, 'TriggerRepeat', 1);
set(ai, 'TriggerType', 'manual');
set(ai, 'TimerPeriod', timePeriod);
set(ai, 'BufferingConfig',[2048,20]);
%%
% Object Execution.
% Start the analog input object.
start(ai);
trigger(ai);
%%
% Obtain the available time and data.
[d,time] = getdata(ai, ai.SamplesPerTrigger);
%%
Fs = get(ai, 'SampleRate');
%%
% Update the data structure.
data.ai = ai;
data.handle = [];
%%
% Set the object's UserData to data.
set(data.ai, 'UserData', data);
%% ***********************************************************************
% Create the display.
function data = localInitFig(data)
fe=44100;
btnColor=get(0,'DefaultUIControlBackgroundColor');
screenUnits=get(0,'Units');
set(0,'Units','pixels');
screenSize=get(0,'ScreenSize');
set(0,'Units',screenUnits);
figWidth=600;
figHeight=360;
figPos=[(screenSize(3)-figWidth)/2 (screenSize(4)-figHeight)/2 ...
figWidth figHeight];
hFig=figure(...
'Color' ,btnColor ,...
'IntegerHandle' ,'off' ,...
'DoubleBuffer' ,'on' ,...
'DeleteFcn' ,'LOCA(''close'',gcbf)',...
'MenuBar' ,'none' ,...
'HandleVisibility' ,'on' ,...
'Name' ,'LOCA' ,...
'Tag' ,'LOCA' ,...
'NumberTitle' ,'off' ,...
'Units' ,'pixels' ,...
'Position' ,figPos ,...
'UserData' ,[] ,...
'Colormap' ,[0 0 0] ,...
'Pointer' ,'arrow' ,...
'Visible' ,'off' ...
);
set(hFig, 'Units','Normalize','OuterPosition',[0 0.035 1 0.965]);
%menu
hmenu(1) = uimenu('Parent', hFig,...
'Label', ' Fichier ');
hmenu(2) = uimenu(hmenu(1),...
'Label', ' Quitter ',...
'Callback', 'LOCA(''close'',gcbf)');
hmenu(3) = uimenu(hFig,...
'Label', ' Chargement ');
hmenu(4) = uimenu('Parent', hmenu(3),...
'Label', ' Signal ',...
'Callback', 'LOCA(''chargement1'',gcbf)');
hmenu(5) = uimenu('Parent', hmenu(3),...
'Label', ' Bruit ',...
'Callback', 'LOCA(''chargement2'',gcbf)');
data.handle.figure = hFig;
set(hFig,'Visible','on','UserData',data,'HandleVisibility', 'off');
% set(hIm(2:2:21),'Visible','off');
%%
% Configure the callback to update the display.
set(data.ai, 'TimerFcn', @localfftShowData);
%% ***********************************************************************
% Close the figure window.
function localClose(data)
%%
% Stop the device if it is running and delete the object.
if isvalid(data.ai)
if isrunning(data.ai)
stop(data.ai);
end
delete(data.ai);
end
%%
% Close the figure window.
delete(data.handle.figure);
%% ***********************************************************************
% Stop or start the device.
function data = localStop(data)
%%
% Based on the state either stop or start.
if isrunning(data.ai)
% Stop the device.
stop(data.ai);
set(data.handle.toggle(1), 'String', 'Start');
% Store the new state.
data.state(1) = 1;
else
% Toggle the Start/Stop string.
set(data.handle.toggle(1), 'String', 'Stop');
% Store the new state.
data.state(1) = 0;
% Start the device.
start(data.ai);
end
%% ***********************************************************************
% Update the plot.
function localfftShowData(obj,event)
%%
% Execute a peekdata.
x = peekdata(obj, obj.SamplesPerTrigger);
drawnow; |
Partager