-
Notifications
You must be signed in to change notification settings - Fork 0
/
isignal.m
5120 lines (5056 loc) · 212 KB
/
isignal.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 [pY,PowerSpectrum,maxy,miny,area,stdev]=isignal(datamatrix,xcenter,xrange,sm,sw,em,dm,rm,s1,s2,sr,mw,spm)
% Y=isignal(DataMatrix,xcenter,xrange,SmoothMode,SmoothWidth,ends,...
% DerivativeMode,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth,SpectrumMode)
% An interactive function that performs smoothing, differentiation, and
% peak sharpening of a time-series signal in the form of a 2-column
% matrix with the independent variable (x-vfixedparametersalues) in the first
% column and dependent variable (y values) in the second column, or as
% separate x and y vectors. Returns the processed independent axis (Y)
% vector as the output argument. The lower half of the figure window shows
% a plot of the entire signal, and the upper half shows a selected portion
% controlled by the pan and zoom keystrokes or by optional input
% arguments 'xcenter' and 'xrange', respeSctively. Other keystrokes
% also allow you to control the smooth type, width, and ends
% treatment, the derivative order (0th through 5th), and peak
% sharpening. (Alternatively, the initial values of these parameters
% can be passed to the function via the optional input arguments.)
%
% Version 5.71 Adds Shift-L to replace signal with processed version
% Shift-V for Fourier convolution/Deconvolution function menu
%
% By T. C. O'Haver (toh@umd.edu); Savitzky-Golay smooth code by Diederick.
% See http://terpconnect.umd.edu/~toh/spectrum/iSignal.html
% The S key (or optional argument "sm") determines the smooth mode:
% If sm=0, the signal is not smoothed.
% If sm=1, rectangular (sliding-average or boxcar)
% If sm=2, triangular (2 passes of sliding-average)
% If sm=3, pseudo-Gaussian (3 passes of sliding-average)
% If sm=4, Savitzky-Golay smooth
% The A and Z keys (or optional argument sw) control the smooth width.
% The Z key (or argument "em") controls how the "ends" of the signal
% (the first w/2 points and the last w/2 points) are handled.
% If ends=0, the ends are zeroed
% If ends=1, the ends are smoothed with progressively
% smaller smooths the closer to the end.
% See http://terpconnect.umd.edu/~toh/spectrum/Smoothing.html
%
% The D key (or optional input argument "dm") determines the derivative
% order (O, 1, 2, 3, 4, 5, and back to 0). See
% http://terpconnect.umd.edu/~toh/spectrum/Differentiation.html
%
% The E key (or optional argument "rm") turns off and on peak
% sharpening (resolution enhancement). The sharpening strength is
% controled by the F and V keys (optional argument "s1") and B and G
% keys (optional argument "s2"). The optimum values depend on the
% peak shape and width; For details, see
% http://terpconnect.umd.edu/~toh/spectrum/InteractiveResEnhance.htm).
%
% Shift-S key toggles on and off Frequency Spectrum mode, which computes
% frequency spectrum of the segment of the signal displayed in the upper
% window and displays it in the lower window (in red). Use the pan and zoom
% keys to adjust the region of the signal to be viewed. (Press Ctrl-A to
% select the entire signal). In the frequency spectrum mode, you can press
% Shift-A to cycle through four plot modes (linear, semilog X, semilog Y,
% or log-log) and press Shift-X to toggle between a frequency on the x axis
% and time on the x-axis. Press Shift-S again to return to the normal mode.
% Shift-Z toggles on and off peak detection and labeling on the
% frequency/time spectrum. Adjust peak detection in lines 2196-2199; see
% http://terpconnect.umd.edu/~toh/spectrum/PeakFindingandMeasurement.htm
%
% The P key toggles off and on the peak measure mode, which measures and
% displays the peak position, height, width, and area of the one peak
% at a time if it is centered and zoomed in; a red "cap" on the peak
% indicates that portion of the signal that is taken for the measurement.
% The 'R' key prints out the peak measures in the command window.
% The L key toggles off and on the Overlay mode, which overlays the
% selected portion in the upper plot with the original signal as a dotted
% line, for comparison.
% The H key switches between linear and log y-axis on the lower plot. The 0
% (zero) key set minimun signal to zero.
% The ; key (semicolon) sets the entire selected region to zero (use to
% remove stray data points).
% The Tab key resets smooth, derivative, and sharpen effects to zero.
% The O (letter O) key saves the X,Y processed signal as a "mat" file, in a
% location and with a file name that you specify.
% The C key condenses the signal by the specified factor N, replacing each
% group of N points with their average;
% The I key replaces the signal with a linearily interploated version
% containing N data points.
% The M key implements a median filter for removing spikes. The ~ key
% limits the maximum rate of change of the signal.
% The + key computes the absolute value of the entire signal.
%
% Press K to see all keyboard commands.
%
% EXAMPLE 1: Data in two columns of a matrix: [x y].
% >> load data.mat
% >> isignal(DataMatrix);
%
% EXAMPLE 2: Data in separate x,y vectors or single y vector
% >> isignal(x,y); or
% >> isignal(y);
%
% EXAMPLE 3: As above, but specifies initial values of pan (xcenter) and
% zoom (xrange) in the last two input arguments.
% >> isignal(DataMatrix,180,40); or
% >> isignal(x,y,180,40);
%
% EXAMPLE 4: As above, but additionally specifies initial values of
% SmoothMode, SmoothWidth, ends, and DerivativeMode.
% >> isignal(DataMatrix,180,40,2,9,0,1);
%
% EXAMPLE 5: As above, but additionally specifies initial values of the
% peak sharpening parameters Sharpen, Sharp1, and Sharp2.
% >> isignal(DataMatrix,180,40,4,19,0,0,1,51,6000);
% (Press 'E' key to toggle sharpening ON/OFF)
%
% EXAMPLE 6: >> x=[0:.005:2];y=humps(x);Data=[x;y];
% 4th derivative of the peak at x=0.9:
% >> isignal(Data,0.9,0.5,1,3,1,4);
% Peak sharpening applied to the peak at x=0.3:
% >> isignal(Data,0.3,0.5,4,3,1,0,1,220,5400);
% (Press 'E' key to toggle sharpening ON/OFF)
%
% EXAMPLE 7: Measurement of peak area. This example generates four
% Gaussian peaks, all with the exact same peak height (1.00) and area
% (1.77). The first peak (at x=4) is isolated, the second peak (x=9)
% is slightly overlapped with the third one, and the last two peaks
% (at x= 13 and 15) are strongly overlapped. To measure the area under
% a peak using the perpendicular drop method, position the dotted red
% marker lines at the minimum between the overlapped peaks.
%
% >> x=[0:.01:20];y=exp(-(x-4).^2)+exp(-(x-9).^2)+exp(-(x-13).^2)+exp(-(x-15).^2);
% >> isignal(x,y);
%
% EXAMPLE 8: Single peak with random spikes. Compare smoothing vs spike
% filter (M key) and slew rate limit (~ key) to remove spikes.
% >> x=-5:.01:5;
% >> y=exp(-(x).^2);for n=1:1000,if randn()>2,y(n)=rand()+y(n);,end,end;
% >> isignal(x,y);
%
% Example 9: Weak peak at x=128 on a smooth, curved background.
% Try second derivative + smoothing
% >> x=1:.1:256;
% >> y=gaussian(x,-100,300)+.02.*gaussian(x,128,30)+0.001.*randn(size(x));
% >> isignal(x,y);
%
% Example 10: Spectrum mode
% >> x=0:.1:60; y=sin(x)+sin(10.*x);
% >> [pY,PowerSpectrum]=isignal([x;y],30,30,4,3,1,0,0,1,0,0,0,1);
% >> plot(PowerSpectrum)
%
% Example 11: Noisy 4th derivative signal. Adjust smoothing to reveal peak
% at x=150, height=1e-4; SNR=90.
% isignal(x,deriv4(100000.*gaussian(x,150,PeakWidth)+.1*randn(size(x))));
%
% KEYBOARD CONTROLS, version 5.5:
% Pan signal left and right...Coarse pan: < and >
% Fine pan: left and right cursor arrows
% Nudge: [ and ]
% Zoom in and out.............Coarse zoom: / and "
% Fine zoom: up and down cursor arrows
% Resets pan and zoom.........ESC
% Select entire signal........Ctrl-A
% Display Grid (on/off).......Shift-G Temporarily displays grid on plots
% Adjust smooth width.........A,Z (A=>more, Z=>less)
% Adjust smooth type..........S (No, Rectanglular, Triangle, Gaussian, Savitzky-Golay)
% Toggle smooth ends..........X (0=ends zeroed 1=ends smoothed (slower)
% Cycle derivative orders.....D/Shift-D Increase/Decrease derivative order
% Toggle peak sharpening......E (0=OFF 1=ON)
% Sharpening for Gaussian.....Y Set sharpen settings for Gaussian
% Sharpening for Lorentzian...U Set sharpen settings for Lorentzian
% Adjust sharp1...............F,V F=>sharper, V=>less sharpening
% Adjust sharp2...............G,B G=>sharper, B=>less sharpening
% Slew rate limit (0=OFF).....` Largest allowed change between points
% Spike filter width (O=OFF)..m Spike filter eliminates sharp spikes
% Toggle peak parabola........P fits parabola to center, labels vertex
% Fit polynomial to segment...Shift-o Asks for polynomial order
% Fits peak in upper window...Shift-F (Asks for shape, number of peaks, etc)
% Spectrum mode on/off........Shift-S (Shift-A and Shift-X to change axes)
% Peak labels on spectrum.....Shift-Z in spectrum/time mode
% Display Waterfall spectrum..Shift-W Allows choice of mesh, surf, contour, or pcolor
% Lock in current processing..Shift-L Replace signal with processed version
% ConVolution/DeconVolution...Shift-V Convolution/Deconvolution menu
% Click on graph..............C Prints out x and y coordinates
% Print peak report...........R prints position, height, width, area
% Toggle overlay mode.........L Overlays original signal as dotted line
% Toggle log y mode...........H semilog plot in lower window
% Cycles baseline mode........T none, linear, quadratic, or flat baseline mode
% Restores original signal....Tab or Ctrl-Z key resets to previous signal
% Baseline subtraction........Backspace, then click baseline at multiple points
% Restore background..........\ to cancel previous background subtraction
% Invert signal...............Shift-N Invert (negate) the signal (flip + and -)
% Remove offset...............0 (zero) set minimun signal to zero
% Sets region to zero.........; sets selected region to zero.
% Absolute value..............+ Computes absolute value of entire signal')
% Condense signal.............C Condense oversampled signal by factor N
% Interpolate signal..........i Interpolate (resample) to N points
% Print keyboard commands.....K prints this list
% Print signal report.........Q prints signal info and current settings
% Print isignal arguments.....W prints isignal (current arguments)
% Save output to disk.........O as .mat file with processed signal matrix
% Play signal as sound........Spacebar or Shift-P Play selected section
% Play signal as sound........Shift-R Change sampling rate for playing sound
% Switch to ipf.m.............Shift-Ctrl-F transfer current signal to ipf.m
% Switch to iPeak.............Shift-Ctrl-P transfer current signal to iPeak.m
% Copyright (c) 2016, Thomas C. O'Haver
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the "Software"), to deal
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included in
% all copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
% THE SOFTWARE.
%
global X Y xo dx DerivativeMode Sharpen Sharp1 Sharp2 SmoothWidth SlewRate MedianWidth
global SmoothType ends SmoothMode SavedSignal SavedXvalues PeakLabels Report autozero
global plotmode xmode SpectrumMode samplerate LabelPeaks NumSigs DataMatrix
format short g
format compact
warning off all
DataMatrix=datamatrix;
NumSigs=1;
switch nargin % Process arguments
% 'nargin' is the number of arguments
case 1 % One argument only
% Might be isignal(DataMatrix) ot isignal(Y-vector)
% If data is in the wrong transposition, fix it.
datasize=size(DataMatrix);
if datasize(1)<datasize(2),DataMatrix=DataMatrix';end
datasize=size(DataMatrix);
if datasize(2)==1, % Must be isignal(Y-vector)
X=1:length(DataMatrix); % Create an independent variable vector
Y=DataMatrix;
else
% Must be isignal(DataMatrix)
X=DataMatrix(:,1); % Split matrix argument
Y=DataMatrix(:,2);
end
SmoothMode=0; % Initial SmoothMode = Rect
SmoothWidth=3; % Initial smooth width
SmoothType='Rect.'; % Label for initial SmoothMode
DerivativeMode=0; % Derivative mode off initially
ends=0; % Initial smooth ends setting zero (no tapering)
Sharpen=0; % Initially no sharpening
Sharp1=10; % Initial factor1 for resolution enhancement
Sharp2=1000; % Initial factor2 for resolution enhancement
SlewRate=0;
MedianWidth=0;
xo=length(Y)/2; % Initial Pan setting
dx=length(Y); % Initial Zoom setting
SpectrumMode=0; % Frequency spectrum initially off.
case 2
% Two arguments, might be separate x and y data vectors,
% or one data matrix and a peak density estimate.
if isscalar(xcenter) % if second argument is scalar
% Must be isignal(DataMatrix,xcenter)
% If DataMatrix is in the wrong transposition, fix it.
datasize=size(DataMatrix);
if datasize(1)<datasize(2),DataMatrix=DataMatrix';end
X=DataMatrix(:,1); % Split matrix argument
Y=DataMatrix(:,2);
xo=val2ind(X,xcenter);
else % if second argument is not scalar
% Must be isignal(x,y)
xdatasize=size(DataMatrix);
if xdatasize(1)<xdatasize(2),DataMatrix=DataMatrix';end
X=DataMatrix; % First argument is X
xdatasize=size(xcenter);
if xdatasize(1)<xdatasize(2),xcenter=xcenter';end
Y=xcenter; % Second argument is Y
xo=length(Y)/2; % % Default initial zoom setting
end % if isscalar
SmoothMode=0; % Initial SmoothMode = No
SmoothWidth=3; % Initial smooth width
SmoothType='Rect.'; % Label for initial SmoothMode
DerivativeMode=0; % Derivative mode off initially
ends=0; % Initial smooth ends setting zero (no tapering)
Sharpen=0; % Initially no sharpening
Sharp1=10; % factor1 for resolution enhancement
Sharp2=1000; % factor2 for resolution enhancement
SlewRate=0;
MedianWidth=0;
dx=length(Y); % % Default initial zoom setting
SpectrumMode=0; % Frequency spectrum initially off.
case 3
% Might be isignal(DataMatrix,xcenter,xrange) or isignal(x,y,xcenter)
if isscalar(xcenter) % if second argument is scalar
% Must be isignal(DataMatrix,xcenter,xrange)
% If DataMatrix is in the wrong transposition, fix it.
datasize=size(DataMatrix);
if datasize(1)<datasize(2),DataMatrix=DataMatrix';end
X=DataMatrix(:,1); % Split matrix argument
Y=DataMatrix(:,2);
[xo,dx]=panandzoom(X,xcenter,xrange);
else % if second argument is not isscalar
% Must be isignal(x,y,xcenter)
xdatasize=size(DataMatrix);
if xdatasize(1)<xdatasize(2),DataMatrix=DataMatrix';end
X=DataMatrix; % First argument is X
xdatasize=size(xcenter);
if xdatasize(1)<xdatasize(2),xcenter=xcenter';end
Y=xcenter; % Second argument is Y
xo=xrange; % third argument is xcenter
dx=length(Y); % Default initial zoom setting
end % if isscalar
SmoothMode=0; % Initial SmoothMode = No
SmoothWidth=3; % Initial smooth width
SmoothType='Rect.'; % Label for initial SmoothMode
DerivativeMode=0; % Derivative mode off initially
ends=0; % Initial smooth ends setting zero (no tapering)
Sharpen=0; % Initially no sharpening
Sharp1=10; % factor1 for resolution enhancement
Sharp2=1000; % factor2 for resolution enhancement
SlewRate=0;
MedianWidth=0;
SpectrumMode=0; % Frequency spectrum initially off.
case 4 % Must be isignal(x,y,xcenter,xrange)
xdatasize=size(DataMatrix);
if xdatasize(1)<xdatasize(2),DataMatrix=DataMatrix';end
X=DataMatrix; % First argument is X
xdatasize=size(xcenter);
if xdatasize(1)<xdatasize(2),xcenter=xcenter';end
Y=xcenter; % Second argument is Y
SmoothMode=0; % Initial SmoothMode = No
SmoothWidth=3; % Initial smooth width
SmoothType='Rect.'; % Label for initial SmoothMode
DerivativeMode=0; % Derivative mode off initially
ends=0; % Initial smooth ends setting zero (no tapering)
Sharpen=0; % Initially no sharpening
Sharp1=10; % factor1 for resolution enhancement
Sharp2=1000; % factor2 for resolution enhancement
SlewRate=0;
MedianWidth=0;
[xo,dx]=panandzoom(X,xrange,sm);
SpectrumMode=0; % Frequency spectrum initially off.
case 7
% One data matrix, all smoothing and derivative parameters specified
% in arguments, default values for resolution enhancement.
% If DataMatrix is in the wrong transposition, fix it.
datasize=size(DataMatrix);
if datasize(1)<datasize(2),DataMatrix=DataMatrix';end
X=DataMatrix(:,1); % Split matrix argument
Y=DataMatrix(:,2);
[xo,dx]=panandzoom(X,xcenter,xrange);
SmoothMode=sm; % SmoothMode (O, 1, 2, 3 or 4)
SmoothWidth=sw; % Smooth width
DerivativeMode=dm; % Derivative mode (0, 1, 2, 3, 4)
ends=em; % Smooth ends setting (0 or 1)
Sharpen=0; % Initially no sharpening
Sharp1=10; % factor1 for resolution enhancement
Sharp2=1000; % factor2 for resolution enhancement
SlewRate=0;
MedianWidth=0;
SpectrumMode=0; % Frequency spectrum initially off.
case 10
% One data matrix, all signal processing parameters specified
% in arguments, including resolution enhancement.
% If DataMatrix is in the wrong transposition, fix it.
datasize=size(DataMatrix);
if datasize(1)<datasize(2),DataMatrix=DataMatrix';end
X=DataMatrix(:,1); % Split matrix argument
Y=DataMatrix(:,2);
[xo,dx]=panandzoom(X,xcenter,xrange);
SmoothMode=sm; % SmoothMode sm
SmoothWidth=sw; % Smooth width
DerivativeMode=dm; % Derivative mode (0, 1, 2, 3, 4)
ends=em; % Smooth ends setting (0 or 1)
Sharpen=rm; % Sharpen mode
Sharp1=s1; % factor1 for resolution enhancement
Sharp2=s2; % factor2 for resolution enhancement
SlewRate=0;
MedianWidth=0;
SpectrumMode=0; % Frequency spectrum initially off.
case 11
% One data matrix, all signal processing parameters specified
% in arguments, except MedianWidth.
% If DataMatrix is in the wrong transposition, fix it.
datasize=size(DataMatrix);
if datasize(1)<datasize(2),DataMatrix=DataMatrix';end
X=DataMatrix(:,1); % Split matrix argument
Y=DataMatrix(:,2);
[xo,dx]=panandzoom(X,xcenter,xrange);
SmoothMode=sm; % SmoothMode sm
SmoothWidth=sw; % Smooth width
DerivativeMode=dm; % Derivative mode (0, 1, 2, 3, 4)
ends=em; % Smooth ends setting (0 or 1)
Sharpen=rm; % Sharpen mode
Sharp1=s1; % factor1 for resolution enhancement
Sharp2=s2; % factor2 for resolution enhancement
SlewRate=sr;
MedianWidth=0;
SpectrumMode=0; % Frequency spectrum initially off.
case 12
% One data matrix, all signal processing parameters specified
% in arguments, except SpectrumMode.
% If DataMatrix is in the wrong transposition, fix it.
datasize=size(DataMatrix);
if datasize(1)<datasize(2),DataMatrix=DataMatrix';end
X=DataMatrix(:,1); % Split matrix argument
Y=DataMatrix(:,2);
[xo,dx]=panandzoom(X,xcenter,xrange);
SmoothMode=sm; % SmoothMode sm
SmoothWidth=sw; % Smooth width
DerivativeMode=dm; % Derivative mode (0, 1, 2, 3, 4)
ends=em; % Smooth ends setting (0 or 1)
Sharpen=rm; % Sharpen mode
Sharp1=s1; % factor1 for resolution enhancement
Sharp2=s2; % factor2 for resolution enhancement
SlewRate=sr;
MedianWidth=mw;
SpectrumMode=0; % Frequency spectrum initially off.
case 13
% One data matrix, all signal processing parameters specified
% in arguments, except SpectrumMode.
% If DataMatrix is in the wrong transposition, fix it.
datasize=size(DataMatrix);
if datasize(1)<datasize(2),DataMatrix=DataMatrix';end
X=DataMatrix(:,1); % Split matrix argument
Y=DataMatrix(:,2);
[xo,dx]=panandzoom(X,xcenter,xrange);
SmoothMode=sm; % SmoothMode sm
SmoothWidth=sw; % Smooth width
DerivativeMode=dm; % Derivative mode (0, 1, 2, 3, 4)
ends=em; % Smooth ends setting (0 or 1)
Sharpen=rm; % Sharpen mode
Sharp1=s1; % factor1 for resolution enhancement
Sharp2=s2; % factor2 for resolution enhancement
SlewRate=sr;
MedianWidth=mw;
SpectrumMode=spm;
otherwise
disp('Invalid number of arguments')
disp('Expected forms are:')
disp('isignal(y); % Data in single y vector')
disp('isignal(x,y); % Data in separate x and y vectors')
disp('isignal(DataMatrix); % Data in two columns of DataMatrix')
disp('isignal(x,y,xcenter,xrange); ')
disp('isignal(DataMatrix,xcenter,xrange;) ')
disp('isignal(DataMatrix,xcenter,xrange,SmoothMode,SmoothWidth,ends,DerivativeMode); ' )
disp('isignal(DataMatrix,xcenter,xrange,SmoothMode,SmoothWidth,ends,DerivativeMode,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth); ')
beep
return
end % switch nargin
% Define smooth type string for xlabel
switch SmoothMode
case 0
SmoothType='No';
case 1
SmoothType='Rect.';
case 2
SmoothType='Tri.';
case 3
SmoothType='Gauss';
case 4
SmoothType='Savitzky-Golay';
end
PeakLabels=0; % Start with peak label turned off
% Save original signal in SavedSignal for undo function
SavedSignal=Y;
SavedXvalues=X;
Overlay=0; % Start with overlay turned off
Report=0;
autozero=0;
logymode=0; % Start in linear y mode.
plotmode=2; % Frequency spectrum initially in semilog y mode.
% NumPeaksUW=1;
xmode=0;% Frequency spectrum initially in frequency mode.
PowerSpectrum=0;
samplerate=44100;
LabelPeaks=0;
extra=0;
NumTrials=1;
% Plot the signal
[xx,yy]=RedrawSignal(X,Y,xo,dx);
pY=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
Y=pY;
% xo=length(Y)/2; % Initial Pan setting
% dx=length(Y); % Initial Zoom setting
[xx,yy]=RedrawSignal(X,Y,xo,dx);
maxy=max(yy);
miny=min(yy);
area=trapz(xx,yy);
stdev=std(yy);
if SpectrumMode==1;
% Plot the power spectrum in the lower half of the window.
[f realsy PowerSpectrum]=PlotFrequencySpectrum(X,Y,xo,dx,plotmode,xmode,LabelPeaks);
subplot(2,1,1)
title('iSignal 5 Frequency Spectrum Mode (Press Shift-S again to cancel')
end
% Attaches KeyPress test function to the figure.
set(gcf,'KeyPressFcn',@ReadKey)
uicontrol('Style','text')
% end of outer function
% ----------------------------SUBFUNCTIONS--------------------------------
function ReadKey(obj,eventdata)
% Interprets key presses from the Figure window. When a key is pressed,
% executes the code in the corresponding section in the SWITCH statement.
% Note: If you don't like my key assignments, you can change the numbers
% in the case statements here to re-assign that function to any other key.
% If you press a key that has not yet beZen assigned to a function, it
% displays the key code number in the command window so you can easily
% add that to the SWITCH statement for your own custom functions.
global X Y xx yy xo dx SmoothMode SmoothWidth DerivativeMode SlewRate extra SpectrumMode
global Sharpen Sharp1 Sharp2 SavedSignal SavedXvalues SavedBackground plotmode
global SmoothType ends PeakLabels Overlay Report GaussEstimate MedianWidth xmode
global LorentzEstimate logymode autozero Shape NumTrials NumPeaksUW fixedparameters
global PowerSpectrum samplerate LabelPeaks SS NumSigs DataMatrix AllMode SavedMatrix
key=get(gcf,'CurrentCharacter');
if isscalar(key),
ly=length(Y);
switch double(key),
case 28
% Pans down when right arrow pressed.
xo=xo-dx/20;
if xo<1,xo=1;end
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 29
% Pans up when left arrow pressed.
xo=xo+dx/20;
if xo>ly,xo=ly;end
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 91
% Nudge down 1 point when [ pressed.
xo=xo-1;
if xo<1,xo=1;end
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 93
% Nudge up 1 point when ] pressed.
xo=xo+1;
if xo>ly,xo=ly;end
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 44
% Pans down when > key pressed.
xo=xo-dx;
if xo<1,xo=1;end
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 46
% Pans up when < key pressed.
xo=xo+dx;
if xo>ly,xo=ly;end
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 31
% Zooms up when up arrow pressed.
dx=dx+dx/10;
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 30
% Zooms down when down arrow pressed.
dx=dx-dx/10;
if dx>ly,dx=ly;end
if dx<2,dx=2;end
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 47
% Zooms x 2 up when / pressed.
dx=dx*2;
if dx>ly,dx=ly;end
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 39
% Zooms x 1/2 down when ' pressed.
dx=round(dx/2);
if dx<2,dx=2;end
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 1 % Ctrl-A selects entire signal
xo=length(Y)/2; % Initial Pan setting
dx=length(Y); % Initial Zoom setting
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 71 % Shift-G temporatiy displays grid on both upper and lower panels
subplot(211);grid
subplot(212);grid
% case {49,50,51,52,53,54,55,56,57}
% % When a number key is pressed, sets the signal
% % number
% % NumSigs=NumSigs; % Testing
% AllMode=0;
% SS=key-48;
% if SS>NumSigs,
% disp('The signal matrix is not that large.')
% SS=NumSigs;
% end
% datasize=size(DataMatrix);
% % if SS>sizey(2),SS=sizey(2);end
% % SignalSelected=[SS NumSigs]
% % sizeX=size(X)
% % sizeY=size(Y)
% switch SmoothMode(SS)
% case 0
% SmoothType='No';
% case 1
% SmoothType='Rect.';
% case 2
% SmoothType='Tri.';
% case 3
% SmoothType='Gauss';
% case 4
% SmoothType='Savitzky-Golay';
% end
% Y=ProcessSignal(X,DataMatrix(:,SS),DerivativeMode(SS),SmoothWidth(SS),SmoothMode(SS),ends(SS),Sharpen(SS),Sharp1(SS),Sharp2(SS),SlewRate(SS),MedianWidth(SS));
% [xx,yy]=RedrawSignal(X,Y,xo,dx);
case 41 % When Shift-0 ')' key is pressed, asks for the signal number
SS=input('Enter desired signal number and press Enter:');
if isempty(SS),SS=1;end
if isnan(SS),SS=1;end
if SS>NumSigs,
disp('The signal matrix is not that large.')
SS=NumSigs;
end
switch SmoothMode(SS)
case 0
SmoothType='No';
case 1
SmoothType='Rect.';
case 2
SmoothType='Tri.';
case 3
SmoothType='Gauss';
case 4
SmoothType='Savitzky-Golay';
end
Y=DataMatrix(:,SS);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 63 % Shift-?
disp(['SizeDataMatrix= ' num2str(size(DataMatrix)) ] )
MaxY=max(max(Y));disp(['MaxY = ' num2str(MaxY) ] )
MinY=min(min(Y));disp(['MinY = ' num2str(MinY) ] )
disp(['DerivativeMode = ' num2str(DerivativeMode) ] )
disp(['SmoothWidth = ' num2str(SmoothWidth) ] )
disp(['SmoothMode = ' num2str(SmoothMode) ] )
disp(['Sharpen = ' num2str(Sharpen) ] )
disp(['Sharp1 = ' num2str(Sharp1) ] )
disp(['Sharp2 = ' num2str(Sharp2) ] )
disp(['MedianWidth = ' num2str(MedianWidth) ] )
disp(['SlewRate = ' num2str(SlewRate) ] )
disp(['Peak Shape = ' num2str(Shape) ] )
disp(['NumPeaks = ' num2str(NumPeaksUW) ] )
disp(['NumTrials = ' num2str(NumTrials) ] )
disp(['Baseline mode = ' num2str(autozero) ] )
case 77 % Shift-M key applies current processing variable to all signals
for sig=1:NumSigs
DerivativeMode(sig)=DerivativeMode(SS);
SmoothWidth(sig)=SmoothWidth(SS);
SmoothMode(sig)=SmoothMode(SS);
Sharpen(sig)=Sharpen(SS);
ends(sig)=ends(SS);
Sharp1(sig)=Sharp1(SS);
Sharp2(sig)=Sharp2(SS);
MedianWidth(sig)=MedianWidth(SS);
Y=ProcessSignal(X,SavedMatrix(:,sig),DerivativeMode(SS),SmoothWidth(SS),SmoothMode(SS),ends(SS),Sharpen(SS),Sharp1(SS),Sharp2(SS),SlewRate(SS),MedianWidth(SS));
DataMatrix(:,sig)=Y;
end
disp('Current signal processing applied to all signals')
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 8
% When 'Backspace' key is pressed, user clicks the graph
% along the presumed background points, then the program
% subtracts the interploated background between the points.
SavedBackground=Y;
disp('Multi-point baseline subtraction')
BaselinePoints=input('Number of baseline points to click): ');
if isempty(BaselinePoints),BaselinePoints=8;end
% Acquire background points from user mouse clicks
subplot(2,1,2)
title(['Click on ' num2str(BaselinePoints) ' points on the baseline between the peaks.'])
bX=[];bY=[];
for g=1:BaselinePoints;
[clickX,clickY] = ginput(1);
bX(g)=clickX;
bY(g)=clickY;
xlabel(['Baseline point ' num2str(g) ' / ' num2str(BaselinePoints) ])
end
tempY=Y;
for k=1:length(bX)-1,
fp=val2ind(X,bX(k)); % First point in segment
lp=val2ind(X,bX(k+1)); % Last point in segment
% Subtract piecewise linear background from Y
tempY(fp:lp)=Y(fp:lp)-((bY(k+1)-bY(k))/(bX(k+1)-bX(k))*(X(fp:lp)-bX(k))+bY(k));
end
Y=tempY;
SavedSignal=Y;
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 92
% When '\' key is pressed, restoreed original signal
SavedSignal=SavedBackground;
X=SavedXvalues;
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 122
% When 'z' key is pressed, DEcreases "SmoothWidth" by 1 or 10%
if SmoothMode==0,
SmoothMode=1;
SmoothType='Rect.';
end
if SmoothWidth>20,
SmoothWidth=round(SmoothWidth-.1.*SmoothWidth);
SmoothWidth=2*round(SmoothWidth/2)-1;
else
SmoothWidth=SmoothWidth-1;
end
if SmoothWidth<1, SmoothWidth=1;end
if SmoothMode==0,
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
else
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
end
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 97
% When 'a' key is pressed, INcreases "SmoothWidth" by 1 or 10%
if SmoothMode==0,
SmoothMode=1;
SmoothType='Rect.';
end
if SmoothWidth>20,
SmoothWidth=round(SmoothWidth+.1.*SmoothWidth);
SmoothWidth=2*round(SmoothWidth/2)+1;
else
SmoothWidth=SmoothWidth+1;
end
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 115 % When 's' key is pressed, steps through SmoothModes
SmoothMode=SmoothMode+1;
if SmoothMode==5,SmoothMode=0; end
switch SmoothMode
case 0
SmoothType='No';
case 1
SmoothType='Rect.';
case 2
SmoothType='Tri.';
case 3
SmoothType='Gauss';
case 4
SmoothType='Savitzky-Golay';
end
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 120 % When 'x' key is pressed, toggles between ends 0 and 1
if ends==0,
ends=1;
else
ends=0;
end
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 100
% When 'd' key is pressed, cycles through DerivativeModes 0,1,2,3,4,5->0
% if length(Y)>10000,disp('Warning: Derivatives can be slow for for signal lengths above 10,000 points'),end
DerivativeMode=DerivativeMode+1;
if DerivativeMode==6,DerivativeMode=0; end
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 68
% When 'Shift-d' key is pressed, cycles through DerivativeModes 5,4,3,2,1->0
% if length(Y)>10000,disp('Warning: Derivatives can be slow for for signal lengths above 10,000 points'),end
DerivativeMode=DerivativeMode-1;
if DerivativeMode==-1,DerivativeMode=5; end
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 101 % When 'e' key is pressed, toggles between Sharpen 0 and 1
% if length(Y)>10000,disp('Warning: Sharpening can be slow for for signal lengths above 10,000 points'),end
if Sharpen==0,
Sharpen=1;
SmoothMode=4;
if SmoothWidth<3;SmoothWidth=3;end
SmoothType='Savitzky-Golay';
else
Sharpen=0;
end
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 121 % When 'y' key is pressed, sets Sharp1 and 2 for Gaussian
GaussEstimate=1;
% if length(Y)>10000,disp('Warning: Sharpening can be slow for
% for signal lengths above 10,000 points'),end
PeakLabels=1;
SmoothMode=4;
if SmoothWidth<3;SmoothWidth=3;end
SmoothType='Savitzky-Golay';
[xx,yy]=RedrawSignal(X,Y,xo,dx);
Sharpen=1;
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 117 % When 'u' key is pressed, sets Sharp1 and 2 for Lorentzian
LorentzEstimate=1;
% if length(Y)>10000,disp('Warning: Sharpening can be slow for for signal lengths above 10,000 points'),end
SmoothMode=4;
if SmoothWidth<3;SmoothWidth=3;end
SmoothType='Savitzky-Golay';
PeakLabels=1;
[xx,yy]=RedrawSignal(X,Y,xo,dx);
Sharpen=1;
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 102
% When 'f' key is pressed, increases Sharp1
if Sharpen==0,Sharpen=1;end
Sharp1=Sharp1+.1*Sharp1;
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 118
% When 'v' key is pressed, decreases Sharp1
if Sharpen==0,Sharpen=1;end
Sharp1=Sharp1-.1*Sharp1;
if Sharp1<0, Sharp1=0;end
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 103
% When 'g' key is pressed, increases Sharp2
if Sharpen==0,Sharpen=1;end
Sharp2=Sharp2+.1*Sharp2;
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 98
% When 'b' key is pressed, decreases Sharp2
if Sharpen==0,Sharpen=1;end
Sharp2=Sharp2-.1*Sharp2;
if Sharp2<0, Sharp2=0;end
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 112
% When 'p' key is pressed, toggles on/off peak labels in upper panel
if PeakLabels==0,
PeakLabels=1;
else
PeakLabels=0;
end
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 108 % When 'L' key is pressed, toggles between ends 0 and 1
if Overlay==0,
Overlay=1;
else
Overlay=0;
end
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 104 % When 'H' key is pressed, toggles between normal and logy plot
if logymode==0,
logymode=1;
else
logymode=0;
end
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 114 % When 'R' key is pressed, toggles between Report 0 and 1
if Report==0,
Report=1;
switch autozero,
case 0
disp('No baseline correction')
case 1
disp('Linear baseline subtraction')
case 2
disp('Quadratic subtraction baseline')
case 3
disp('Flat baseline correction')
end
disp('Position Height Width Gauss. Area Total Area SNR FWHM')
else
Report=0;
end
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 116 % When 'T' key is pressed, toggles between normal and autozero plot
% When 't' key is pressed, steps through AUTOZERO modes
autozero=autozero+1;
if autozero==4,autozero=0;end
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case {9,26} % When 'Tab' or Ctrl-Z key is pressed, resets to original signal and modes
Y=SavedSignal;
X=SavedXvalues;
SmoothMode=0;
SmoothWidth=1;
SmoothType='No';
DerivativeMode=0;
Sharpen=0;
SlewRate=0;
MedianWidth=0;
Y=ProcessSignal(X,Y,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 27 % When 'ESC' key is pressed, resets pan and zoom
xo=length(Y)/2; % Initial Pan setting
dx=length(Y)/4; % Initial Zoom setting
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 59
% When ';' key is pressed, replaces selected segment with zeros
doit=input('Replace selected region with zeros?','s');
if doit=='y',
startpoint=round(xo-dx/2);
if startpoint<1;startpoint=1;end
endpoint=round(xo+dx/2);
if endpoint>length(Y);endpoint=length(Y);end
Y(startpoint:endpoint)=0;
end
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 48
% When '0' key is pressed, minimum value of Y is set to zero
Y=Y-min(Y);
SavedSignal=Y;
[xx,yy]=RedrawSignal(X,Y,xo,dx);
disp('Signal re-zeroed')
case 78
% When 'Shift-N' key is pressed, invert the signal
SavedSignal=-SavedSignal;
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 61
% When '+' plus key is pressed, compute absolute value of the signal
SavedSignal=abs(SavedSignal);
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 96
% When '~' (tilde) key is pressed, enforce maximum slew rate
SavedSignal=Y;
disp(['Current slew rate limit =' num2str(SlewRate)])
SlewRate=input('Enter desired slew rate:');
if SlewRate=='',SlewRate=0;end
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 109
% When 'm' key is pressed, performs median filter
SavedSignal=Y;
disp(['Current spike width =' num2str(MedianWidth)])
MedianWidth=input('Enter spike width (1,2,3,...):');
if MedianWidth=='',MedianWidth=0;end
MedianWidth=round(MedianWidth);
Y=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
[xx,yy]=RedrawSignal(X,Y,xo,dx);
case 127
% When 'Delete' key is pressed, sets the single point under the
% green cursor to zero
Y(round(xo))=0;
SavedSignal=Y;
[xx,yy]=RedrawSignal(X,Y,xo,dx);
% case 95 % FUTURE ADDITION?
% % When '_' key (Shift '-') is pressed, replaces selected region
% startpoint=round(xo-dx/2);
% if startpoint<1;startpoint=1;end
% endpoint=round(xo+dx/2)-1;
% if endpoint>length(Y);endpoint=length(Y);end
% lxx=length(xx);
% bkgsize=2;
% X1=xx(1:round(lxx/bkgsize));
% X2=xx((lxx-round(lxx/bkgsize)):lxx);
% MX=[X1;X2];
% Y1=yy(1:round(length(xx)/bkgsize));
% Y2=yy((lxx-round(lxx/bkgsize)):lxx);
% MY=[Y1;Y2];
% bkgcoef=polyfit(MX,MY,1); % Fit straight line to sub-group of points
% bkg=polyval(bkgcoef,xx);
% Y(startpoint:endpoint)=bkg;
% Y=ProcessSignal(X,Y,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
% [xx,yy]=RedrawSignal(X,Y,xo,dx);
case 73
% When 'I' key (upper-case i or Shift-i) is pressed, integrates the signal
sum=0;
for n=1:length(X),
sum=sum+Y(n);
Y(n)=sum;
end
[xx,yy]=RedrawSignal(X,Y.*(X(2)-X(1)),xo,dx);
case 6 % Shift-Ctrl-F transfers current signal to Interactive Curve Fitter
ipf(X,Y);
case 16 % Shift-Ctrl-P transfers current signal to Interactive Peak Detector
ipeak(X,Y);
case 21 % Shift-Ctrl-U transfers current signal to Interactive Fourier Filter
ifilter(X,Y);
case 105
% When 'i' key (lower-case i) is pressed, interpolates the signal
% to find XI,YI, the values of the underlying function Y at the points
% linearly interpolated between the points of X, using interp1.
disp(['X,Y size before interpolation = ' num2str(size(X)) ' , ' num2str(size(Y)) ] )
InterPoints=input('Number of points in interpolated signal: ');
if InterPoints>1,
Xi=linspace(min(X),max(X),InterPoints);
Y=interp1(X,Y,Xi)';
X=Xi';
disp(['X,Y size after interpolation = ' num2str(size(X)) ' , ' num2str(size(Y)) ] )
xo=length(Y)/2; % Initial Pan setting
dx=length(Y)/4; % Initial Zoom setting
SavedSignal=Y;
SavedXvalues=X;
pY=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
Y=pY;
RedrawSignal(X,Y,xo,dx);
end
case 99
% When C key is pressed, condenses signal by specified factor
CondenseFactor=input('Condense oversampled signal by factor of (e.g. 2, 3, 4...): ');
if CondenseFactor>1,
disp([ 'X,Y size before condensation = ' num2str(size(X)) ' , ' num2str(size(Y)) ] )
X=condense(X,CondenseFactor)';
Y=condense(Y,CondenseFactor)';
xo=length(Y)/2; % Initial Pan setting
dx=length(Y)/4; % Initial Zoom setting
SavedSignal=Y;
SavedXvalues=X;
disp([ 'X,Y size after condensation = ' num2str(size(X)) ' , ' num2str(size(Y)) ] )
pY=ProcessSignal(X,SavedSignal,DerivativeMode,SmoothWidth,SmoothMode,ends,Sharpen,Sharp1,Sharp2,SlewRate,MedianWidth);
Y=pY;
RedrawSignal(X,Y,xo,dx);