+++ /dev/null
-function varargout = CNAQ(varargin)\r
-% CNAQ M-file for CNAQ.fig\r
-%\r
-% Copyright (c) 2007 Guillaume Pellerin <guillaume.pellerin@cnam.fr>\r
-% All rights reserved.\r
-\r
-% This software is governed by the CeCILL license under French law and\r
-% abiding by the rules of distribution of free software. You can use, \r
-% modify and/ or redistribute the software under the terms of the CeCILL\r
-% license as circulated by CEA, CNRS and INRIA at the following URL\r
-% "http://www.cecill.info". \r
-% \r
-% As a counterpart to the access to the source code and rights to copy,\r
-% modify and redistribute granted by the license, users are provided only\r
-% with a limited warranty and the software's author, the holder of the\r
-% economic rights, and the successive licensors have only limited\r
-% liability. \r
-% \r
-% In this respect, the user's attention is drawn to the risks associated\r
-% with loading, using, modifying and/or developing or reproducing the\r
-% software by the user in light of its specific status of free software,\r
-% that may mean that it is complicated to manipulate, and that also\r
-% therefore means that it is reserved for developers and experienced\r
-% professionals having in-depth computer knowledge. Users are therefore\r
-% encouraged to load and test the software's suitability as regards their\r
-% requirements in conditions enabling the security of their systems and/or \r
-% data to be ensured and, more generally, to use and operate it in the \r
-% same conditions as regards security. \r
-% \r
-% The fact that you are presently reading this means that you have had\r
-% knowledge of the CeCILL license given in the file COPYING and\r
-% that you accept its terms. The terms are also available at\r
-% http://svn.parisson.org/cnaq/wiki/CnacqLicense.\r
-\r
-% Author: Guillaume Pellerin <guillaume.pellerin@cnam.fr>\r
-\r
-% Last Modified by GUIDE v2.5 07-Nov-2007 18:26:57\r
-\r
-% CNAQ, by itself, creates a new CNAQ or raises the existing\r
-% singleton*.\r
-%\r
-% H = CNAQ returns the handle to a new CNAQ or the handle to\r
-% the existing singleton*.\r
-%\r
-% CNAQ('CALLBACK',hObject,eventData,handles,...) calls the local\r
-% function named CALLBACK in CNAQ.M with the given input arguments.\r
-%\r
-% CNAQ('Property','Value',...) creates a new CNAQ or raises the\r
-% existing singleton*. Starting from the left, property value pairs are\r
-% applied to the GUI before CNAQ_OpeningFunction gets called. An\r
-% unrecognized property name or invalid value makes property application\r
-% stop. All inputs are passed to CNAQ_OpeningFcn via varargin.\r
-%\r
-% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one\r
-% instance to run (singleton)".\r
-%\r
-% See also: GUIDE, GUIDATA, GUIHANDLES\r
-\r
-\r
-% Global variables\r
-\r
-% ==============================================================\r
-% Begin initialization code - DO NOT EDIT\r
-gui_Singleton = 1;\r
-gui_State = struct('gui_Name', mfilename, ...\r
- 'gui_Singleton', gui_Singleton, ...\r
- 'gui_OpeningFcn', @CNAQ_OpeningFcn, ...\r
- 'gui_OutputFcn', @CNAQ_OutputFcn, ...\r
- 'gui_LayoutFcn', [] , ...\r
- 'gui_Callback', []);\r
-if nargin && ischar(varargin{1})\r
- gui_State.gui_Callback = str2func(varargin{1});\r
-end\r
-\r
-if nargout\r
- [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});\r
-else\r
- gui_mainfcn(gui_State, varargin{:});\r
-end\r
-% End initialization code - DO NOT EDIT\r
-\r
-\r
-%global out_button_value in_button_value gen_button_value mes_button_value f_s n_bits;\r
-\r
-% --- Executes just before CNAQ is made visible.\r
-function CNAQ_OpeningFcn(hObject, eventdata, handles, varargin)\r
-% This function has no output args, see OutputFcn.\r
-% hObject handle to figure\r
-% eventdata reserved - to be defined in a future version of MATLAB\r
-% handles structure with handles and user data (see GUIDATA)\r
-% varargin command line arguments to CNAQ (see VARARGIN)\r
-\r
-% Choose default command line output for CNAQ\r
-handles.output = hObject;\r
-\r
-% Update handles structure\r
-guidata(hObject, handles);\r
-\r
-% --- Outputs from this function are returned to the command line.\r
-function varargout = CNAQ_OutputFcn(hObject, eventdata, handles) \r
-% varargout cell array for returning output args (see VARARGOUT);\r
-% hObject handle to figure\r
-% eventdata reserved - to be defined in a future version of MATLAB\r
-% handles structure with handles and user data (see GUIDATA)\r
-\r
-% Get default command line output from handles structure\r
-varargout{1} = handles.output;\r
-\r
-\r
-% UIWAIT makes CNAQ wait for user response (see UIRESUME)\r
-% uiwait(handles.figure1);\r
-% ==============================================================\r
-\r
-\r
-% ==============================================================\r
-% INIT\r
-% ==============================================================\r
-\r
-cnaq_version = '0.1';\r
-\r
-% Get/Set home_dir & paths\r
-root_dir = 'E:\CNAQ';\r
-home_dir = uigetdir(root_dir, 'Choisissez votre dossier de travail');\r
-set(handles.home_dir_box,'String',home_dir);\r
-\r
-% Get tools\r
-%cnaq_path = pwd;\r
-cnaq_path = root_dir;\r
-manu_path = [cnaq_path '\Manulab\'];\r
-tools_path = [cnaq_path '\tools\'];\r
-path(path, cnaq_path);\r
-path(path, manu_path);\r
-path(path, tools_path);\r
-\r
-% Get/Set ID\r
-id = get_id(handles);\r
-set(handles.ID,'String',id);\r
-\r
-set(handles.info1_text,'String',['CNAQ v' cnaq_version ' - Copyright (C) 2007']);\r
-set(handles.info2_text,'String','Guillaume Pellerin, Manuel Melon (CNAM Paris) http://svn.parisson.org/cnaq/');\r
-\r
-%set(handles.home_dir_box,'C:\CNAQ\');\r
-\r
-set(handles.f_gen_min,'String','20');\r
-set(handles.f_gen_max,'String','20000');\r
-set(handles.f_gen,'Value',1000);\r
-set(handles.f_gen,'Min',20);\r
-set(handles.f_gen,'Max',20000);\r
-set(handles.freq_value,'String','1000')\r
-\r
-set(handles.gain_in,'Value',-6.0);\r
-set(handles.gain_in_value,'String','-6.0');\r
-set(handles.gain_out,'Value',-6.0);\r
-set(handles.gain_out_value,'String','-6.0');\r
-\r
-set(handles.time_gen_min,'String','1');\r
-set(handles.time_gen_max,'String','20');\r
-set(handles.time_gen,'Value',5);\r
-set(handles.time_gen,'Min',1);\r
-set(handles.time_gen,'Max',20);\r
-set(handles.time_value,'String','5')\r
-\r
-set(handles.nbits,'String','16|24'); \r
-set(handles.f_s,'String','44100|48000|96000');\r
-\r
-%set(handles.out_on_off,'Value',0);\r
-set(handles.in_on_off,'Value',0);\r
-set(handles.gen_on_off,'Value',0);\r
-set(handles.sig_type,'String','Sinus|Chirp');\r
-set(handles.voices_in,'String','1|1 2|1 2 3|1 2 3 4');\r
-set(handles.voices_out,'String','1|1 2|1 2 3|1 2 3 4');\r
-\r
-buffer = 2048;\r
-os_sep = '\';\r
-\r
-% ==============================================================\r
-% TOOLS\r
-% ==============================================================\r
-\r
-function id = get_id(handles)\r
- home_dir = get(handles.home_dir_box,'String');\r
- id_file = [home_dir '\ID.m'];\r
- if exist(id_file) == 0\r
- id = '1';\r
- elseif exist(id_file) == 2\r
- fid = fopen(id_file, 'r');\r
- id = fgetl(fid);\r
- fclose(fid); \r
- end\r
-\r
-function increment_id(handles)\r
- home_dir = get(handles.home_dir_box,'String');\r
- id_file = [home_dir '\ID.m'];\r
- id = get_id(handles);\r
- id = num2str(str2double(id) + 1);\r
- fid = fopen(id_file, 'w+');\r
- fprintf(fid, id);\r
- fclose(fid);\r
- set(handles.ID,'String',id);\r
- \r
-function f_s = get_fs(handles)\r
- fs_ind = get(handles.f_s,'Value');\r
- if fs_ind == 1\r
- f_s = 44100;\r
- elseif fs_ind == 2\r
- f_s = 48000;\r
- elseif fs_ind == 3\r
- f_s = 96000;\r
- end\r
-\r
-function voices_out = get_voices_out(handles)\r
- vo_ind = get(handles.voices_out,'Value');\r
- if vo_ind == 1\r
- voices_out = [1];\r
- elseif vo_ind == 2\r
- voices_out = [1,2];\r
- elseif vo_ind == 3\r
- voices_out = [1,2,3];\r
- elseif vo_ind == 4\r
- voices_out = [1,2,3,4];\r
- end\r
- \r
-function voices_in = get_voices_in(handles)\r
- vi_ind = get(handles.voices_in,'Value');\r
- if vi_ind == 1\r
- voices_in = [1];\r
- elseif vi_ind == 2\r
- voices_in = [1 2];\r
- elseif vi_ind == 3\r
- voices_in = [1 2 3];\r
- elseif vi_ind == 4\r
- voices_in = [1 2 3 4];\r
- end\r
-\r
-function nbits = get_nbits(handles)\r
- nb_ind = get(handles.nbits,'Value');\r
- if nb_ind == 1\r
- nbits = 16;\r
- elseif nb_ind == 2\r
- nbits = 24;\r
- end\r
-\r
-\r
-%============================================\r
-% DONNEES\r
-%============================================\r
-\r
-function username_Callback(hObject, eventdata, handles)\r
-% hObject handle to username (see GCBO)\r
-% eventdata reserved - to be defined in a future version of MATLAB\r
-% handles structure with handles and user data (see GUIDATA)\r
-\r
-% Hints: get(hObject,'String') returns contents of username as text\r
-% str2double(get(hObject,'String')) returns contents of username as a double\r
-\r
-% --- Executes during object creation, after setting all properties.\r
-function username_CreateFcn(hObject, eventdata, handles)\r
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
- set(hObject,'BackgroundColor','white');\r
- end\r
-\r
-function comment_Callback(hObject, eventdata, handles)\r
-\r
-function comment_CreateFcn(hObject, eventdata, handles)\r
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
- set(hObject,'BackgroundColor','white');\r
- end\r
-\r
-function f_s_Callback(hObject, eventdata, handles)\r
-\r
-function f_s_CreateFcn(hObject, eventdata, handles)\r
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
- set(hObject,'BackgroundColor','white');\r
- end\r
-\r
-function nbits_Callback(hObject, eventdata, handles)\r
-\r
-function nbits_CreateFcn(hObject, eventdata, handles)\r
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
- set(hObject,'BackgroundColor','white');\r
- end\r
-\r
-function get_home_dir_Callback(hObject, eventdata, handles)\r
- home_dir = uigetdir;\r
- set(handles.home_dir_box,'String',home_dir);\r
- id = get_id(handles);\r
- set(handles.ID,'String',id);\r
- \r
- \r
-%============================================\r
-% MONITOR\r
-%============================================\r
- \r
-function in_on_off_Callback(hObject, eventdata, handles)\r
- device = 0;\r
- buffer = 4096;\r
- window = hanning(buffer);\r
- f_s = get_fs(handles);\r
- time = buffer/f_s;\r
- t = [0:1/f_s:time-1/f_s];\r
- \r
- f_min = str2double(get(handles.f_gen_min,'String'));\r
- f_max = str2double(get(handles.f_gen_max,'String'));\r
- freq = 2*(f_max-f_min)/buffer;\r
- f = [f_min:freq:f_max-freq];\r
- voices_in = get_voices_in(handles);\r
- voice_first = voices_in(1);\r
- voice_last = voices_in(length(voices_in));\r
- \r
- while get(handles.in_on_off,'Value') == 1\r
- % TIME_GEN\r
- %sig_in = wavrecord(buffer,f_s,2);\r
- sig_in = pa_wavrecord(voice_first, voice_last, buffer, f_s, device, 'asio');\r
- sig_in = sig_in(:,1);\r
- axes(handles.plot_in_temp);\r
- cla;\r
- %sig = sin(2*pi*10*t);\r
- plot(t,sig_in);\r
- grid on;\r
- \r
- % FREQ\r
- axes(handles.plot_in_freq);\r
- cla;\r
- fft_in = fft(sig_in.*window,buffer);\r
- log_abs_fft_in = 20*log10(2*abs(fft_in(1:round(buffer/2)))/buffer);\r
- semilogx(f,log_abs_fft_in);\r
- %axis([f_min f_max min(log_abs_fft_in) max(log_abs_fft_in)]);\r
- axis([f_min f_max -120 0]);\r
- grid on;\r
- drawnow;\r
- pause(0.01);\r
- end\r
-\r
- \r
-%============================================\r
-% VOIES\r
-%============================================\r
-\r
-function gain_in_Callback(hObject, eventdata, handles)\r
- set(handles.gain_in_value,'String',num2str(get(handles.gain_in,'Value')));\r
-\r
-function gain_in_CreateFcn(hObject, eventdata, handles)\r
- if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
- set(hObject,'BackgroundColor',[.9 .9 .9]);\r
- end\r
-\r
-function gain_out_Callback(hObject, eventdata, handles)\r
- set(handles.gain_out_value,'String',num2str(get(handles.gain_out,'Value')))\r
-\r
-function gain_out_CreateFcn(hObject, eventdata, handles)\r
- if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
- set(hObject,'BackgroundColor',[.9 .9 .9]);\r
- end\r
-\r
-function voices_in_Callback(hObject, eventdata, handles)\r
-\r
-function voices_in_CreateFcn(hObject, eventdata, handles)\r
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
- set(hObject,'BackgroundColor','white');\r
- end\r
-\r
-function voices_out_Callback(hObject, eventdata, handles)\r
-\r
-function voices_out_CreateFcn(hObject, eventdata, handles)\r
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
- set(hObject,'BackgroundColor','white');\r
- end\r
- \r
-%============================================\r
-% GENERATEUR\r
-%============================================\r
-\r
-function sig_type_Callback(hObject, eventdata, handles)\r
-\r
-function sig_type_CreateFcn(hObject, eventdata, handles)\r
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
- set(hObject,'BackgroundColor','white');\r
- end\r
-\r
-% TIME\r
-\r
-function time_gen_min_Callback(hObject, eventdata, handles)\r
- tg_min = str2double(get(handles.time_gen_min,'String'));\r
- tg_value = get(handles.time_gen,'Value');\r
- if tg_min > tg_value\r
- set(handles.time_gen,'String',num2str(tg_min));\r
- end\r
- set(handles.time_gen,'Min',tg_min);\r
-\r
-function time_gen_min_CreateFcn(hObject, eventdata, handles)\r
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
- set(hObject,'BackgroundColor','white');\r
- end\r
-\r
-function time_gen_max_Callback(hObject, eventdata, handles)\r
- tg_max = str2double(get(handles.time_gen_max,'String'));\r
- tg_value = get(handles.time_gen,'Value');\r
- if tg_max < tg_value\r
- set(handles.time_gen,'String',num2str(tg_max));\r
- end\r
- set(handles.time_gen,'Max',tg_max);\r
-\r
-function time_gen_max_CreateFcn(hObject, eventdata, handles)\r
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
- set(hObject,'BackgroundColor','white');\r
- end\r
-\r
-function time_gen_Callback(hObject, eventdata, handles)\r
- set(handles.time_value,'String',num2str(get(handles.time_gen,'Value')))\r
-\r
-function time_gen_CreateFcn(hObject, eventdata, handles)\r
- if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
- set(hObject,'BackgroundColor',[.9 .9 .9]);\r
- end\r
-\r
-\r
-% FREQ\r
-\r
-function f_gen_max_Callback(hObject, eventdata, handles)\r
- fg_max = str2double(get(handles.f_gen_max,'String'));\r
- fg_value = get(handles.f_gen,'Value');\r
- if fg_max < fg_value\r
- set(handles.f_gen,'String',num2str(fg_max));\r
- end\r
- set(handles.f_gen,'Max',fg_max); \r
-\r
-function f_gen_max_CreateFcn(hObject, eventdata, handles)\r
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
- set(hObject,'BackgroundColor','white');\r
- end\r
-\r
-function f_gen_min_Callback(hObject, eventdata, handles)\r
- fg_min = str2double(get(handles.f_gen_min,'String'));\r
- fg_value = get(handles.f_gen,'Value');\r
- if fg_min > fg_value\r
- set(handles.f_gen,'String',num2str(fg_min));\r
- end\r
- set(handles.f_gen,'Min',fg_min);\r
-\r
-function f_gen_min_CreateFcn(hObject, eventdata, handles)\r
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
- set(hObject,'BackgroundColor','white');\r
- end\r
-\r
-\r
-function f_gen_Callback(hObject, eventdata, handles)\r
- set(handles.freq_value,'String',num2str(get(handles.f_gen,'Value')));\r
-\r
-\r
-function f_gen_CreateFcn(hObject, eventdata, handles)\r
- if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
- set(hObject,'BackgroundColor',[.9 .9 .9]);\r
- end\r
-\r
-\r
-\r
-function gen_on_off_Callback(hObject, eventdata, handles)\r
-% Hint: get(hObject,'Value') returns toggle state of gen_on_off\r
- \r
- f_min = str2double(get(handles.f_gen_min,'String'));\r
- f_max = str2double(get(handles.f_gen_max,'String'));\r
- sig_type = get(handles.sig_type,'Value');\r
- sin_freq = get(handles.f_gen,'Value');\r
- f_s = get_fs(handles);\r
- time = get(handles.time_gen,'Value');\r
- voices_out = get_voices_out(handles);\r
- %voice_first = voices_out(1);\r
- %voice_last = voices_out(length(voices_out));\r
- gain_out = get(handles.gain_out,'Value');\r
- gain_out = 10^(gain_out/20);\r
- t = [0:1/f_s:time];\r
- \r
- if sig_type == 1\r
- % SINUS\r
- sig = gain_out*sin(2*pi*sin_freq*t);\r
- elseif sig_type == 2\r
- % CHIRP\r
- sig = gain_out*chirp(t,f_min,time,f_max,'logarithmic');\r
- end\r
- \r
- sig_out = [];\r
- for i=1:length(voices_out)\r
- sig_out(:,i) = sig';\r
- end\r
- \r
- % Matlab way...\r
- ao = analogoutput('winsound', 0);\r
- addchannel(ao, voices_out);\r
- set(ao, 'StandardSampleRates', 'Off');\r
- set(ao, 'SampleRate', f_s);\r
- \r
- if get(handles.gen_on_off,'Value') == 1\r
- putdata(ao, sig_out);\r
- start(ao);\r
- set(handles.gen_on_off,'Value',0);\r
- end\r
- \r
- %delete(ao);\r
-\r
- % PA way but can't work with monitor !...\r
- % pa_wavplay(sig_out',f_s,0,'asio');\r
-\r
-\r
-%============================================\r
-% MESURE\r
-%============================================\r
-\r
-function mes_type_Callback(hObject, eventdata, handles)\r
-\r
-function mes_type_CreateFcn(hObject, eventdata, handles)\r
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
- set(hObject,'BackgroundColor','white');\r
- end\r
-\r
-function mes_on_Callback(hObject, eventdata, handles)\r
- device = 0;\r
- nfft = 16384;\r
- f_min = str2double(get(handles.f_gen_min,'String'));\r
- f_max = str2double(get(handles.f_gen_max,'String'));\r
- f_s = get_fs(handles);\r
- time = get(handles.time_gen,'Value');\r
- voices_in = get_voices_in(handles);\r
- voice_first = voices_in(1);\r
- voice_last = voices_in(length(voices_in));\r
- gain_out = get(handles.gain_out,'Value');\r
- gain_out = 10^(gain_out/20);\r
- \r
- % Avoid Gibbs like phenomenon\r
- f0 = 0.1;\r
- f1 = f_min;\r
- f2 = f_max;\r
- f3 = f_s/2;\r
- fade_in_time = time/((log(f2/f0)/log(f1/f0))-1);\r
- fade_out_time = time*((log(f3/f1)/log(f2/f1))-1); \r
- total_time = fade_in_time + time + fade_out_time;\r
- t = [0:1/f_s:total_time];\r
- \r
- % Remove clicks durring emission and oscillations in the spectral response\r
- len_win_in = fade_in_time * f_s;\r
- window = blackman(len_win_in);\r
- len_win_in = round(len_win_in/2);\r
- window_in = window(1:len_win_in);\r
- \r
- len_win_out = fade_out_time * f_s;\r
- window = blackman (len_win_out);\r
- len_win_out = round(len_win_out/2);\r
- window_out = flipud(window(1:len_win_out));\r
- \r
- sig_exc = gain_out*chirp_farina(t,total_time,f0,f3);\r
- l_t = length(t);\r
- one(1:l_t-len_win_in-len_win_out) = 1;\r
- mask = [window_in' one window_out'];\r
- sig_exc = sig_exc.*mask;\r
- \r
- % Synchronizing\r
- %The number of samples in the buffer (latency of the sound card in\r
- %samples. See tests/testacqui.m)\r
- delay = 588; \r
- zero = zeros(1,delay);\r
- % Zeros are added before and removed after\r
- sig_exc_z = [sig_exc zero];\r
- len_sig_exc = length(sig_exc);\r
- \r
- % Make all voices\r
- sig_out = [];\r
- for i=1:length(voices_in)\r
- sig_out(:,i) = sig_exc_z';\r
- end\r
- \r
- % Measure\r
- sig_mes = pa_wavplayrecord(sig_out, device, f_s, 0, voice_first, voice_last, device, 'asio');\r
- % Usage:\r
- % inputbuffer = pa_wavplayrecord(playbuffer,[playdevice],[samplerate],\r
- % [recnsamples], [recfirstchannel], [reclastchannel],\r
- % [recdevice], [devicetype])\r
- \r
- % Resynchro\r
- len_sig_mes = length(sig_mes);\r
- size_sig_mes = size(sig_mes);\r
- n_col_sig_mes = size_sig_mes(2);\r
- sig_mes = sig_mes(delay+1:len_sig_mes,:);\r
- len_sig_mes = length(sig_mes);\r
- sig_exc = sig_exc';\r
- f = logspace(log10(f0), log10(f3), len_sig_mes)';\r
- \r
- % Save data\r
- set(handles.ID,'UserData',sig_mes);\r
- set(handles.id_title,'UserData',sig_exc);\r
- set(handles.mes_on,'UserData',f);\r
- \r
- % Get infos\r
- username = get(handles.username,'String');\r
- comment = get(handles.comment,'String');\r
- id = get(handles.ID,'String');\r
- \r
- % Compute excitation spectrum\r
- [rep_imp_exc, spec_exc] = fonc_trans(f, sig_exc, sig_exc);\r
- len_spec_exc = length(spec_exc);\r
- spec_exc = spec_exc(1:len_spec_exc/2);\r
- \r
- % Compute all Ris and specs\r
- for i=1:n_col_sig_mes\r
- voice = num2str(i);\r
- [rep_imp_mes, spec_mes] = fonc_trans(f, sig_exc, sig_mes(:,i));\r
- len_spec_mes = length(spec_mes); \r
- spec_mes = spec_mes(1:len_spec_mes/2);\r
- % Plot results\r
- f_lin = [0:f_s/len_spec_mes:f_s/2];\r
- f_lin = f_lin(1:length(f_lin)-1);\r
- plot_mes(t, f_lin, f_s, f_min, f_max, sig_exc, sig_mes(:,i), rep_imp_mes, spec_mes, spec_exc, id, voice, username, comment, i);\r
- end\r
- \r
- set(handles.close_button,'UserData',f_lin');\r
- set(handles.plot,'UserData',t);\r
-\r
- \r
-% Close all figures\r
-% --- Executes on button press in close_button.\r
-function close_button_Callback(hObject, eventdata, handles)\r
-% hObject handle to close_button (see GCBO)\r
-% eventdata reserved - to be defined in a future version of MATLAB\r
-% handles structure with handles and user data (see GUIDATA)\r
- close all;\r
- \r
-\r
-% --- Executes on button press in plot.\r
-function plot_Callback(hObject, eventdata, handles)\r
-% hObject handle to plot (see GCBO)\r
-% eventdata reserved - to be defined in a future version of MATLAB\r
-% handles structure with handles and user data (see GUIDATA)\r
- \r
- % Get data\r
- sig_mes = get(handles.ID,'UserData');\r
- sig_exc = get(handles.id_title,'UserData');\r
- f = get(handles.mes_on,'UserData');\r
- t = get(handles.plot,'UserData');\r
- f_min = str2double(get(handles.f_gen_min,'String'));\r
- f_max = str2double(get(handles.f_gen_max,'String'));\r
- f_s = get_fs(handles);\r
- \r
- % Get infos\r
- username = get(handles.username,'String');\r
- comment = get(handles.comment,'String');\r
- id = get(handles.ID,'String');\r
- \r
- % Compute excitation spectrum\r
- [rep_imp_exc, spec_exc] = fonc_trans(f, sig_exc, sig_exc);\r
- len_spec_exc = length(spec_exc);\r
- spec_exc = spec_exc(1:len_spec_exc/2);\r
- \r
- size_sig_mes = size(sig_mes);\r
- n_col_sig_mes = size_sig_mes(2);\r
- \r
- % Compute all Ris and specs\r
- for i=1:n_col_sig_mes\r
- voice = num2str(i);\r
- [rep_imp_mes, spec_mes] = fonc_trans(f, sig_exc, sig_mes(:,i));\r
- len_spec_mes = length(spec_mes); \r
- spec_mes = spec_mes(1:len_spec_mes/2);\r
- % Plot results\r
- f_lin = [0:f_s/len_spec_mes:f_s/2];\r
- f_lin = f_lin(1:length(f_lin)-1);\r
- plot_mes(t, f_lin, f_s, f_min, f_max, sig_exc, sig_mes(:,i), rep_imp_mes, spec_mes, spec_exc, id, voice, username, comment, i);\r
- end\r
-\r
- \r
-% SAVE all data in a mat file \r
-function save_button_Callback(hObject, eventdata, handles) \r
- % Get data\r
- id = get(handles.ID,'String');\r
- username = get(handles.username,'String');\r
- home_dir = get(handles.home_dir_box,'String');\r
- comment = get(handles.comment,'String');\r
- sig_exc = get(handles.id_title,'UserData');\r
- sig_mes = get(handles.ID,'UserData');\r
- f_log = get(handles.mes_on,'UserData');\r
- f_lin = get(handles.close_button,'UserData');\r
- f_s = get_fs(handles);\r
- nbits = get_nbits(handles);\r
- f_min = str2double(get(handles.f_gen_min,'String'));\r
- f_max = str2double(get(handles.f_gen_max,'String'));\r
- time = get(handles.time_gen,'Value');\r
- voices_in = get_voices_in(handles);\r
- gain_in = get(handles.gain_in,'Value');\r
- voices_out = get_voices_out(handles);\r
- gain_out = get(handles.gain_out,'Value');\r
- \r
- % Save it\r
- file = [home_dir '\' username '_' id '.mat'];\r
- save(file);\r
- \r
- % Clear big data\r
- set(handles.ID,'UserData',[]);\r
- set(handles.id_title,'UserData',[]);\r
- set(handles.mes_on,'UserData',[]);\r
- \r
- % Increment ID\r
- increment_id(handles);\r
- \r
- \r
-\r
- \r
-\r
-\r
--- /dev/null
+function varargout = CNAQ(varargin)\r
+% CNAQ M-file for CNAQ.fig\r
+%\r
+% Copyright (c) 2007 Guillaume Pellerin <guillaume.pellerin@cnam.fr>\r
+% All rights reserved.\r
+\r
+% This software is governed by the CeCILL license under French law and\r
+% abiding by the rules of distribution of free software. You can use, \r
+% modify and/ or redistribute the software under the terms of the CeCILL\r
+% license as circulated by CEA, CNRS and INRIA at the following URL\r
+% "http://www.cecill.info". \r
+% \r
+% As a counterpart to the access to the source code and rights to copy,\r
+% modify and redistribute granted by the license, users are provided only\r
+% with a limited warranty and the software's author, the holder of the\r
+% economic rights, and the successive licensors have only limited\r
+% liability. \r
+% \r
+% In this respect, the user's attention is drawn to the risks associated\r
+% with loading, using, modifying and/or developing or reproducing the\r
+% software by the user in light of its specific status of free software,\r
+% that may mean that it is complicated to manipulate, and that also\r
+% therefore means that it is reserved for developers and experienced\r
+% professionals having in-depth computer knowledge. Users are therefore\r
+% encouraged to load and test the software's suitability as regards their\r
+% requirements in conditions enabling the security of their systems and/or \r
+% data to be ensured and, more generally, to use and operate it in the \r
+% same conditions as regards security. \r
+% \r
+% The fact that you are presently reading this means that you have had\r
+% knowledge of the CeCILL license given in the file COPYING and\r
+% that you accept its terms. The terms are also available at\r
+% http://svn.parisson.org/cnaq/wiki/CnacqLicense.\r
+\r
+% Author: Guillaume Pellerin <guillaume.pellerin@cnam.fr>\r
+\r
+% Last Modified by GUIDE v2.5 07-Nov-2007 18:26:57\r
+\r
+% CNAQ, by itself, creates a new CNAQ or raises the existing\r
+% singleton*.\r
+%\r
+% H = CNAQ returns the handle to a new CNAQ or the handle to\r
+% the existing singleton*.\r
+%\r
+% CNAQ('CALLBACK',hObject,eventData,handles,...) calls the local\r
+% function named CALLBACK in CNAQ.M with the given input arguments.\r
+%\r
+% CNAQ('Property','Value',...) creates a new CNAQ or raises the\r
+% existing singleton*. Starting from the left, property value pairs are\r
+% applied to the GUI before CNAQ_OpeningFunction gets called. An\r
+% unrecognized property name or invalid value makes property application\r
+% stop. All inputs are passed to CNAQ_OpeningFcn via varargin.\r
+%\r
+% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one\r
+% instance to run (singleton)".\r
+%\r
+% See also: GUIDE, GUIDATA, GUIHANDLES\r
+\r
+\r
+% Global variables\r
+\r
+% ==============================================================\r
+% Begin initialization code - DO NOT EDIT\r
+gui_Singleton = 1;\r
+gui_State = struct('gui_Name', mfilename, ...\r
+ 'gui_Singleton', gui_Singleton, ...\r
+ 'gui_OpeningFcn', @CNAQ_OpeningFcn, ...\r
+ 'gui_OutputFcn', @CNAQ_OutputFcn, ...\r
+ 'gui_LayoutFcn', [] , ...\r
+ 'gui_Callback', []);\r
+if nargin && ischar(varargin{1})\r
+ gui_State.gui_Callback = str2func(varargin{1});\r
+end\r
+\r
+if nargout\r
+ [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});\r
+else\r
+ gui_mainfcn(gui_State, varargin{:});\r
+end\r
+% End initialization code - DO NOT EDIT\r
+\r
+\r
+%global out_button_value in_button_value gen_button_value mes_button_value f_s n_bits;\r
+\r
+% --- Executes just before CNAQ is made visible.\r
+function CNAQ_OpeningFcn(hObject, eventdata, handles, varargin)\r
+% This function has no output args, see OutputFcn.\r
+% hObject handle to figure\r
+% eventdata reserved - to be defined in a future version of MATLAB\r
+% handles structure with handles and user data (see GUIDATA)\r
+% varargin command line arguments to CNAQ (see VARARGIN)\r
+\r
+% Choose default command line output for CNAQ\r
+handles.output = hObject;\r
+\r
+% Update handles structure\r
+guidata(hObject, handles);\r
+\r
+% --- Outputs from this function are returned to the command line.\r
+function varargout = CNAQ_OutputFcn(hObject, eventdata, handles) \r
+% varargout cell array for returning output args (see VARARGOUT);\r
+% hObject handle to figure\r
+% eventdata reserved - to be defined in a future version of MATLAB\r
+% handles structure with handles and user data (see GUIDATA)\r
+\r
+% Get default command line output from handles structure\r
+varargout{1} = handles.output;\r
+\r
+\r
+% UIWAIT makes CNAQ wait for user response (see UIRESUME)\r
+% uiwait(handles.figure1);\r
+% ==============================================================\r
+\r
+\r
+% ==============================================================\r
+% INIT\r
+% ==============================================================\r
+\r
+cnaq_version = '0.1';\r
+\r
+% Get/Set home_dir & paths\r
+root_dir = 'E:\CNAQ';\r
+home_dir = uigetdir(root_dir, 'Choisissez votre dossier de travail');\r
+set(handles.home_dir_box,'String',home_dir);\r
+\r
+% Get tools\r
+%cnaq_path = pwd;\r
+cnaq_path = root_dir;\r
+manu_path = [cnaq_path '\Manulab\'];\r
+tools_path = [cnaq_path '\tools\'];\r
+path(path, cnaq_path);\r
+path(path, manu_path);\r
+path(path, tools_path);\r
+\r
+% Get/Set ID\r
+id = get_id(handles);\r
+set(handles.ID,'String',id);\r
+\r
+set(handles.info1_text,'String',['CNAQ v' cnaq_version ' - Copyright (C) 2007']);\r
+set(handles.info2_text,'String','Guillaume Pellerin, Manuel Melon (CNAM Paris) http://svn.parisson.org/cnaq/');\r
+\r
+%set(handles.home_dir_box,'C:\CNAQ\');\r
+\r
+set(handles.f_gen_min,'String','20');\r
+set(handles.f_gen_max,'String','20000');\r
+set(handles.f_gen,'Value',1000);\r
+set(handles.f_gen,'Min',20);\r
+set(handles.f_gen,'Max',20000);\r
+set(handles.freq_value,'String','1000')\r
+\r
+set(handles.gain_in,'Value',-6.0);\r
+set(handles.gain_in_value,'String','-6.0');\r
+set(handles.gain_out,'Value',-6.0);\r
+set(handles.gain_out_value,'String','-6.0');\r
+\r
+set(handles.time_gen_min,'String','1');\r
+set(handles.time_gen_max,'String','20');\r
+set(handles.time_gen,'Value',5);\r
+set(handles.time_gen,'Min',1);\r
+set(handles.time_gen,'Max',20);\r
+set(handles.time_value,'String','5')\r
+\r
+set(handles.nbits,'String','16|24'); \r
+set(handles.f_s,'String','44100|48000|96000');\r
+\r
+%set(handles.out_on_off,'Value',0);\r
+set(handles.in_on_off,'Value',0);\r
+set(handles.gen_on_off,'Value',0);\r
+set(handles.sig_type,'String','Sinus|Chirp');\r
+set(handles.voices_in,'String','1|1 2|1 2 3|1 2 3 4');\r
+set(handles.voices_out,'String','1|1 2|1 2 3|1 2 3 4');\r
+\r
+buffer = 2048;\r
+os_sep = '\';\r
+\r
+% ==============================================================\r
+% TOOLS\r
+% ==============================================================\r
+\r
+function id = get_id(handles)\r
+ home_dir = get(handles.home_dir_box,'String');\r
+ id_file = [home_dir '\ID.m'];\r
+ if exist(id_file) == 0\r
+ id = '1';\r
+ elseif exist(id_file) == 2\r
+ fid = fopen(id_file, 'r');\r
+ id = fgetl(fid);\r
+ fclose(fid); \r
+ end\r
+\r
+function increment_id(handles)\r
+ home_dir = get(handles.home_dir_box,'String');\r
+ id_file = [home_dir '\ID.m'];\r
+ id = get_id(handles);\r
+ id = num2str(str2double(id) + 1);\r
+ fid = fopen(id_file, 'w+');\r
+ fprintf(fid, id);\r
+ fclose(fid);\r
+ set(handles.ID,'String',id);\r
+ \r
+function f_s = get_fs(handles)\r
+ fs_ind = get(handles.f_s,'Value');\r
+ if fs_ind == 1\r
+ f_s = 44100;\r
+ elseif fs_ind == 2\r
+ f_s = 48000;\r
+ elseif fs_ind == 3\r
+ f_s = 96000;\r
+ end\r
+\r
+function voices_out = get_voices_out(handles)\r
+ vo_ind = get(handles.voices_out,'Value');\r
+ if vo_ind == 1\r
+ voices_out = [1];\r
+ elseif vo_ind == 2\r
+ voices_out = [1,2];\r
+ elseif vo_ind == 3\r
+ voices_out = [1,2,3];\r
+ elseif vo_ind == 4\r
+ voices_out = [1,2,3,4];\r
+ end\r
+ \r
+function voices_in = get_voices_in(handles)\r
+ vi_ind = get(handles.voices_in,'Value');\r
+ if vi_ind == 1\r
+ voices_in = [1];\r
+ elseif vi_ind == 2\r
+ voices_in = [1 2];\r
+ elseif vi_ind == 3\r
+ voices_in = [1 2 3];\r
+ elseif vi_ind == 4\r
+ voices_in = [1 2 3 4];\r
+ end\r
+\r
+function nbits = get_nbits(handles)\r
+ nb_ind = get(handles.nbits,'Value');\r
+ if nb_ind == 1\r
+ nbits = 16;\r
+ elseif nb_ind == 2\r
+ nbits = 24;\r
+ end\r
+\r
+\r
+%============================================\r
+% DONNEES\r
+%============================================\r
+\r
+function username_Callback(hObject, eventdata, handles)\r
+% hObject handle to username (see GCBO)\r
+% eventdata reserved - to be defined in a future version of MATLAB\r
+% handles structure with handles and user data (see GUIDATA)\r
+\r
+% Hints: get(hObject,'String') returns contents of username as text\r
+% str2double(get(hObject,'String')) returns contents of username as a double\r
+\r
+% --- Executes during object creation, after setting all properties.\r
+function username_CreateFcn(hObject, eventdata, handles)\r
+ if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
+ set(hObject,'BackgroundColor','white');\r
+ end\r
+\r
+function comment_Callback(hObject, eventdata, handles)\r
+\r
+function comment_CreateFcn(hObject, eventdata, handles)\r
+ if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
+ set(hObject,'BackgroundColor','white');\r
+ end\r
+\r
+function f_s_Callback(hObject, eventdata, handles)\r
+\r
+function f_s_CreateFcn(hObject, eventdata, handles)\r
+ if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
+ set(hObject,'BackgroundColor','white');\r
+ end\r
+\r
+function nbits_Callback(hObject, eventdata, handles)\r
+\r
+function nbits_CreateFcn(hObject, eventdata, handles)\r
+ if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
+ set(hObject,'BackgroundColor','white');\r
+ end\r
+\r
+function get_home_dir_Callback(hObject, eventdata, handles)\r
+ home_dir = uigetdir;\r
+ set(handles.home_dir_box,'String',home_dir);\r
+ id = get_id(handles);\r
+ set(handles.ID,'String',id);\r
+ \r
+ \r
+%============================================\r
+% MONITOR\r
+%============================================\r
+ \r
+function in_on_off_Callback(hObject, eventdata, handles)\r
+ device = 0;\r
+ buffer = 4096;\r
+ window = hanning(buffer);\r
+ f_s = get_fs(handles);\r
+ time = buffer/f_s;\r
+ t = [0:1/f_s:time-1/f_s];\r
+ \r
+ f_min = str2double(get(handles.f_gen_min,'String'));\r
+ f_max = str2double(get(handles.f_gen_max,'String'));\r
+ freq = 2*(f_max-f_min)/buffer;\r
+ f = [f_min:freq:f_max-freq];\r
+ voices_in = get_voices_in(handles);\r
+ voice_first = voices_in(1);\r
+ voice_last = voices_in(length(voices_in));\r
+ \r
+ while get(handles.in_on_off,'Value') == 1\r
+ % TIME_GEN\r
+ %sig_in = wavrecord(buffer,f_s,2);\r
+ sig_in = pa_wavrecord(voice_first, voice_last, buffer, f_s, device, 'asio');\r
+ sig_in = sig_in(:,1);\r
+ axes(handles.plot_in_temp);\r
+ cla;\r
+ %sig = sin(2*pi*10*t);\r
+ plot(t,sig_in);\r
+ grid on;\r
+ \r
+ % FREQ\r
+ axes(handles.plot_in_freq);\r
+ cla;\r
+ fft_in = fft(sig_in.*window,buffer);\r
+ log_abs_fft_in = 20*log10(2*abs(fft_in(1:round(buffer/2)))/buffer);\r
+ semilogx(f,log_abs_fft_in);\r
+ %axis([f_min f_max min(log_abs_fft_in) max(log_abs_fft_in)]);\r
+ axis([f_min f_max -120 0]);\r
+ grid on;\r
+ drawnow;\r
+ pause(0.01);\r
+ end\r
+\r
+ \r
+%============================================\r
+% VOIES\r
+%============================================\r
+\r
+function gain_in_Callback(hObject, eventdata, handles)\r
+ set(handles.gain_in_value,'String',num2str(get(handles.gain_in,'Value')));\r
+\r
+function gain_in_CreateFcn(hObject, eventdata, handles)\r
+ if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
+ set(hObject,'BackgroundColor',[.9 .9 .9]);\r
+ end\r
+\r
+function gain_out_Callback(hObject, eventdata, handles)\r
+ set(handles.gain_out_value,'String',num2str(get(handles.gain_out,'Value')))\r
+\r
+function gain_out_CreateFcn(hObject, eventdata, handles)\r
+ if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
+ set(hObject,'BackgroundColor',[.9 .9 .9]);\r
+ end\r
+\r
+function voices_in_Callback(hObject, eventdata, handles)\r
+\r
+function voices_in_CreateFcn(hObject, eventdata, handles)\r
+ if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
+ set(hObject,'BackgroundColor','white');\r
+ end\r
+\r
+function voices_out_Callback(hObject, eventdata, handles)\r
+\r
+function voices_out_CreateFcn(hObject, eventdata, handles)\r
+ if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
+ set(hObject,'BackgroundColor','white');\r
+ end\r
+ \r
+%============================================\r
+% GENERATEUR\r
+%============================================\r
+\r
+function sig_type_Callback(hObject, eventdata, handles)\r
+\r
+function sig_type_CreateFcn(hObject, eventdata, handles)\r
+ if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
+ set(hObject,'BackgroundColor','white');\r
+ end\r
+\r
+% TIME\r
+\r
+function time_gen_min_Callback(hObject, eventdata, handles)\r
+ tg_min = str2double(get(handles.time_gen_min,'String'));\r
+ tg_value = get(handles.time_gen,'Value');\r
+ if tg_min > tg_value\r
+ set(handles.time_gen,'String',num2str(tg_min));\r
+ end\r
+ set(handles.time_gen,'Min',tg_min);\r
+\r
+function time_gen_min_CreateFcn(hObject, eventdata, handles)\r
+ if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
+ set(hObject,'BackgroundColor','white');\r
+ end\r
+\r
+function time_gen_max_Callback(hObject, eventdata, handles)\r
+ tg_max = str2double(get(handles.time_gen_max,'String'));\r
+ tg_value = get(handles.time_gen,'Value');\r
+ if tg_max < tg_value\r
+ set(handles.time_gen,'String',num2str(tg_max));\r
+ end\r
+ set(handles.time_gen,'Max',tg_max);\r
+\r
+function time_gen_max_CreateFcn(hObject, eventdata, handles)\r
+ if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
+ set(hObject,'BackgroundColor','white');\r
+ end\r
+\r
+function time_gen_Callback(hObject, eventdata, handles)\r
+ set(handles.time_value,'String',num2str(get(handles.time_gen,'Value')))\r
+\r
+function time_gen_CreateFcn(hObject, eventdata, handles)\r
+ if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
+ set(hObject,'BackgroundColor',[.9 .9 .9]);\r
+ end\r
+\r
+\r
+% FREQ\r
+\r
+function f_gen_max_Callback(hObject, eventdata, handles)\r
+ fg_max = str2double(get(handles.f_gen_max,'String'));\r
+ fg_value = get(handles.f_gen,'Value');\r
+ if fg_max < fg_value\r
+ set(handles.f_gen,'String',num2str(fg_max));\r
+ end\r
+ set(handles.f_gen,'Max',fg_max); \r
+\r
+function f_gen_max_CreateFcn(hObject, eventdata, handles)\r
+ if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
+ set(hObject,'BackgroundColor','white');\r
+ end\r
+\r
+function f_gen_min_Callback(hObject, eventdata, handles)\r
+ fg_min = str2double(get(handles.f_gen_min,'String'));\r
+ fg_value = get(handles.f_gen,'Value');\r
+ if fg_min > fg_value\r
+ set(handles.f_gen,'String',num2str(fg_min));\r
+ end\r
+ set(handles.f_gen,'Min',fg_min);\r
+\r
+function f_gen_min_CreateFcn(hObject, eventdata, handles)\r
+ if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
+ set(hObject,'BackgroundColor','white');\r
+ end\r
+\r
+\r
+function f_gen_Callback(hObject, eventdata, handles)\r
+ set(handles.freq_value,'String',num2str(get(handles.f_gen,'Value')));\r
+\r
+\r
+function f_gen_CreateFcn(hObject, eventdata, handles)\r
+ if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
+ set(hObject,'BackgroundColor',[.9 .9 .9]);\r
+ end\r
+\r
+\r
+\r
+function gen_on_off_Callback(hObject, eventdata, handles)\r
+% Hint: get(hObject,'Value') returns toggle state of gen_on_off\r
+ \r
+ f_min = str2double(get(handles.f_gen_min,'String'));\r
+ f_max = str2double(get(handles.f_gen_max,'String'));\r
+ sig_type = get(handles.sig_type,'Value');\r
+ sin_freq = get(handles.f_gen,'Value');\r
+ f_s = get_fs(handles);\r
+ time = get(handles.time_gen,'Value');\r
+ voices_out = get_voices_out(handles);\r
+ %voice_first = voices_out(1);\r
+ %voice_last = voices_out(length(voices_out));\r
+ gain_out = get(handles.gain_out,'Value');\r
+ gain_out = 10^(gain_out/20);\r
+ t = [0:1/f_s:time];\r
+ \r
+ if sig_type == 1\r
+ % SINUS\r
+ sig = gain_out*sin(2*pi*sin_freq*t);\r
+ elseif sig_type == 2\r
+ % CHIRP\r
+ sig = gain_out*chirp(t,f_min,time,f_max,'logarithmic');\r
+ end\r
+ \r
+ sig_out = [];\r
+ for i=1:length(voices_out)\r
+ sig_out(:,i) = sig';\r
+ end\r
+ \r
+ % Matlab way...\r
+ ao = analogoutput('winsound', 0);\r
+ addchannel(ao, voices_out);\r
+ set(ao, 'StandardSampleRates', 'Off');\r
+ set(ao, 'SampleRate', f_s);\r
+ \r
+ if get(handles.gen_on_off,'Value') == 1\r
+ putdata(ao, sig_out);\r
+ start(ao);\r
+ set(handles.gen_on_off,'Value',0);\r
+ end\r
+ \r
+ %delete(ao);\r
+\r
+ % PA way but can't work with monitor !...\r
+ % pa_wavplay(sig_out',f_s,0,'asio');\r
+\r
+\r
+%============================================\r
+% MESURE\r
+%============================================\r
+\r
+function mes_type_Callback(hObject, eventdata, handles)\r
+\r
+function mes_type_CreateFcn(hObject, eventdata, handles)\r
+ if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))\r
+ set(hObject,'BackgroundColor','white');\r
+ end\r
+\r
+function mes_on_Callback(hObject, eventdata, handles)\r
+ device = 0;\r
+ nfft = 16384;\r
+ f_min = str2double(get(handles.f_gen_min,'String'));\r
+ f_max = str2double(get(handles.f_gen_max,'String'));\r
+ f_s = get_fs(handles);\r
+ time = get(handles.time_gen,'Value');\r
+ voices_in = get_voices_in(handles);\r
+ voice_first = voices_in(1);\r
+ voice_last = voices_in(length(voices_in));\r
+ gain_out = get(handles.gain_out,'Value');\r
+ gain_out = 10^(gain_out/20);\r
+ \r
+ % Avoid Gibbs like phenomenon\r
+ f0 = 0.1;\r
+ f1 = f_min;\r
+ f2 = f_max;\r
+ f3 = f_s/2;\r
+ fade_in_time = time/((log(f2/f0)/log(f1/f0))-1);\r
+ fade_out_time = time*((log(f3/f1)/log(f2/f1))-1); \r
+ total_time = fade_in_time + time + fade_out_time;\r
+ t = [0:1/f_s:total_time];\r
+ \r
+ % Remove clicks durring emission and oscillations in the spectral response\r
+ len_win_in = fade_in_time * f_s;\r
+ window = blackman(len_win_in);\r
+ len_win_in = round(len_win_in/2);\r
+ window_in = window(1:len_win_in);\r
+ \r
+ len_win_out = fade_out_time * f_s;\r
+ window = blackman (len_win_out);\r
+ len_win_out = round(len_win_out/2);\r
+ window_out = flipud(window(1:len_win_out));\r
+ \r
+ sig_exc = gain_out*chirp_farina(t,total_time,f0,f3);\r
+ l_t = length(t);\r
+ one(1:l_t-len_win_in-len_win_out) = 1;\r
+ mask = [window_in' one window_out'];\r
+ sig_exc = sig_exc.*mask;\r
+ \r
+ % Synchronizing\r
+ %The number of samples in the buffer (latency of the sound card in\r
+ %samples. See tests/testacqui.m)\r
+ delay = 588; \r
+ zero = zeros(1,delay);\r
+ % Zeros are added before and removed after\r
+ sig_exc_z = [sig_exc zero];\r
+ len_sig_exc = length(sig_exc);\r
+ \r
+ % Make all voices\r
+ sig_out = [];\r
+ for i=1:length(voices_in)\r
+ sig_out(:,i) = sig_exc_z';\r
+ end\r
+ \r
+ % Measure\r
+ sig_mes = pa_wavplayrecord(sig_out, device, f_s, 0, voice_first, voice_last, device, 'asio');\r
+ % Usage:\r
+ % inputbuffer = pa_wavplayrecord(playbuffer,[playdevice],[samplerate],\r
+ % [recnsamples], [recfirstchannel], [reclastchannel],\r
+ % [recdevice], [devicetype])\r
+ \r
+ % Resynchro\r
+ len_sig_mes = length(sig_mes);\r
+ size_sig_mes = size(sig_mes);\r
+ n_col_sig_mes = size_sig_mes(2);\r
+ sig_mes = sig_mes(delay+1:len_sig_mes,:);\r
+ len_sig_mes = length(sig_mes);\r
+ sig_exc = sig_exc';\r
+ f = logspace(log10(f0), log10(f3), len_sig_mes)';\r
+ \r
+ % Save data\r
+ set(handles.ID,'UserData',sig_mes);\r
+ set(handles.id_title,'UserData',sig_exc);\r
+ set(handles.mes_on,'UserData',f);\r
+ \r
+ % Get infos\r
+ username = get(handles.username,'String');\r
+ comment = get(handles.comment,'String');\r
+ id = get(handles.ID,'String');\r
+ \r
+ % Compute excitation spectrum\r
+ [rep_imp_exc, spec_exc] = fonc_trans(f, sig_exc, sig_exc);\r
+ len_spec_exc = length(spec_exc);\r
+ spec_exc = spec_exc(1:len_spec_exc/2);\r
+ \r
+ % Compute all Ris and specs\r
+ for i=1:n_col_sig_mes\r
+ voice = num2str(i);\r
+ [rep_imp_mes, spec_mes] = fonc_trans(f, sig_exc, sig_mes(:,i));\r
+ len_spec_mes = length(spec_mes); \r
+ spec_mes = spec_mes(1:len_spec_mes/2);\r
+ % Plot results\r
+ f_lin = [0:f_s/len_spec_mes:f_s/2];\r
+ f_lin = f_lin(1:length(f_lin)-1);\r
+ plot_mes(t, f_lin, f_s, f_min, f_max, sig_exc, sig_mes(:,i), rep_imp_mes, spec_mes, spec_exc, id, voice, username, comment, i);\r
+ end\r
+ \r
+ set(handles.close_button,'UserData',f_lin');\r
+ set(handles.plot,'UserData',t);\r
+\r
+ \r
+% Close all figures\r
+% --- Executes on button press in close_button.\r
+function close_button_Callback(hObject, eventdata, handles)\r
+% hObject handle to close_button (see GCBO)\r
+% eventdata reserved - to be defined in a future version of MATLAB\r
+% handles structure with handles and user data (see GUIDATA)\r
+ close all;\r
+ \r
+\r
+% --- Executes on button press in plot.\r
+function plot_Callback(hObject, eventdata, handles)\r
+% hObject handle to plot (see GCBO)\r
+% eventdata reserved - to be defined in a future version of MATLAB\r
+% handles structure with handles and user data (see GUIDATA)\r
+ \r
+ % Get data\r
+ sig_mes = get(handles.ID,'UserData');\r
+ sig_exc = get(handles.id_title,'UserData');\r
+ f = get(handles.mes_on,'UserData');\r
+ t = get(handles.plot,'UserData');\r
+ f_min = str2double(get(handles.f_gen_min,'String'));\r
+ f_max = str2double(get(handles.f_gen_max,'String'));\r
+ f_s = get_fs(handles);\r
+ \r
+ % Get infos\r
+ username = get(handles.username,'String');\r
+ comment = get(handles.comment,'String');\r
+ id = get(handles.ID,'String');\r
+ \r
+ % Compute excitation spectrum\r
+ [rep_imp_exc, spec_exc] = fonc_trans(f, sig_exc, sig_exc);\r
+ len_spec_exc = length(spec_exc);\r
+ spec_exc = spec_exc(1:len_spec_exc/2);\r
+ \r
+ size_sig_mes = size(sig_mes);\r
+ n_col_sig_mes = size_sig_mes(2);\r
+ \r
+ % Compute all Ris and specs\r
+ for i=1:n_col_sig_mes\r
+ voice = num2str(i);\r
+ [rep_imp_mes, spec_mes] = fonc_trans(f, sig_exc, sig_mes(:,i));\r
+ len_spec_mes = length(spec_mes); \r
+ spec_mes = spec_mes(1:len_spec_mes/2);\r
+ % Plot results\r
+ f_lin = [0:f_s/len_spec_mes:f_s/2];\r
+ f_lin = f_lin(1:length(f_lin)-1);\r
+ plot_mes(t, f_lin, f_s, f_min, f_max, sig_exc, sig_mes(:,i), rep_imp_mes, spec_mes, spec_exc, id, voice, username, comment, i);\r
+ end\r
+\r
+ \r
+% SAVE all data in a mat file \r
+function save_button_Callback(hObject, eventdata, handles) \r
+ % Get data\r
+ id = get(handles.ID,'String');\r
+ username = get(handles.username,'String');\r
+ home_dir = get(handles.home_dir_box,'String');\r
+ comment = get(handles.comment,'String');\r
+ sig_exc = get(handles.id_title,'UserData');\r
+ sig_mes = get(handles.ID,'UserData');\r
+ f_log = get(handles.mes_on,'UserData');\r
+ f_lin = get(handles.close_button,'UserData');\r
+ f_s = get_fs(handles);\r
+ nbits = get_nbits(handles);\r
+ f_min = str2double(get(handles.f_gen_min,'String'));\r
+ f_max = str2double(get(handles.f_gen_max,'String'));\r
+ time = get(handles.time_gen,'Value');\r
+ voices_in = get_voices_in(handles);\r
+ gain_in = get(handles.gain_in,'Value');\r
+ voices_out = get_voices_out(handles);\r
+ gain_out = get(handles.gain_out,'Value');\r
+ \r
+ % Save it\r
+ file = [home_dir '\' username '_' id '.mat'];\r
+ save(file);\r
+ \r
+ % Clear big data\r
+ set(handles.ID,'UserData',[]);\r
+ set(handles.id_title,'UserData',[]);\r
+ set(handles.mes_on,'UserData',[]);\r
+ \r
+ % Increment ID\r
+ increment_id(handles);\r
+ \r
+ \r
+\r
+ \r
+\r
+\r