diff toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirskewness.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirskewness.m	Tue Feb 10 15:05:51 2015 +0000
@@ -0,0 +1,39 @@
+function varargout = mirskewness(orig,varargin)
+%   s = skewness(x) calculates the skewness of x, showing the (lack of)
+%       symmetry of the curve.
+%   x can be either:
+%       - a spectrum (spectral skewness),
+%       - an envelope (temporal skewness), or
+%       - any histogram.
+
+
+varargout = mirfunction(@mirskewness,orig,varargin,nargout,struct,@init,@main);
+
+
+function [x type] = init(x,option)
+if not(isamir(x,'mirdata')) || isamir(x,'miraudio')
+    x = mirspectrum(x);
+end
+type = 'mirscalar';
+
+
+function s = main(x,option,postoption)
+if iscell(x)
+    x = x{1};
+end
+y = peaksegments(@skewness,get(x,'Data'),...
+                           get(x,'Pos'),...
+                           get(mircentroid(x),'Data'),...
+                           get(mirspread(x),'Data'));
+if isa(x,'mirspectrum')
+    t = 'Spectral skewness';
+elseif isa(x,'mirenvelope')
+    t = 'Temporal skewness';
+else
+    t = ['Skewness of ',get(x,'Title')];
+end
+s = mirscalar(x,'Data',y,'Title',t,'Unit','');
+
+
+function s = skewness(d,p,c,sp)
+s = sum((p-c).^3.*d) ./ sum(d) ./ sp.^3;
\ No newline at end of file