summaryrefslogtreecommitdiff
path: root/macros/mscohere.sci
diff options
context:
space:
mode:
authorAbinash Singh2024-08-08 16:44:10 +0530
committerAbinash Singh2024-08-08 16:44:10 +0530
commit2e21edde1c1a251a60739b15e1c699172401f044 (patch)
tree4c2655d2cc3a57fd8e262001c5f93ef870469610 /macros/mscohere.sci
parent1a3caa688450fd49135a1777418c7370e15bb72d (diff)
downloadFOSSEE-Signal-Processing-Toolbox-2e21edde1c1a251a60739b15e1c699172401f044.tar.gz
FOSSEE-Signal-Processing-Toolbox-2e21edde1c1a251a60739b15e1c699172401f044.tar.bz2
FOSSEE-Signal-Processing-Toolbox-2e21edde1c1a251a60739b15e1c699172401f044.zip
Implemented by Abinash Singh during FOSSEE semester long fellowship 2024
issues in Pwelch : Handle neagtive inputs to strictly postive arguments of log plots Function should be tested for every possible calling Sequence.
Diffstat (limited to 'macros/mscohere.sci')
-rw-r--r--macros/mscohere.sci122
1 files changed, 41 insertions, 81 deletions
diff --git a/macros/mscohere.sci b/macros/mscohere.sci
index 357da58..b9a45f8 100644
--- a/macros/mscohere.sci
+++ b/macros/mscohere.sci
@@ -1,82 +1,42 @@
-function [PXX, FREQ] = mscohere (X, Y, WINDOW, OVERLAP, NFFT, FS, RANGE)
-//It estimate (mean square) coherence of signals x and y.
-//Calling Sequence
-//[Pxx, freq] = mscohere (x, y)
-//[Pxx, freq] = mscohere (x, y, window)
-//[Pxx, freq] = mscohere (x, y, window, overlap)
-//[Pxx, freq] = mscohere (x, y, window, overlap, Nfft)
-//[Pxx, freq] = mscohere (x, y, window, overlap, Nfft, Fs)
-//[Pxx, freq] = mscohere (x, y, window, overlap, Nfft, Fs, range)
-//mscohere (...)
-//Description
-//This function estimate (mean square) coherence of signals x and y.
-//Examples
-//[Pxx, freq] = mscohere(4,5)
-//ans =
-//PXX =
-// Nan
-// 1
-//FREQ =
-// 0
-// 0.5
-funcprot(0);
-lhs = argn(1)
-rhs = argn(2)
-if (rhs < 2 | rhs > 7)
-error("Wrong number of input arguments.")
-end
-
-select(rhs)
-
- case 2 then
- if(lhs==0)
- callOctave("mscohere",X,Y)
- elseif(lhs==2)
- [PXX, FREQ] = callOctave("mscohere",X,Y)
- else
- error("Wrong number of output arguments.")
- end
-
- case 3 then
- if(lhs==0)
- callOctave("mscohere",X,Y,WINDOW)
- elseif(lhs==2)
- [PXX, FREQ] = callOctave("mscohere",X,Y,WINDOW)
- else
- error("Wrong number of output arguments.")
- end
- case 4 then
- if(lhs==0)
- callOctave("mscohere",X,Y,WINDOW,OVERLAP)
- elseif(lhs==2)
- [PXX, FREQ] = callOctave("mscohere",X,Y,WINDOW,OVERLAP)
- else
- error("Wrong number of output arguments.")
- end
- case 5 then
- if(lhs==0)
- callOctave("mscohere",X,Y,WINDOW,OVERLAP,NFFT)
- elseif(lhs==2)
- [PXX, FREQ] = callOctave("mscohere",X,Y,WINDOW,OVERLAP,NFFT)
- else
- error("Wrong number of output arguments.")
- end
- case 6 then
- if(lhs==0)
- callOctave("mscohere",X,Y,WINDOW,OVERLAP,NFFT,FS)
- elseif(lhs==2)
- [PXX, FREQ] = callOctave("mscohere",X,Y,WINDOW,OVERLAP,NFFT,FS)
- else
- error("Wrong number of output arguments.")
- end
- case 7 then
- if(lhs==0)
- callOctave("mscohere",X,Y,WINDOW,OVERLAP,NFFT,FS,RANGE,)
- elseif(lhs==2)
- [PXX, FREQ] = callOctave("mscohere",X,Y,WINDOW,OVERLAP,NFFT,FS,RANGE)
- else
- error("Wrong number of output arguments.")
- end
- end
-endfunction
+/*Description:
+Estimate (mean square) coherence of signals x and y. Use the Welch (1967) periodogram/FFT method.
+Calling Sequence:
+ [Pxx, freq] = mscohere (x, y)
+ […] = mscohere (x, y, window)
+ […] = mscohere (x, y, window, overlap)
+ […] = mscohere (x, y, window, overlap, Nfft)
+ […] = mscohere (x, y, window, overlap, Nfft, Fs)
+ […] = mscohere (x, y, window, overlap, Nfft, Fs, range)
+ mscohere (…)
+See "help pwelch" for description of arguments, hints and references
+Dependencies : pwelch
+*/
+function varargout = mscohere(varargin)
+ // Check fixed argument
+ if (nargin < 2 || nargin > 7)
+ error("Invalid number of arguments");
+ end
+ nvarargin = length(varargin);
+ // remove any pwelch RESULT args and add 'cross'
+ for iarg=1:nvarargin
+ arg = varargin(iarg);
+ if ( ~isempty(arg) && ( type(arg) == 10 ) && ( ~strcmp(arg,'power') || ...
+ ~strcmp(arg,'cross') || ~strcmp(arg,'trans') || ...
+ ~strcmp(arg,'coher') || ~strcmp(arg,'ypower') ))
+ varargin(iarg) = [];
+ end
+ end
+ varargin(nvarargin+1) = 'coher';
+ disp(varargin)
+ if ( nargout==0 )
+ pwelch(varargin(:));
+ elseif ( nargout==1 )
+ Pxx = pwelch(varargin(:));
+ varargout(1) = Pxx;
+ elseif ( nargout>=2 )
+ [Pxx,f] = pwelch(varargin(:));
+ varargout(1) = Pxx;
+ varargout(2) = f;
+ end
+ endfunction