To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

The primary repository for this project is hosted at git://github.com/rmeddis/MAP.git .
This repository is a read-only copy which is updated automatically every hour.

Statistics Download as Zip
| Branch: | Revision:

root / userProgramsTim / speechmanipulation.m

History | View | Annotate | Download (26.9 KB)

1 38:c2204b18f4a2 rmeddis
function varargout = speechmanipulation(varargin)
2
% SPEECHMANIPULATION MATLAB code for speechmanipulation.fig
3
%      SPEECHMANIPULATION, by itself, creates a new SPEECHMANIPULATION or raises the existing
4
%      singleton*.
5
%
6
%      H = SPEECHMANIPULATION returns the handle to a new SPEECHMANIPULATION or the handle to
7
%      the existing singleton*.
8
%
9
%      SPEECHMANIPULATION('CALLBACK',hObject,eventData,handles,...) calls the local
10
%      function named CALLBACK in SPEECHMANIPULATION.M with the given input arguments.
11
%
12
%      SPEECHMANIPULATION('Property','Value',...) creates a new SPEECHMANIPULATION or raises the
13
%      existing singleton*.  Starting from the left, property value pairs are
14
%      applied to the GUI before speechmanipulation_OpeningFcn gets called.  An
15
%      unrecognized property name or invalid value makes property application
16
%      stop.  All inputs are passed to speechmanipulation_OpeningFcn via varargin.
17
%
18
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
19
%      instance to run (singleton)".
20
%
21
% See also: GUIDE, GUIDATA, GUIHANDLES
22
23
% Edit the above text to modify the response to help speechmanipulation
24
25
% Last Modified by GUIDE v2.5 05-Oct-2011 11:21:58
26
27
% Begin initialization code - DO NOT EDIT
28
gui_Singleton = 1;
29
gui_State = struct('gui_Name',       mfilename, ...
30
                   'gui_Singleton',  gui_Singleton, ...
31
                   'gui_OpeningFcn', @speechmanipulation_OpeningFcn, ...
32
                   'gui_OutputFcn',  @speechmanipulation_OutputFcn, ...
33
                   'gui_LayoutFcn',  [] , ...
34
                   'gui_Callback',   []);
35
if nargin && ischar(varargin{1})
36
    gui_State.gui_Callback = str2func(varargin{1});
37
end
38
39
if nargout
40
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
41
else
42
    gui_mainfcn(gui_State, varargin{:});
43
end
44
% End initialization code - DO NOT EDIT
45
46
47
% --- Executes just before speechmanipulation is made visible.
48
function speechmanipulation_OpeningFcn(hObject, eventdata, handles, varargin)
49
% This function has no output args, see OutputFcn.
50
% hObject    handle to figure
51
% eventdata  reserved - to be defined in a future version of MATLAB
52
% handles    structure with handles and user data (see GUIDATA)
53
% varargin   command line arguments to speechmanipulation (see VARARGIN)
54
global wavfilescell;
55
global rateaxeshandle; %handle to axis6 is needed, if radiobuttons12 and 13 change
56
57
58
% Choose default command line output for speechmanipulation
59
handles.output = hObject;
60
61
% Update handles structure
62
guidata(hObject, handles);
63
64
% UIWAIT makes speechmanipulation wait for user response (see UIRESUME)
65
% uiwait(handles.figure1);
66
wavfiles = dir(['..' filesep 'wavFileStore' filesep '*.wav']);
67
for iCounter = 1:length(wavfiles)
68
    wavfilescell{iCounter} = wavfiles(iCounter).name;
69
end
70
set(handles.popupmenu1,'String',wavfilescell);
71
set(handles.popupmenu2,'String',wavfilescell);
72
set(handles.uipanel8,'SelectionChangeFcn',@radiobuttonselected);
73
rateaxeshandle = handles.axes6;
74
75
% --- Outputs from this function are returned to the command line.
76
function varargout = speechmanipulation_OutputFcn(hObject, eventdata, handles)
77
% varargout  cell array for returning output args (see VARARGOUT);
78
% hObject    handle to figure
79
% eventdata  reserved - to be defined in a future version of MATLAB
80
% handles    structure with handles and user data (see GUIDATA)
81
82
% Get default command line output from handles structure
83
varargout{1} = handles.output;
84
85
function edit1_Callback(hObject, eventdata, handles)
86
function edit2_Callback(hObject, eventdata, handles)
87
function edit3_Callback(hObject, eventdata, handles)
88
function edit4_Callback(hObject, eventdata, handles)
89
function edit5_Callback(hObject, eventdata, handles)
90
function edit6_Callback(hObject, eventdata, handles)
91
function edit7_Callback(hObject, eventdata, handles)
92
function edit8_Callback(hObject, eventdata, handles)
93
function edit9_Callback(hObject, eventdata, handles)
94
function edit10_Callback(hObject, eventdata, handles)
95
function edit11_Callback(hObject, eventdata, handles)
96
function edit12_Callback(hObject, eventdata, handles)
97
98
99
% --- Executes on selection change in popupmenu1.
100
function popupmenu1_Callback(hObject, eventdata, handles)
101
% hObject    handle to popupmenu1 (see GCBO)
102
% eventdata  reserved - to be defined in a future version of MATLAB
103
% handles    structure with handles and user data (see GUIDATA)
104
105
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
106
%        contents{get(hObject,'Value')} returns selected item from popupmenu1
107
%% CHOOSE AND LOAD WAVEFORM
108
global wavfilescell
109
global originalsignal
110
global actualsignal
111
112
%get the number from the popupmenu
113
selectedfileno = get(handles.popupmenu1,'Value');
114
115
%load it
116
[waveform,sfreq] = wavread(['..' filesep 'wavFileStore' filesep wavfilescell{selectedfileno}]);
117
118
%if it is from OLLO then cut it
119
if regexp(wavfilescell{selectedfileno}, 'S[0-9]*[A-Z]_L[0-9]*_V[0-9]_M[0-9]_N[0-9]_CS0.wav') %pattern for OLLO-files
120
    waveform = cutsignal(waveform,sfreq,'a_a');
121
end
122
123
%store it in global variables
124
actualsignal.waveform = waveform;
125
actualsignal.sfreq = sfreq;
126
originalsignal.waveform = waveform;
127
originalsignal.sfreq = sfreq;
128
129
%plot it
130
multipleplot(actualsignal,handles);
131
132
% --- Executes during object creation, after setting all properties.
133
function popupmenu1_CreateFcn(hObject, eventdata, handles)
134
% hObject    handle to popupmenu1 (see GCBO)
135
% eventdata  reserved - to be defined in a future version of MATLAB
136
% handles    empty - handles not created until after all CreateFcns called
137
138
% Hint: popupmenu controls usually have a white background on Windows.
139
%       See ISPC and COMPUTER.
140
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
141
    set(hObject,'BackgroundColor','white');
142
end
143
144
145
% --- Executes on button press in pushbutton1.
146
function pushbutton1_Callback(hObject, eventdata, handles)
147
% hObject    handle to pushbutton1 (see GCBO)
148
% eventdata  reserved - to be defined in a future version of MATLAB
149
% handles    structure with handles and user data (see GUIDATA)
150
%% LOAD WAVEFORM
151
global wavfilescell
152
global originalsignal
153
global actualsignal
154
155
%get the number from the popupmenu
156
selectedfileno = get(handles.popupmenu1,'Value');
157
158
%load it
159
[waveform,sfreq] = wavread(['..' filesep 'wavFileStore' filesep wavfilescell{selectedfileno}]);
160
161
%if it is from OLLO then cut it
162
if regexp(wavfilescell{selectedfileno}, 'S[0-9]*[A-Z]_L[0-9]*_V[0-9]_M[0-9]_N[0-9]_CS0.wav') %pattern for OLLO-files
163
    waveform = cutsignal(waveform,sfreq,'a_a');
164
end
165
166
%store it in global variables
167
actualsignal.waveform = waveform;
168
actualsignal.sfreq = sfreq;
169
originalsignal.waveform = waveform;
170
originalsignal.sfreq = sfreq;
171
172
%plot it
173
multipleplot(actualsignal,handles)
174
175
176
% --- Executes during object creation, after setting all properties.
177
function edit1_CreateFcn(hObject, eventdata, handles)
178
% hObject    handle to edit1 (see GCBO)
179
% eventdata  reserved - to be defined in a future version of MATLAB
180
% handles    empty - handles not created until after all CreateFcns called
181
182
% Hint: edit controls usually have a white background on Windows.
183
%       See ISPC and COMPUTER.
184
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
185
    set(hObject,'BackgroundColor','white');
186
end
187
188
189
% --- Executes on button press in pushbutton2.
190
function pushbutton2_Callback(hObject, eventdata, handles)
191
% hObject    handle to pushbutton2 (see GCBO)
192
% eventdata  reserved - to be defined in a future version of MATLAB
193
% handles    structure with handles and user data (see GUIDATA)
194
%% PLAY THE ACTUAL (MANIPULATED) SIGNAL
195
global actualsignal
196
global toplay
197
198
toplay = audioplayer(actualsignal.waveform,actualsignal.sfreq);
199
play(toplay);
200
201
202
% --- Executes on button press in pushbutton3.
203
function pushbutton3_Callback(hObject, eventdata, handles)
204
% hObject    handle to pushbutton3 (see GCBO)
205
% eventdata  reserved - to be defined in a future version of MATLAB
206
% handles    structure with handles and user data (see GUIDATA)
207
208
%% MANIPULATE SIGNAL
209
global wavfilescell
210
global originalsignal
211
global actualsignal
212
213
actualsignal = originalsignal; %reset
214
215
%% speed factor change
216
speedfactor = str2num(get(handles.edit1,'String'));
217
newfakesfreq=actualsignal.sfreq*speedfactor;
218
if speedfactor == 1
219
else
220
    actualsignal.waveform = resample(actualsignal.waveform,actualsignal.sfreq,newfakesfreq);
221
end
222
223
%% low and high pass filter (butterworth)
224
% get the desired filter from radio buttons
225
radiofilterhandles=get(handles.uipanel2,'Children');
226
for iCounter = 1:length(radiofilterhandles)
227
    if get(radiofilterhandles(iCounter),'Value') == 1
228
        filtertype = get(radiofilterhandles(iCounter),'String');
229
    end
230
end
231
% read parameters
232
tmp = get(handles.edit3,'String');
233
cutofffreq=str2num(tmp{1});
234
tmp = get(handles.edit4,'String');
235
filterorder=str2num(tmp{1});
236
%do the filter calculations
237
switch filtertype
238
    case 'none'
239
    case 'High pass'
240
        if isempty(cutofffreq) || isempty(filterorder)
241
            error('Please specify cutoff frequency and/or filter order')
242
        else
243
            [a,b] = butter(filterorder,cutofffreq*2/actualsignal.sfreq,'high');
244
            actualsignal.waveform=filter(a,b,actualsignal.waveform);
245
        end
246
    case 'Low pass'
247
        if isempty(cutofffreq)|| isempty(filterorder)
248
            error('Please specify cutoff frequency')
249
        else
250
            [a,b] = butter(filterorder,cutofffreq*2/actualsignal.sfreq,'low');
251
            actualsignal.waveform=filter(a,b,actualsignal.waveform);
252
        end
253
end
254
255
%additive noise
256
% get the desired filter from radio buttons
257
radionoisehandles=get(handles.uipanel4,'Children');
258
for iCounter = 1:length(radionoisehandles)
259
    if get(radionoisehandles(iCounter),'Value') == 1
260
        noisetype = get(radionoisehandles(iCounter),'String');
261
    end
262
end
263
% read parameters
264
tmp = get(handles.edit5,'String');
265
snr=str2num(tmp{1});
266
%do the noise calculations
267
switch noisetype
268
    case 'none'
269
    case 'White noise'
270
        if isempty(snr)
271
            error('Please specify SNR')
272
        else
273
            whitenoise = rand(length(actualsignal.waveform),1)-0.5;
274
            %set level
275
            levelsignal = 20*log10(sqrt(mean(actualsignal.waveform.^2)));
276
            levelnoise = levelsignal-snr;
277
            whitenoise = whitenoise./sqrt(mean(whitenoise.^2)).*10^(levelnoise/20);
278
            %20*log10(sqrt(mean(whitenoise.^2)))
279
            actualsignal.waveform=actualsignal.waveform+whitenoise;
280
        end
281
    case 'From file'
282
        if isempty(snr)
283
            error('Please specify SNR')
284
        else
285
            selectedfileno = get(handles.popupmenu2,'Value');
286
287
            [noisewaveform,noisesfreq] = wavread(['..' filesep 'wavFileStore' filesep wavfilescell{selectedfileno}]);
288
            if noisesfreq == actualsignal.sfreq
289
            else
290
                noisewaveform = resample(noisewaveform,actualsignal.sfreq,noisesfreq);
291
                noisesfreq = actualsignal.sfreq;
292
            end
293
            if length(noisewaveform) < length(actualsignal.waveform)
294
                warning('Noise waveform too short. Noise is looped without fading at the endings!');
295
                noisewaveform = repmat(noisewaveform, ceil(length(actualsignal.waveform)/length(noisewaveform)),1);
296
            end
297
            noisewaveform=noisewaveform(1:length(actualsignal.waveform));
298
            %set level
299
            levelsignal = 20*log10(sqrt(mean(actualsignal.waveform.^2)));
300
            levelnoise = levelsignal-snr;
301
            noisewaveform = noisewaveform./sqrt(mean(noisewaveform.^2)).*10^(levelnoise/20);
302
            %20*log10(sqrt(mean(noisewaveform.^2)))
303
            %finally add the two signals
304
            actualsignal.waveform = actualsignal.waveform + noisewaveform;
305
        end
306
end
307
308
%plot the resulting manipulated waveform
309
multipleplot(actualsignal,handles);
310
311
% --- Executes during object creation, after setting all properties.
312
function edit3_CreateFcn(hObject, eventdata, handles)
313
% hObject    handle to edit3 (see GCBO)
314
% eventdata  reserved - to be defined in a future version of MATLAB
315
% handles    empty - handles not created until after all CreateFcns called
316
317
% Hint: edit controls usually have a white background on Windows.
318
%       See ISPC and COMPUTER.
319
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
320
    set(hObject,'BackgroundColor','white');
321
end
322
323
324
% --- Executes during object creation, after setting all properties.
325
function edit4_CreateFcn(hObject, eventdata, handles)
326
% hObject    handle to edit4 (see GCBO)
327
% eventdata  reserved - to be defined in a future version of MATLAB
328
% handles    empty - handles not created until after all CreateFcns called
329
330
% Hint: edit controls usually have a white background on Windows.
331
%       See ISPC and COMPUTER.
332
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
333
    set(hObject,'BackgroundColor','white');
334
end
335
336
337
% --- Executes during object creation, after setting all properties.
338
function edit5_CreateFcn(hObject, eventdata, handles)
339
% hObject    handle to edit5 (see GCBO)
340
% eventdata  reserved - to be defined in a future version of MATLAB
341
% handles    empty - handles not created until after all CreateFcns called
342
343
% Hint: edit controls usually have a white background on Windows.
344
%       See ISPC and COMPUTER.
345
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
346
    set(hObject,'BackgroundColor','white');
347
end
348
349
350
% --- Executes during object creation, after setting all properties.
351
function popupmenu2_CreateFcn(hObject, eventdata, handles)
352
% hObject    handle to popupmenu2 (see GCBO)
353
% eventdata  reserved - to be defined in a future version of MATLAB
354
% handles    empty - handles not created until after all CreateFcns called
355
356
% Hint: popupmenu controls usually have a white background on Windows.
357
%       See ISPC and COMPUTER.
358
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
359
    set(hObject,'BackgroundColor','white');
360
end
361
362
363
% --- Executes on button press in pushbutton4.
364
function pushbutton4_Callback(hObject, eventdata, handles)
365
% hObject    handle to pushbutton4 (see GCBO)
366
% eventdata  reserved - to be defined in a future version of MATLAB
367
% handles    structure with handles and user data (see GUIDATA)
368
%% PLAY THE ORIGINAL WAVEFORM
369
global originalsignal
370
global toplay
371
toplay = audioplayer(originalsignal.waveform,originalsignal.sfreq);
372
play(toplay)
373
374
375
% --- Executes on button press in pushbutton5.
376
function pushbutton5_Callback(hObject, eventdata, handles)
377
% hObject    handle to pushbutton5 (see GCBO)
378
% eventdata  reserved - to be defined in a future version of MATLAB
379
% handles    structure with handles and user data (see GUIDATA)
380
global toplay
381
stop(toplay);
382
383
384
function edit6_Callback(hObject, eventdata, handles)
385
% hObject    handle to edit6 (see GCBO)
386
% eventdata  reserved - to be defined in a future version of MATLAB
387
% handles    structure with handles and user data (see GUIDATA)
388
389
% Hints: get(hObject,'String') returns contents of edit6 as text
390
%        str2double(get(hObject,'String')) returns contents of edit6 as a double
391
392
393
% --- Executes during object creation, after setting all properties.
394
function edit6_CreateFcn(hObject, eventdata, handles)
395
% hObject    handle to edit6 (see GCBO)
396
% eventdata  reserved - to be defined in a future version of MATLAB
397
% handles    empty - handles not created until after all CreateFcns called
398
399
% Hint: edit controls usually have a white background on Windows.
400
%       See ISPC and COMPUTER.
401
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
402
    set(hObject,'BackgroundColor','white');
403
end
404
405
% --- Executes during object creation, after setting all properties.
406
function edit7_CreateFcn(hObject, eventdata, handles)
407
% hObject    handle to edit7 (see GCBO)
408
% eventdata  reserved - to be defined in a future version of MATLAB
409
% handles    empty - handles not created until after all CreateFcns called
410
411
% Hint: edit controls usually have a white background on Windows.
412
%       See ISPC and COMPUTER.
413
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
414
    set(hObject,'BackgroundColor','white');
415
end
416
417
418
% --- Executes during object creation, after setting all properties.
419
function edit8_CreateFcn(hObject, eventdata, handles)
420
% hObject    handle to edit8 (see GCBO)
421
% eventdata  reserved - to be defined in a future version of MATLAB
422
% handles    empty - handles not created until after all CreateFcns called
423
424
% Hint: edit controls usually have a white background on Windows.
425
%       See ISPC and COMPUTER.
426
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
427
    set(hObject,'BackgroundColor','white');
428
end
429
430
431
% --- Executes on button press in pushbutton6.
432
function pushbutton6_Callback(hObject, eventdata, handles)
433
% hObject    handle to pushbutton6 (see GCBO)
434
% eventdata  reserved - to be defined in a future version of MATLAB
435
% handles    structure with handles and user data (see GUIDATA)
436
437
%% CALCULATE MAP 1.14 auditory nerve probability output
438
addpath(['..' filesep 'MAP']);
439
addpath(['..' filesep 'utilities']);
440
global actualsignal
441
global AN_HSRoutput
442
443
tmp = get(handles.edit6,'String');
444
level4MAP=str2num(tmp);
445
if isempty(level4MAP)
446
    error('Please specify level');
447
end
448
449
tmp = get(handles.edit7,'String');
450
parameterfile=tmp;
451
if isempty(parameterfile)
452
    error('Please specify parameter file');
453
end
454
455
% identify model parameter changes if any
456
paramChanges=get(handles.edit8,'string');
457
if ~strcmp(paramChanges, ';'), paramChanges=[paramChanges ';']; end
458
eval(paramChanges);
459
460
%set level
461
actualsignal.waveform = actualsignal.waveform./sqrt(mean(actualsignal.waveform.^2)).*10^(-(94-level4MAP)/20);
462
%20*log10(sqrt(mean(actualsignal.waveform.^2))/20e-6) %reference pressure: 20uPa
463
464
MAP1_14(actualsignal.waveform,actualsignal.sfreq,-1,parameterfile, ...
465
    'probability',paramChanges);
466
global ANprobRateOutput savedBFlist
467
468
%take only the HSR fibers
469
AN_HSRoutput = ANprobRateOutput(size(ANprobRateOutput)/2+1:end,:);
470
471
%plot the auditory nerve firing probability as line plot
472
start_time = size(AN_HSRoutput,2)/2/actualsignal.sfreq-0.025; %start time to plot in s
473
end_time = start_time+0.05; %plot 50ms
474
plotIFRAN(AN_HSRoutput,start_time,end_time,actualsignal.sfreq,savedBFlist,handles.axes4);
475
set(handles.edit11,'String',num2str(1000*size(AN_HSRoutput,2)/2/actualsignal.sfreq));
476
477
%plot the fourierhistogram as image plot
478
formantpattern = fourierautocorrelationhistogram_direct(AN_HSRoutput,actualsignal.sfreq,handles.axes5);
479
caxis([0 2000]);
480
colorbar;
481
482
%plot the rate output
483
plotrateOutput(AN_HSRoutput,actualsignal.sfreq,handles.axes6,[33.7 300]);
484
set(handles.radiobutton12,'Value',1);
485
486
%calculate the IPIH
487
ipih=track_formants_from_IPI_guy(AN_HSRoutput, actualsignal.sfreq);
488
%the following code assumes that the bin width is 1/actualsignal.sfreq and
489
%the temporal step size is 3ms
490
491
ipihfreqaxis=1./[1/actualsignal.sfreq:1/actualsignal.sfreq:size(ipih,1)/actualsignal.sfreq];
492
ipihtimeaxis=[0:3:size(ipih,2)*3];
493
set(gcf,'CurrentAxes',handles.axes7);
494
YTickIdx = 1:floor(numel(ipihfreqaxis)/6):numel(ipihfreqaxis);
495
XTickIdx = 1:floor(numel(ipihtimeaxis)/6):numel(ipihtimeaxis);
496
imagesc(ipih);
497
set(gca, 'YTick', YTickIdx);
498
set(gca, 'YTickLabel', num2str(  ipihfreqaxis(YTickIdx)', '%0.0f' ));
499
ylabel('best frequency (Hz)')
500
set(gca, 'XTick', XTickIdx);
501
set(gca, 'XTickLabel', XTickIdx.*3);
502
xlabel('Time (ms)');
503
caxis([0 8e4]); %set color
504
colorbar;
505
506
%calculate and plot summarized autocorrelation, code from Ray
507
method.dt=1/actualsignal.sfreq;
508
method.segmentNo=1;
509
method.nonlinCF=savedBFlist;
510
511
minPitch=	80; maxPitch=	4000; numPitches=100;    % specify lags
512
pitches=10.^ linspace(log10(minPitch), log10(maxPitch),numPitches);
513
pitches=fliplr(pitches);
514
filteredSACFParams.lags=1./pitches;     % autocorrelation lags vector
515
filteredSACFParams.acfTau=	.003;       % time constant of running ACF
516
filteredSACFParams.lambda=	0.12;       % slower filter to smooth ACF
517
filteredSACFParams.lambda=	0.01;       % slower filter to smooth ACF
518
519
filteredSACFParams.plotACFs=0;          % special plot (see code)
520
filteredSACFParams.plotFilteredSACF=0;  % 0 plots unfiltered ACFs
521
filteredSACFParams.plotMoviePauses=.5;%.3          % special plot (see code)
522
523
filteredSACFParams.usePressnitzer=0; % attenuates ACF at  long lags
524
filteredSACFParams.lagsProcedure=  'useAllLags';
525
filteredSACFParams.criterionForOmittingLags=3;
526
filteredSACFParams.plotACFsInterval=50;%200;
527
528
% compute ACF
529
%switch saveAN_spikesOrProbability
530
%    case 'probability'
531
        inputToACF=ANprobRateOutput.^0.5;
532
%    otherwise
533
%        inputToACF=ANoutput;
534
%end
535
536
disp ('computing ACF...')
537
t=method.dt*(1:length(actualsignal.waveform));
538
[P, BFlist, sacf, boundaryValue] = ...
539
    filteredSACF(inputToACF, method, filteredSACFParams);
540
P = real(P); %dont know why sometimes P can be (very slightly) complex
541
disp(' ACF done.')
542
543
% SACF
544
set(gcf,'CurrentAxes',handles.axes8);
545
imagesc(P)
546
ylabel('periodicities (Hz)')
547
xlabel('time (s)')
548
%title(['running smoothed (root) SACF. ' saveAN_spikesOrProbability ' input'])
549
pt=[1 get(gca,'ytick')]; % force top xtick to show
550
set(gca,'ytick',pt)
551
set(gca,'ytickLabel', round(pitches(pt)))
552
tt=get(gca,'xtick');
553
tt=tt(tt<length(t));
554
set(gca,'xtickLabel', round(100*t(tt))/100)
555
colorbar;
556
557
% --- Executes on button press in pushbutton7.
558
function pushbutton7_Callback(hObject, eventdata, handles)
559
% hObject    handle to pushbutton7 (see GCBO)
560
% eventdata  reserved - to be defined in a future version of MATLAB
561
% handles    structure with handles and user data (see GUIDATA)
562
563
%% SHOW THE  (PREVIOUSLY STORED) AUDITORY PROFILE CORRESPONDING TO THE
564
%% PARAMETER FILE
565
addpath(['..' filesep 'multithreshold 1.46' filesep]);
566
% read the parameter file
567
tmp = get(handles.edit7,'String');
568
parameterfile=tmp;
569
if isempty(parameterfile)
570
    error('Please specify parameter file');
571
end
572
573
%what kind of profiles are in the profiles directory?
574
files_in_profiles = dir(['..' filesep 'profiles' filesep '*.m']);%if exist('',file)
575
done = 0;
576
577
%try to map the specified parameter file to these found in the directory
578
%and
579
for iCounter = 1:length(files_in_profiles)
580
    if strfind(files_in_profiles(iCounter).name,parameterfile)
581
        %ask the user if this is the correct file - because you'll never
582
        %know ;)
583
        stringtoask = ['Is ' files_in_profiles(iCounter).name ' the correct profile file?'];
584
        Answer = questdlg(stringtoask,'Possible match found','Yes','No','Yes');
585
        switch Answer,
586
            case 'Yes'
587
                plotprofile(files_in_profiles(iCounter).name(1:end-2),'profile_CMA_L');
588
                done = 1;
589
            case 'No'
590
        end %switch
591
    end %if
592
end
593
if ~done
594
    msgbox('No match for this parameter file found.');
595
end
596
597
function multipleplot(actualsignal,handles)
598
%% FUNCTION TO DO 3 PLOTS
599
time_axis = [0:1/actualsignal.sfreq:(length(actualsignal.waveform)-1)/actualsignal.sfreq];
600
601
%waveform plot (temporal)
602
plot(handles.axes1,time_axis,actualsignal.waveform);
603
set(get(handles.axes1,'XLabel'),'String','Time (s)');
604
set(get(handles.axes1,'YLabel'),'String','Amplitude');
605
set(handles.axes1,'XLim',[0 length(actualsignal.waveform)/actualsignal.sfreq]);
606
highestabsampl = max(abs(actualsignal.waveform))*1.05;
607
set(handles.axes1,'YLim',[-highestabsampl highestabsampl]);
608
609
%average spectrum plot
610
complspectrum = fft(actualsignal.waveform)/(length(actualsignal.waveform));
611
frequency = [0:1/time_axis(end):1/(2*(time_axis(2)-time_axis(1)))];
612
plot(handles.axes2,frequency,20*log10(sqrt(2)*abs(complspectrum(1:round(length(complspectrum)/2)))));
613
set(get(handles.axes2,'XLabel'),'String','frequency (Hz)');
614
set(get(handles.axes2,'YLabel'),'String','fourier amplitude (dB)');
615
set(handles.axes2,'XLim',[100 10000]);
616
set(handles.axes2,'XScale','log');
617
618
%spectrogram plot (10 ms temporal resolution)
619
[s,f,t] = spectrogram(actualsignal.waveform,hann(round(0.01*actualsignal.sfreq)),[],[],actualsignal.sfreq); %10ms short term windows
620
set(gcf,'CurrentAxes',handles.axes3);
621
if max(f)>10000
622
    [tmp,idx] = min(abs(f-10000));
623
    imagesc(t,f(1:idx),20*log10(abs(s(1:idx,:))));
624
else
625
    imagesc(t,f,20*log10(abs(s)));
626
end
627
axis xy;
628
set(get(handles.axes3,'YLabel'),'String','frequency (Hz)');
629
set(get(handles.axes3,'XLabel'),'String','Time (s)');
630
631
632
function plotrateOutput(ratepattern,sfreq,axeshandle,colorrange)
633
%% calculate rate representation and plot, code from Nick
634
global savedBFlist
635
%calculate rate representation
636
ANsmooth = [];%Cannot pre-allocate a size as it is unknown until the enframing
637
hopSize = 10; %ms
638
winSize = 25; %ms
639
winSizeSamples = round(winSize*sfreq/1000);
640
hann = hanning(winSizeSamples);
641
hopSizeSamples = round(hopSize*sfreq/1000);
642
for chan = 1:size(ratepattern,1)
643
    f = enframe(ratepattern(chan,:), hann, hopSizeSamples);
644
    ANsmooth(chan,:) = mean(f,2)';
645
end
646
647
%plot rate representation
648
time_axis_rate=[0:hopSize/1000:size(ratepattern,2)/sfreq];
649
set(gcf,'CurrentAxes',axeshandle);
650
YTickIdx = 1:floor(numel(savedBFlist)/6):numel(savedBFlist);
651
XTickIdx = 1:floor(numel(time_axis_rate)/6):numel(time_axis_rate);
652
imagesc(ANsmooth);
653
axis xy;
654
set(gca, 'YTick', YTickIdx);
655
set(gca, 'YTickLabel', num2str(  savedBFlist(YTickIdx)', '%0.0f' ));
656
ylabel('best frequency (Hz)')
657
set(gca, 'XTick', XTickIdx);
658
set(gca, 'XTickLabel', XTickIdx.*10);
659
xlabel('Time (ms)');
660
caxis(colorrange); %set color from average spontaneous rate to a maximum of 600
661
colorbar;
662
663
664
% --- Executes if the radiobuttons hsr and lsr are changed
665
function radiobuttonselected(source, eventdata)
666
667
global rateaxeshandle
668
global ANprobRateOutput
669
global actualsignal
670
671
selected = get(get(source,'SelectedObject'),'String');
672
673
if isempty(ANprobRateOutput)
674
    msgbox('Please calculate AN pattern first!');
675
elseif strcmp(selected,'HSR')
676
    AN_HSRoutput = ANprobRateOutput(size(ANprobRateOutput)/2+1:end,:);
677
    colorrange = [33.7 300];
678
    plotrateOutput(AN_HSRoutput,actualsignal.sfreq,rateaxeshandle,colorrange);
679
else
680
    AN_LSRoutput = ANprobRateOutput(1:size(ANprobRateOutput)/2,:);
681
    colorrange = [10.7 100];
682
    plotrateOutput(AN_LSRoutput,actualsignal.sfreq,rateaxeshandle,colorrange);
683
end
684
685
686
% --- Executes during object creation, after setting all properties.
687
function edit11_CreateFcn(hObject, eventdata, handles)
688
% hObject    handle to edit11 (see GCBO)
689
% eventdata  reserved - to be defined in a future version of MATLAB
690
% handles    empty - handles not created until after all CreateFcns called
691
692
% Hint: edit controls usually have a white background on Windows.
693
%       See ISPC and COMPUTER.
694
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
695
    set(hObject,'BackgroundColor','white');
696
end
697
698
699
% --- Executes on button press in pushbutton8.
700
function pushbutton8_Callback(hObject, eventdata, handles)
701
% hObject    handle to pushbutton8 (see GCBO)
702
% eventdata  reserved - to be defined in a future version of MATLAB
703
% handles    structure with handles and user data (see GUIDATA)
704
%plot the auditory nerve firing probability as line plot after grabbing the
705
%time value from edit11
706
global AN_HSRoutput
707
global actualsignal
708
global savedBFlist
709
710
middletime = str2num(get(handles.edit11,'String'))/1000;
711
712
start_time = min([size(AN_HSRoutput,2)/actualsignal.sfreq-0.01 max([0 middletime-0.025])]); %start time to plot in s
713
end_time = max([start_time+0.01 min([start_time+0.05 size(AN_HSRoutput,2)/actualsignal.sfreq-0.01])]); %plot max 50ms
714
plotIFRAN(AN_HSRoutput,start_time,end_time,actualsignal.sfreq,savedBFlist,handles.axes4);