Rank: 892 based on 95 downloads (last 30 days) and 5 files submitted
photo

Scott McKinney

E-mail

Personal Profile:
Professional Interests:

 

Watch this Author's files

 

Files Posted by Scott View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
18 Jan 2011 Screenshot Fast root-mean-square (RMS) power Instantaneous root-mean-square (RMS) power via convolution Author: Scott McKinney signal processing, rms power, standard deviation, variance, signal envelope, instantaneous amplitu... 21 0
18 Oct 2010 Screenshot hilbert2 Extract instantaneous envelope and frequency from a bandlimited signal via Hilbert transform. Author: Scott McKinney bandlimited, instantaneous frequen..., analytic signal, envelope, instantaneous envelop..., hilbert transform 35 0
17 Oct 2010 Screenshot mapcolors Create a custom RGB colormap by interpolating between two pre-defined extremes. Author: Scott McKinney graphics, visualization, colormap, rgb, plotting, 3d 2 0
17 Oct 2010 Screenshot derivative Compute derivative while preserving dimensions Author: Scott McKinney signal processing, mathematics, derivative, finite difference, calculus 31 2
  • 5.0
5.0 | 2 ratings
30 Sep 2010 z2p Converts z-statistic to p-value by integrating the standard normal pdf Author: Scott McKinney statistics, normal distribution, hypothesis testing, z statistic, p value 6 0
Comments and Ratings by Scott
Updated File Comments Rating
06 Oct 2010 marginhist.m 2D scatterplot w/marginal histograms. Author: Peter Perkins

This function is quite good. However, for aesthetics, it would be nice to have that supporting line on the x-axis histogram as well as on the y-axis histogram.

This can be achieved by replacing
 subplot(2,2,4); bar(cx,-nx,1); h2 = gca; axis([xlim -max(nx)*1.01 0]); axis('off');

with

subplot(2,2,4); bar(cx,-nx,1); line(xlims,[0 0],'Color','k'); h2 = gca; axis([xlim -max(nx)*1.01 0.01]); axis('off');

Comments and Ratings on Scott's Files View all
Updated File Comment by Comments Rating
22 Oct 2010 derivative Compute derivative while preserving dimensions Author: Scott McKinney Michael

Thanks for the submission. I had a different way to do this... maybe it will help? If not, no problem. Feel free to incorporate any of my code if you like.

Here is mine (only works on vectors):

function dy = diff2(y)
% DIFF2 computes the first derivative while preserving the number of
% elements. dx is considered to be 1. So, divide this result by your grid
% spacing to get the correct value of the derivative.
%
% DIFF2(y) returns the central difference of y. y is a vector of at least
% three elements.
%
% This scheme is second-order accurate (central differences).
%
% EXAMPLE:
% dx = 0.001; x = 0:dx:2*pi;
% y = sin(x); dydx = diff2(y)/dx;
% plot(x,y,x,dydx);
%
% Created by Mike Hanchak, October 2010
%
% See also DIFF

% Check inputs.
[m,n] = size(y);
if m*n < 3 || m*n > max([m,n]) || nargin ~= 1
    error('Input must be a vector of at least three elements.')
end

% Force data into a row vector.
y = y(:)';

% Calculate central difference for interior terms.
temp = (y(3:end)-y(1:end-2))/2;

% Concatenate derivatives at endpoints using second order forward and
% backward differences.
dy = [ (-3*y(1)+4*y(2)-y(3))/2, temp, (3*y(end)-4*y(end-1)+y(end-2))/2];

% Reshape to match input
if m > n
    dy = dy';
end

06 Oct 2010 derivative Compute derivative while preserving dimensions Author: Scott McKinney Simon, Jan

Thanks! Matlab's GRADIENT is useful for vectors, but cannot process an array just in a specific dimension - unfortunately! In my opinion, this is a design error.

H1 Line, descriptive help, some comments in the source are existing. It would be useful to include the author, date of creation and an example in the help section. Mentioning GRADIENT as "See also" and describing the differences could be helpful. Check of inputs, look for the 1st non-singelton dim as usual in Matlab.

You can increase the speed remarkably, e.g. 65% faster for a [100x100] matrix:
Replace: dx = mean(cat(3, first, last), 3)
with: dx = (first + last) * 0.5
Then your idea to let DIFF do the work is very efficient: Using something like this:
  dx = [x(2, :), - X(1, :); ...
      (X(3:end, :) - X(1:end-2, :)) * 0.5; ...
      X(end, :) - X(end - 1, :)]
needs 50% more time than the improved version!

The VARARGIN method wastes time compared to simply using 3 inputs and checking with NARGIN. But this is measurable for small x only, e.g. 10% more speed for [100 x 1] vector.

Can you expand this function to N-dim arrays? At least 3D should be straight, for more dims a PERMUTE could bring the dimensions to operate on to the front.

Summary: Useful, usable, efficient (with the small update - I hope it will be included!) - thanks.

04 Oct 2010 derivative Compute derivative while preserving dimensions Author: Scott McKinney Reddy, Krishna
Top Tags Applied by Scott
signal processing, instantaneous amplitude, 3d, analytic signal, bandlimited
Files Tagged by Scott View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
18 Jan 2011 Screenshot Fast root-mean-square (RMS) power Instantaneous root-mean-square (RMS) power via convolution Author: Scott McKinney signal processing, rms power, standard deviation, variance, signal envelope, instantaneous amplitu... 21 0
18 Oct 2010 Screenshot hilbert2 Extract instantaneous envelope and frequency from a bandlimited signal via Hilbert transform. Author: Scott McKinney bandlimited, instantaneous frequen..., analytic signal, envelope, instantaneous envelop..., hilbert transform 35 0
17 Oct 2010 Screenshot mapcolors Create a custom RGB colormap by interpolating between two pre-defined extremes. Author: Scott McKinney graphics, visualization, colormap, rgb, plotting, 3d 2 0
17 Oct 2010 Screenshot derivative Compute derivative while preserving dimensions Author: Scott McKinney signal processing, mathematics, derivative, finite difference, calculus 31 2
  • 5.0
5.0 | 2 ratings
30 Sep 2010 z2p Converts z-statistic to p-value by integrating the standard normal pdf Author: Scott McKinney statistics, normal distribution, hypothesis testing, z statistic, p value 6 0

Contact us at files@mathworks.com