Home > slowness_model > random_signal.m

random_signal

PURPOSE ^

RANDOM_SIGNAL creates a random signal

SYNOPSIS ^

function x=random_signal(len, n, mn, mx),

DESCRIPTION ^

 RANDOM_SIGNAL creates a random signal

   X=RANDOM_SIGNAL(LEN, N, MN, MX) create a (periodic) random signal X. The
   signal is created by choosing random (uniform distribution) phases and
   amplitudes of the first N Fourier components.

   LEN is the length of X
   N is the number of Fourier component to keep (the speed of the signal
     grows with the squared root of N)
   MN,MX define the minumum and maximum possible value of X

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function x=random_signal(len, n, mn, mx),
0002 % RANDOM_SIGNAL creates a random signal
0003 %
0004 %   X=RANDOM_SIGNAL(LEN, N, MN, MX) create a (periodic) random signal X. The
0005 %   signal is created by choosing random (uniform distribution) phases and
0006 %   amplitudes of the first N Fourier components.
0007 %
0008 %   LEN is the length of X
0009 %   N is the number of Fourier component to keep (the speed of the signal
0010 %     grows with the squared root of N)
0011 %   MN,MX define the minumum and maximum possible value of X
0012 
0013   x=zeros(1,len);
0014   % phases
0015   phi = rand(n,1)*2*pi;
0016   % amplitudes
0017   a = rand(n,1);
0018   
0019   % compute the new signal
0020   for k=1:n,
0021     t=(1:len)/len*2*pi*(k-1);
0022     x=x+a(k)*sin(t+phi(k));
0023   end
0024   % mean zero
0025   x=x/n/2+0.5;
0026   
0027   % rescale such that it lies between mn and mx
0028   x=x.*(mx-mn)+mn;
0029

Generated on Thu 24-Mar-2005 09:54:48 by m2html © 2003