Home > atmlab > randomize > iaaft > iaaft_loop_1d.m

iaaft_loop_1d

PURPOSE ^

INPUT:

SYNOPSIS ^

function [y, errorAmplitude, errorSpec] = iaaft_loop_1d(fourierCoeff, sortedValues)

DESCRIPTION ^

 INPUT: 
 fourierCoeff:   The 1 dimensional Fourier coefficients that describe the
                 structure and implicitely pass the size of the matrix
 sortedValues:   A vector with all the wanted amplitudes (e.g. LWC of LWP
                 values) sorted in acending order.
 OUTPUT:
 y:              The 1D IAAFT surrogate time series
 errorAmplitude: The amount of addaption that was made in the last
                 amplitude addaption relative to the total standard deviation.
 errorSpec:      The amont of addaption that was made in the last fourier
                 coefficient addaption relative to the total standard deviation

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

iaaft_loop_1d.m

SOURCE CODE ^

0001 function [y, errorAmplitude, errorSpec] = iaaft_loop_1d(fourierCoeff, sortedValues)
0002 % INPUT:
0003 % fourierCoeff:   The 1 dimensional Fourier coefficients that describe the
0004 %                 structure and implicitely pass the size of the matrix
0005 % sortedValues:   A vector with all the wanted amplitudes (e.g. LWC of LWP
0006 %                 values) sorted in acending order.
0007 % OUTPUT:
0008 % y:              The 1D IAAFT surrogate time series
0009 % errorAmplitude: The amount of addaption that was made in the last
0010 %                 amplitude addaption relative to the total standard deviation.
0011 % errorSpec:      The amont of addaption that was made in the last fourier
0012 %                 coefficient addaption relative to the total standard deviation
0013 
0014 % Settings
0015 errorThresshold = 2e-4; %
0016 timeThresshold  = Inf;  % Time in seconds or Inf to remove this condition
0017 speedThresshold = 1e-5; % Minimal convergence speed in the maximum error.
0018 verbose = 1;
0019 makePlots = 0; % Best used together with debugging.
0020 
0021 % Initialse function
0022 noValues = size(fourierCoeff);
0023 errorAmplitude = 1;
0024 errorSpec = 1;
0025 oldTotalError = 100;
0026 speed = 1;
0027 standardDeviation = std(sortedValues);
0028 t = cputime;
0029 
0030 % The method starts with a randomized uncorrelated time series y with the pdf of
0031 % sorted_values
0032 [dummy,index]=sort(rand(size(sortedValues)));
0033 y(index) = sortedValues;
0034 
0035 % Main intative loop
0036 while ( (errorAmplitude > errorThresshold | errorSpec > errorThresshold) & (cputime-t < timeThresshold) & (speed > speedThresshold) )
0037     % addapt the power spectrum
0038     oldSurrogate = y;    
0039     x=ifft(y);
0040     phase = angle(x);
0041     x = fourierCoeff .* exp(i*phase);
0042     y = fft(x);
0043     difference=mean(mean(abs(real(y)-real(oldSurrogate))));
0044     errorSpec = difference/standardDeviation;
0045     if ( verbose ), errorSpec, end
0046     
0047     if (makePlots)
0048         plot(real(y))
0049         title('Surrogate after spectal adaptation')
0050         axis tight
0051         pause(0.01)
0052     end
0053         
0054     % addept the amplitude distribution
0055     oldSurrogate = y;
0056     [dummy,index]=sort(real(y));
0057     y(index)=sortedValues;
0058     difference=mean(mean(abs(real(y)-real(oldSurrogate))));
0059     errorAmplitude = difference/standardDeviation;
0060     if ( verbose ), errorAmplitude, end
0061     
0062     if (makePlots)
0063         plot(real(y))
0064         title('Surrogate after amplitude adaptation')
0065         axis tight
0066         pause(0.01)
0067     end
0068     totalError = errorSpec + errorAmplitude;
0069     speed = (oldTotalError - totalError) / totalError;
0070     if ( verbose ), totalError, speed, end
0071     oldTotalError = totalError;
0072 end
0073 
0074 errorSpec
0075 errorAmplitude
0076 y = real(y);

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005