-
Notifications
You must be signed in to change notification settings - Fork 2
/
guiDSP.m
1629 lines (1166 loc) · 47.5 KB
/
guiDSP.m
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = guiDSP(varargin)
% GUIDSP Application M-file for guiDSP.fig
% FIG = GUIDSP launch guiDSP GUI.
% GUIDSP('callback_name', ...) invoke the named callback.
% Last Modified by GUIDE v2.5 09-Dec-2014 21:26:39
if nargin == 0 % LAUNCH GUI
fig = openfig(mfilename,'reuse');
% Generate a structure of handles to pass to callbacks, and store it.
handles = guihandles(fig);
guidata(fig, handles);
if nargout > 0
varargout{1} = fig;
end
elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK
try
if (nargout)
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
else
feval(varargin{:}); % FEVAL switchyard
end
catch
disp(lasterr);
end
end
%| ABOUT CALLBACKS:
%| GUIDE automatically appends subfunction prototypes to this file, and
%| sets objects' callback properties to call them through the FEVAL
%| switchyard above. This comment describes that mechanism.
%|
%| Each callback subfunction declaration has the following form:
%| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN)
%|
%| The subfunction name is composed using the object's Tag and the
%| callback type separated by '_', e.g. 'slider2_Callback',
%| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'.
%|
%| H is the callback object's handle (obtained using GCBO).
%|
%| EVENTDATA is empty, but reserved for future use.
%|
%| HANDLES is a structure containing handles of components in GUI using
%| tags as fieldnames, e.g. handles.figure1, handles.slider2. This
%| structure is created at GUI startup using GUIHANDLES and stored in
%| the figure's application data using GUIDATA. A copy of the structure
%| is passed to each callback. You can store additional information in
%| this structure at GUI startup, and you can change the structure
%| during callbacks. Call guidata(h, handles) after changing your
%| copy to replace the stored original so that subsequent callbacks see
%| the updates. Type "help guihandles" and "help guidata" for more
%| information.
%|
%| VARARGIN contains any extra arguments you have passed to the
%| callback. Specify the extra arguments by editing the callback
%| property in the inspector. By default, GUIDE sets the property to:
%| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo))
%| Add any extra arguments after the last argument, before the final
%| closing parenthesis.
% --------------------------------------------------------------------
function varargout = edit2_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = edit3_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = edit4_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = edit5_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = checkOffset_Callback(h, eventdata, handles, varargin)
global s_i_g_n_a_l;
global offset;
N = length(s_i_g_n_a_l);
sampFreq = str2double(get(handles.editSampFreq,'String'));
%axes(handles.axesSignal);
t=0:1/sampFreq:(N-1)/sampFreq;
state = get(handles.checkOffset,'Value');
if state==1,
offset = mean(s_i_g_n_a_l);
s_i_g_n_a_l = s_i_g_n_a_l-offset;
plot(t,s_i_g_n_a_l);
else
s_i_g_n_a_l = s_i_g_n_a_l+offset;
plot(t,s_i_g_n_a_l);
end; %if
% --------------------------------------------------------------------
function varargout = checkOffset_CreateFcn(h, eventdata, handles, varargin)
% global s_i_g_n_a_l;
%
% N = length(s_i_g_n_a_l);
%
% sampFreq = str2double(get(handles.editSampFreq,'String'));
% axes(handles.axesSignal);
% t=0:1/sampFreq:(N-1)/sampFreq;
% plot(t,s_i_g_n_a_l);
% --------------------------------------------------------------------
function varargout = axesSignal_CreateFcn(h, eventdata, handles, varargin)
% global s_i_g_n_a_l;
% global offset;
%
% N = length(s_i_g_n_a_l);
%
% %sampFreq = str2double(get(handles.editSampFreq,'String'));
% %axes(handles.axesSignal);
% sampFreq = 4000;
% t=0:1/sampFreq:(N-1)/sampFreq;
%
% plot(t,s_i_g_n_a_l);
%
% % if state==1,
% % offset = mean(s_i_g_n_a_l);
% % s_i_g_n_a_l = s_i_g_n_a_l-offset;
% % plot(t,s_i_g_n_a_l);
% % else
% % s_i_g_n_a_l = s_i_g_n_a_l+offset;
% % plot(t,s_i_g_n_a_l);
% % end; %if
% --------------------------------------------------------------------
function varargout = figure1_CreateFcn(h, eventdata, handles, varargin)
vars = evalin('base','who');
disp(handles);
% set(handles.listbox_var,'String','vars');
% --------------------------------------------------------------------
function varargout = menu_dsp_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = menu_extrema_Callback(h, eventdata, handles, varargin)
global s_i_g_n_a_l;
%calculating signal extrema (valleys and peaks).
[LocalMaxV,LocalMaxI, LocalMinV,LocalMinI]= extrema(s_i_g_n_a_l);
%exporting instantaneou attributes to workspace
assignin('base','LocalMinAmplitude',LocalMinV);
assignin('base','LocalMaxAmplitude',LocalMaxV);
assignin('base','LocalMinIndex',LocalMinI);
assignin('base','LocalMaxIndex',LocalMaxI);
figure(1);
plot(s_i_g_n_a_l);
hold on; plot(LocalMaxI,LocalMaxV,'r+');
hold on; plot(LocalMinI,LocalMinV,'y*');
legend('signal','peaks','valleys');
% --------------------------------------------------------------------
function varargout = menu_hist_Callback(h, eventdata, handles, varargin)
global s_i_g_n_a_l;
Nbits = str2double(get(handles.Nbits,'String'));
%Estimating the histogram
[xout,n]= histogram(s_i_g_n_a_l,Nbits);
figure(1);
title('Histogram');
plot(xout,n);
ylabel('Number of ocurrences');
xlabel('Amplitude (V)');
% --------------------------------------------------------------------
function varargout = Untitled_4_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = menu_env_Callback(h, eventdata, handles, varargin)
global s_i_g_n_a_l;
%Getting the interpolation method
index_selected = get(handles.edit_interpMethod,'Value');
%Estimating the signal envelope
[AveEnvelope,yu,yl,n_extrema]= meanEnv(s_i_g_n_a_l,index_selected-1);
%exporting envelopes to workspace
assignin('base','UpperEnvelope',yu);
assignin('base','LowerEnvelope',yl);
assignin('base','AveEnvelope',AveEnvelope);
%Creating figure
handle_figure = 333;
figure(handle_figure);
set(handle_figure,'Name','Envelope');
set(handle_figure,'NumberTitle','off');
%Plotting
plot(s_i_g_n_a_l);
hold on; plot(yu,'r--');
hold on; plot(yl,'y--');
hold on; plot(AveEnvelope,'k','LineWidth',2);
ylabel('Amplitude (V)');
xlabel('Samples');
legend('signal','upper envelope','lower envelope', 'mean envelope');
% --------------------------------------------------------------------
function varargout = menu_burst_Callback(h, eventdata, handles, varargin)
global s_i_g_n_a_l;
sampFreq = str2double(get(handles.editSampFreq,'String'));
maxADRange = str2double(get(handles.maxADRange,'String'));
Nbits = str2double(get(handles.Nbits,'String'));
[onset,tr]= detectBurst(s_i_g_n_a_l,maxADRange,Nbits,sampFreq);
figure(1);
plot(onset);
hold on; plot(s_i_g_n_a_l,'r');
hold on; plot([0 length(s_i_g_n_a_l)],[tr tr],'g','LineWidth',2);
hold on; plot([0 length(s_i_g_n_a_l)],[-tr -tr],'g','LineWidth',2);
ylabel('Amplitude (volts)');
xlabel('Samples');
%exporting onset to workspace
assignin('base','Onset',tr);
% --------------------------------------------------------------------
function varargout = menu_InstAt_Callback(h, eventdata, handles, varargin)
global s_i_g_n_a_l;
sampFreq = str2double(get(handles.editSampFreq,'String'));
[amp,phase,freq]= instantAtrib(s_i_g_n_a_l,sampFreq);
%exporting instantaneou attributes to workspace
assignin('base','amp',amp);
assignin('base','phase',phase);
assignin('base','freq',freq);
%Plotting
handle_figure = 222;
figure(handle_figure);
set(handle_figure,'Name','Intantaneous atributes');
set(handle_figure,'NumberTitle','off');
subplot(3,1,1);plot(amp);
ylabel('amplitude (V)');
subplot(3,1,2);plot(phase);
ylabel('phase (rad)');
subplot(3,1,3);plot(freq);
ylabel('frequency (Hz)');
xlabel('samples');
% --------------------------------------------------------------------
function varargout = menu_psd_Callback(h, eventdata, handles, varargin)
global s_i_g_n_a_l;
sampFreq = str2double(get(handles.editSampFreq,'String'));
% estimates the Power Spectral Density of
% a discrete-time signal vector X using Welch's averaged, modified
% periodogram method.
WindowSize = 256;
nPointsFFT = 1024;
[Pxx,F] = pwelch(s_i_g_n_a_l,WindowSize, [],nPointsFFT, sampFreq); %input signal
Pxx = 10*log10(Pxx); %dB
%Plotting
handle_figure = 4;
figure(handle_figure);
set(handle_figure,'Name','PSD - based on Welch`s averaged, modified periodogram method');
set(handle_figure,'NumberTitle','off');
Pxx_norm = convScale(min(Pxx),max(Pxx),Pxx,0,1); %normalizing the spectrum [0 1]
plot(F,Pxx_norm);
xlabel('frequency (Hz)');
ylabel('Normalized amplitude');
title('Power Spectral Density estimate');
% --------------------------------------------------------------------
function varargout = menu_emd_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = menu_sp_Callback(h, eventdata, handles, varargin)
global s_i_g_n_a_l;
global i_m_fs;
global residue;
i_m_fs = [];
%Getting mse (defined by the user)
mse = str2double(get(handles.edit_mse,'String'));
%Getting the interpolation method
index_selected = get(handles.edit_interpMethod,'Value');
%Sifting process
[i_m_fs,residue]= sig_to_imf(s_i_g_n_a_l,mse,index_selected-1);
[r,c] = size(i_m_fs);
%sampling frequency (defined by the user)
sampFreq = str2double(get(handles.editSampFreq,'String'));
%Estimating time
n=length(s_i_g_n_a_l);
t=0:1/sampFreq:(n-1)/sampFreq;
%Plotting
handle_figure = 5;
figure(handle_figure);
set(handle_figure,'Name','Intrinsic mode functions');
set(handle_figure,'NumberTitle','off');
for i=1:r,
subplot(r,1,i);plot(t,i_m_fs(i,:));
if(i~=r),
set(gca,'XTickLabel',{''});
end;
end%for
xlabel('Time (s)');
% %exporting imfs to workspace
for i=1:r,
assignin('base',['imf',num2str(i)],i_m_fs(i,:));
end%for
% --------------------------------------------------------------------
function varargout = menu_hs_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = menu_mhs_Callback(h, eventdata, handles, varargin)
global s_i_g_n_a_l;
global m_a_p;
global hs_dt;
% Verifying if there exists a valid map to generate the Hilbert spectrum
if isempty(m_a_p)==1,
msgbox('There is Hilbert spectrum available.','guiDSP','error');
return;
end
%Getting the lower frequency
LFreq = str2double(get(handles.edit_minFreq,'String'));
%Getting the upper frequency
UFreq =str2double(get(handles.edit_maxFreq,'String'));
%Getting the sampling frequency
sampFreq = str2double(get(handles.editSampFreq,'String'));
%Estimating the Marginal Hilbert spectrum
[mhs,f] = MHSpec(m_a_p,LFreq,UFreq,hs_dt);
%Plotting...
handle_figure = 6;
figure(handle_figure);
set(handle_figure,'Name','Marginal Hilbert spectrum');
set(handle_figure,'NumberTitle','off');
mhs_norm = convScale(min(mhs),max(mhs),mhs,0,1); %normalizing the spectrum [0 1]
plot(f,mhs_norm);
xlabel('frequency (Hz)');
ylabel('Normalized amplitude');
% --------------------------------------------------------------------
function varargout = menu_ds_Callback(h, eventdata, handles, varargin)
global s_i_g_n_a_l;
global m_a_p;
global hs_dt;
if isempty(m_a_p)==1,
msgbox('There is Hilbert spectrum available.','guiDSP','error');
return;
end
%Getting the lower frequency
LFreq = str2double(get(handles.edit_minFreq,'String'));
%Getting the upper frequency
UFreq =str2double(get(handles.edit_maxFreq,'String'));
%Getting samplinf frequency
sampFreq = str2double(get(handles.editSampFreq,'String'));
T = length(s_i_g_n_a_l)*1/sampFreq;
[meanMHS,d_s,f] = DS(m_a_p,LFreq,UFreq,hs_dt,T);
%Plotting...
handle_figure = 60;
figure(handle_figure);
set(handle_figure,'Name','Degree of stationarity');
set(handle_figure,'NumberTitle','off');
figure(handle_figure);
plot(f,d_s);
xlabel('frequency');
ylabel('DS');
% --------------------------------------------------------------------
function varargout = R_M_S_Callback(h, eventdata, handles, varargin)
global s_i_g_n_a_l;
prompt = {'Enter the window size'};
dlg_title = 'RMS estimation';
num_lines= 1;
def = {'20'};
msgbox_output = inputdlg(prompt,dlg_title,num_lines,def);
if(isempty(msgbox_output)==1),
return;
else
%Defining window size
N = str2double(msgbox_output);
%Root mean square estimation
[rms,index] = rmsEst(s_i_g_n_a_l,N);
handle_figure = 1111;
figure(handle_figure);
set(handle_figure,'Name','RMS');
set(handle_figure,'NumberTitle','off');
figure(handle_figure);
plot(index,rms);
hold on; plot(s_i_g_n_a_l,'r');
%exporting filtered signal to workspace
assignin('base','r_m_s',rms);
assignin('base','index',index);
end; %if
% --------------------------------------------------------------------
function varargout = menu_spectrogram_Callback(h, eventdata, handles, varargin)
global s_i_g_n_a_l;
%Getting sampling frequency
sampFreq = str2double(get(handles.editSampFreq,'String'));
%Plotting...
handle_figure = 1000;
figure(handle_figure);
set(handle_figure,'Name','Spectrogram');
set(handle_figure,'NumberTitle','off');
specgram(s_i_g_n_a_l,256,sampFreq,32);
colormap(hot(256));
colorbar;
ylabel('frequency (Hz)');
xlabel('time (s)');
% --------------------------------------------------------------------
function varargout = pushbutton7_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = editSampFreq_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = edit6_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = edit7_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = edit8_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = checkbox3_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = listbox2_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = listbox_var_CreateFcn(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = listbox_var_Callback(h, eventdata, handles, varargin)
global s_i_g_n_a_l;
global offset;
%showing the command window variables in the list box
vars = evalin('base','who');
set(handles.listbox_var,'String',vars);
%selecting the variable chosen by the user
index_selected = get(handles.listbox_var,'Value');
s = vars{index_selected};
s_i_g_n_a_l = evalin('base',s);
axes(handles.axesSignal);%Setting the current axes
sampFreq = str2double(get(handles.editSampFreq,'String'));
%Estimating time
n=length(s_i_g_n_a_l);
t=0:1/sampFreq:(n-1)/sampFreq;
plot(t,s_i_g_n_a_l);
xlabel('Time (s)');
%updating offset
offset = 0;
set(handles.checkOffset,'Value',0);
% --------------------------------------------------------------------
function varargout = edit_mse_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = edit_tag_Callback(h, eventdata, handles, varargin)
global n_bins;
n_bins = str2double(get(handles.editSampFreq,'String'));
% --------------------------------------------------------------------
function varargout = edit_tag_CreateFcn(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = minADRange_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = edit10_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = edit_interpMethod_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = IMF_anlysis_Callback(h, eventdata, handles, varargin)
global s_i_g_n_a_l;
global i_m_fs;
Pxx=[];
F = [];
str = [];
%Getting sampling frequency
sampFreq = str2double(get(handles.editSampFreq,'String'));
% estimates the Power Spectral Density of
% a discrete-time signal vector X using Welch's averaged, modified
% periodogram method.
WindowSize = 256;
nPointsFFT = 1024;
[Pxx,F] = pwelch(s_i_g_n_a_l,WindowSize, [],nPointsFFT, sampFreq); %input signal
MaxPxx=max(Pxx);
str = ('signal');
% %Estimating PSD function of IMFs
numberIMFs = min(size(i_m_fs));
%
for i=1:numberIMFs,
[Pxx(:,i+1),F(:,i+1)] = pwelch(i_m_fs(i,:),WindowSize,[],nPointsFFT,sampFreq); %input signal
auxStr= (['imf ', num2str(i)]);
str = str2mat(str,auxStr);
end;
%
% %Plotting
handle_figure = 114;
figure(handle_figure);
set(handle_figure,'Name','IMF analysis');
set(handle_figure,'NumberTitle','off');
plot(F,Pxx/MaxPxx);
legend(str);
xlabel('Frequency (Hz)');
ylabel('Normalized amplitude');
title('Power spectrum');
% --------------------------------------------------------------------
function varargout = menu_completeness_Callback(h, eventdata, handles, varargin)
global i_m_fs;
global residue;
global s_i_g_n_a_l;
%Reconstructing data
aux=[i_m_fs;residue];
SumAux = sum(aux);
handle_figure = 200;
figure(handle_figure);
set(handle_figure,'Name','Completeness analysis');
set(handle_figure,'NumberTitle','off');
plot(s_i_g_n_a_l);
hold on; plot(SumAux,'r:');
hold on; plot(s_i_g_n_a_l-SumAux,'k-.');
legend('signal', 'reconstructed signal', 'error');
xlabel('Number of samples');
ylabel('Amplitude (V)');
% --------------------------------------------------------------------
function varargout = WLPD_filter_Callback(h, eventdata, handles, varargin)
global s_i_g_n_a_l;
global WLPDsignal;
%Getting sampling frequency
sampFreq = str2double(get(handles.editSampFreq,'String'));
%filtering
[WLPDsignal] = WLPD(s_i_g_n_a_l,sampFreq,40);
handle_figure = 211;
figure(handle_figure);
set(handle_figure,'Name','Weighted low pass differential filter');
set(handle_figure,'NumberTitle','off');
plot(WLPDsignal);
%exporting filtered signal to workspace
assignin('base','WLPDsignal',WLPDsignal);
% --------------------------------------------------------------------
function varargout = MUAP_Analysis_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = maxADRange_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = listbox_var_ButtonDownFcn(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = menu_Principal_peaks_Callback(h, eventdata, handles, varargin)
global s_i_g_n_a_l;
sampFreq = str2double(get(handles.editSampFreq,'String'));
maxADRange = str2double(get(handles.maxADRange,'String'));
Nbits = str2double(get(handles.Nbits,'String'));
[Index,Amplitude]= mainPeaks(s_i_g_n_a_l,maxADRange,Nbits,sampFreq);
figure(1);
plot(s_i_g_n_a_l);
hold on; plot(Index,Amplitude,'ko');
% --------------------------------------------------------------------
function varargout = Filter_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = MovAvgFilt_Callback(h, eventdata, handles, varargin)
%calling filter order setup window
MovAvgFilter;
% --------------------------------------------------------------------
function varargout = EMG_simulator_Callback(h, eventdata, handles, varargin)
% --------------------------------------------------------------------
function varargout = menu_EFAP_Callback(h, eventdata, handles, varargin)
%calling window
%GUI_AP;
[ep,z,t] = GenerateFAP;
figure(1);
plot(t,ep);
title('Muscle fibre action potential');
xlabel('time (ms)');
ylabel('amplitude (mV)');
%exporting filtered signal to workspace
assignin('base','ep',ep);
assignin('base','z',z);
assignin('base','t',t);
% --------------------------------------------------------------------
function varargout = menu_MUAP_Callback(h, eventdata, handles, varargin)
%calling window
%GUI_MUAP;
% --------------------------------------------------------------------
function varargout = menu_MUAPT_Callback(h, eventdata, handles, varargin)
%calling window
%GUI_MUAPT;
% --------------------------------------------------------------------
function varargout = menu_EMG_Callback(h, eventdata, handles, varargin)
%calling window
%GUI_EMG;
MU = evalin('base','MU');
Fs = evalin('base','Fs');
if(isempty(MU)==1 | isempty(Fs)==1 ),
msgbox('MU/Fs is not defined.','guiDSP','error');
return;
end;
prompt = {'SNR (dB)'};
dlg_title = 'EMG signal simulation';
num_lines= 1;
def = {'80'};
msgbox_output = inputdlg(prompt,dlg_title,num_lines,def);
if(isempty(msgbox_output)==1),
return;
else
SNR = str2num(msgbox_output{1});
[EMG]= SimulateCompEMGsignal(MU,Fs,SNR);
end;
figure(3333);
%Number of electrodes
timeVec = 1/Fs*[0:1:size(EMG,2)-1];
plot(timeVec,EMG');
%exporting filtered signal
assignin('base','EMG',EMG);
% --------------------------------------------------------------------
function LPButterworth_Callback(hObject, eventdata, handles)
% hObject handle to LPButterworth (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%calling window
global s_i_g_n_a_l;
prompt = {'Cutoff frequency (Hz)', 'order'};
dlg_title = 'Low-pass Butterworth filter';
num_lines= 1;
def = {'20','4'};
msgbox_output = inputdlg(prompt,dlg_title,num_lines,def);
if(isempty(msgbox_output)==1),
return;
else
cutoffFreq = str2num(msgbox_output{1});
order = str2num(msgbox_output{2});
%current sampling frequency
sampFreq = str2double(get(handles.editSampFreq,'String'));
Wn = cutoffFreq/(sampFreq/2);
[b,a] = butter(order,Wn); %filter design
figure(1); freqz(b,a,round(sampFreq/2),sampFreq); %plotting filter characteristics
y = filtfilt(b,a,s_i_g_n_a_l); %zero-phase digital filtering (zero-phase distortion)
%exporting filtered signal
assignin('base','LowPassButFiltSig',y);
end;
%-------------------
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over editSampFreq.
function editSampFreq_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to editSampFreq (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function editSampFreq_CreateFcn(hObject, eventdata, handles)
% hObject handle to editSampFreq (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --------------------------------------------------------------------
function ss_menu_nws_Callback(hObject, eventdata, handles)
% hObject handle to ss_menu_nws (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global s_i_g_n_a_l;
global r;
if(isempty(s_i_g_n_a_l)==0),
sampFreq = str2double(get(handles.editSampFreq,'String'));
%selecting the variable chosen by the user
index_selected = get(handles.listbox_var,'Value');
s = get(handles.listbox_var,'String');
s = s{index_selected};
%Creating sptool (It is required to have the MatLab signal processing
%toolbox for this option
sptool('load','Signal',s_i_g_n_a_l,sampFreq,s);
end;
% --------------------------------------------------------------------
function ss_menu_peak_detector_Callback(hObject, eventdata, handles)
% hObject handle to ss_menu_peak_detector (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global s_i_g_n_a_l;
% global r; %structure containing the selected markers (noise window, etc)
%guaranteeing that samples are in columns
[r,c] = size(s_i_g_n_a_l);
if (r>c),
s_i_g_n_a_l = s_i_g_n_a_l';
end;
%showing the command window variables in the list box
vars = evalin('base','who');
%selecting the variable chosen by the user
% index_selected = get(handles.listbox_var,'Value');
% s = vars{index_selected};
r = evalin('base','r');%structure containing the selected markers (noise window, etc)
if(isempty(r)==1),
msgbox('A noise of window should be selected and its markers should be exported to a workspace variable called r .','guiDSP','error');
return;
end;
if(isempty(s_i_g_n_a_l)==0),
sampFreq = str2double(get(handles.editSampFreq,'String'));
[amp,phase,freq]= instantAtrib(s_i_g_n_a_l,sampFreq);% estimating instantaneous attributes of the signal
noise = amp(round(r.x1*sampFreq):round(r.x2*sampFreq));
th = 5*std(noise); %estimation of the noise based on the standard deviation of the chosen window
%DetectingMUAPs
[wpeak,wnd]= ss_peakDetector(amp,th,sampFreq);
%Detected MUAPs to the workspace
assignin('base','ss_wpeak',wpeak);
assignin('base','ss_wnd',wnd);
figure(1);
plot(amp);
hold on; stem(wpeak.pos, wpeak.amp,'r');
hold on; plot(wnd.pos_i, wnd.amp_i,'k>');
hold on; plot(wnd.pos_f, wnd.amp_f,'k<');
hold on; plot([0 length(amp)],[th th],'g:');
%Calling a dialog box for definition of the number of bins of the
%histogram
prompt = {'Enter the number of bins for the MUAP histogram:'};
dlg_title = 'Histogram';
num_lines= 1;
msgbox_output = inputdlg(prompt,dlg_title,num_lines);
if(isempty(msgbox_output)==1),
return;
else
bins = str2double(msgbox_output);
figure(2);
hist(wpeak.amp,bins);
xlabel('peaks - amplitude (V)');
ylabel('number of ocurrences');%frequency
end;
end;%if
% --------------------------------------------------------------------
function HS_pcolour_Callback(hObject, eventdata, handles)
% hObject handle to HS_pcolour (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global s_i_g_n_a_l;
global i_m_fs;
global m_a_p;
global n_bins;
global hs_dt;
if isempty(i_m_fs)==1,
msgbox('There is no intrinsic mode function available.','guiDSP','error');
return;
end
%sampling frequency (defined by the user)
sampFreq = str2double(get(handles.editSampFreq,'String'));
%Getting the lower frequency
LFreq = str2double(get(handles.edit_minFreq,'String'));
%Getting the upper frequency
UFreq =str2double(get(handles.edit_maxFreq,'String'));