function f = mfilter( o, s, n, m)
% Generate various kinds of random filters
%
%  Usage:
%   f = mfilter( o, s, n, m);
%
%  Inputs:
%    o: the desired order of the filter
%    s: a string, either 'dense', 'sparse' or 'delay', 
%       describing the type of filter
%    n: required for 'dense' and 'sparse' filters and
%       describes the amount of amplitude slope 
%    m: required for 'sparse', is is the number of taps to use
%
%  Outputs:
%    f: The filter(!), stored in an NxN FIR matrix structure

% Dense filter
if strcmp( s, 'dense')

	% Make exponentially decaying Cauchy noise
	f = (logspace( n, 0, o+1)/(10^n)) .* crand( o+1);

	% Scale it to a (probably) acceptable level
	f = rboost * f/max( abs( f));

% Sparse filter
elseif strcmp( s, 'sparse')

	% Preallocate filter
	f = zeros( o+1, 1);

	% Make a random address index
	i = ceil( rand( m, 1) * (o+1));

	% Assign exponentially decaying Cauchy noise to those addresses
	f(i) = (logspace( n, 0, m)/(10^n)) .* crand( m);

	% Scale it to a (probably) acceptable level
	f = rboost * f/max( abs( f));

% Simple delay filter
elseif strcmp( s, 'delay')

	% Put a random value to a random address
	f = zeros( o+1, 1);
	f( ceil( rand * (o+1))) = rboost;

% Beep! Try again.
else
	error( 'Unknown filter type');
end

% Generate Cauchy-like distribution random numbers
function out = crand( l)

x1 = rand( 1, l);
i = find( x1 == .5);
x1(i) = x1(i) + eps;
x1 = x1 * pi;
out = tan( x1) / 318.3;

% Random number between .5 and 1
function r = rboost

r = .5 + rand/2;
