help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

does Octave have spline function? MATLAB does...


From: Terrence Brannon
Subject: does Octave have spline function? MATLAB does...
Date: 13 Jun 1998 12:54:04 -0700

I tried to execute the code below and it failed on this line:

interp = spline(sampleTimes, sample, T1:T2); 

stating:

octave:1> rateMod2
error: `spline' undefined near line 78 column 10
error: evaluating index expression near line 78, column 10
error: evaluating assignment expression near line 78, column 8
error: near line 78 of file `/home/newport/freeway/brannon/rs/rateMod2.m'
error: evaluating expression near line 1, column 1
octave:1> 


========== Begin Attachment
========== File: ~/rs/rateMod2.m
% Master file: Auditory.m

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This file defines a modulation of poisson parameter lambda 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The idea is to fix the rate randomly at some sample points and
% to extrapolate later by splines. 


%Parameters
%%%%%%%%%%

T = 5000; % time in ms
T = 2^floor(log(T)/log(2));
T1 = floor(T/4);   % Beginning of the tone
T2 = floor(3*T/4); % End of the tone
dT = 100; % Time interval of the random sampling points

Ls = floor((T2-T1)/dT)+1; % Number of sampling points

maxFluct = 1; 
maxFreq = 20;
minFreq = .01;

% Initializtion
%%%%%%%%%%%%%%%%
rVect = zeros(1,T); % Vector of the interpolating function
rVectComp = zeros(1,T); % Vector of the interpolating function
sample = zeros(1,Ls); % Vector of the sparse sample points
interp = zeros(T2-T1+1); % Vector of the full number of points
 
% Random sampling
%%%%%%%%%%%%%%%%%%

bd = (maxFreq-minFreq)/2;
sample(1) =0;
sample(Ls)=0;

%Version1: Uniform distribution with memory 0
%for i=2:Ls-1
%  x = rand; x=2*x-1; % random variable between -1..1
%  sample(i) = x * bd;
%end

%Version2: Uniform distribution with memory 1
for i=2:Ls-1
  odd=rem(i,2); % odd=1 if i=odd, else odd=0
  x = 0.5+rand/2; % random variable between .5..1
  x= -1*odd*x; 
  % x between -1/2..0 if i=even and between 0..1/2 if i=odd
  sample(i) = x * bd;
end

%Version3: silent frequency = maximal frequency during the tone
%sample(1) = maxFreq-maxFluct;
%sample(Ls)= maxFreq-maxFluct;
%for i=1:Ls
%  if rem(i,2)==1; 
%    sample(i)=maxFreq - rand*maxFluct;
%  else
%    sample(i) = minFreq + rand * 2*bd;
%  end
%end

% Interpolation
%%%%%%%%%%%%%%%

sampleTimes = T1:dT:T2; 

% Version 3 with variied time intervals:
%--------------------------------------
dtvar = 2*dT; % Total with of the time interval variation
for i=1:Ls
  dev(i)=max(-dT+1,round(dtvar*(rand - .5)));
  sampleTimes(i) = sampleTimes(i) + max(-dT+1,round(dtvar*(rand - .5)));
end

interp = spline(sampleTimes, sample, T1:T2); 
bdV = bd*ones(1,length(interp)); % For Version 1 and 2 above
interp = min(max(-1.1*bdV,interp),1.1*bdV); % For Version 1 and 2 above
%interp = min(max(minFreq,interp),maxFreq+maxFluct); % For Version 3

mn = mean(interp);mn=mn+0*(max(interp)-mn); % For version 1 and 2 above
%mn = maxFreq-maxFluct; % For version 3 above
rVect(1:T1-1) = mn*ones(T1-1,1);
rVect(T1:T2) = interp;
rVect(T2+1:T) = mn*ones(T-T2,1);
rVectComp = rVect;
mnI = mn*ones(1,T2-T1+1);
rVectComp(T1:T2) = mnI - (interp-mnI);

trans = max(abs(min(rVectComp(T1:T2))),abs(min(rVect(T1:T2))));
rVect = rVect + trans + minFreq; % For Version 1 and 2 above
rVectComp = rVectComp + trans + minFreq; % For Version 1 and 2 above



% Calculating the auto correlation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
corrlabel=1;
if corrlabel==1
%acorr = xcorr(rVect(T1:T2)-mean(rVect(T1:T2)), 'unbiased');
acorr = xcorr(rVect(T1:T2), 'unbiased');
end

% Plots
%%%%%%%%

Lr = T2-T1+1; % Length of rVect(T1:T2)
xwindow = Lr; % Time window for showing the auto correlation

plotlabel=1;
if plotlabel==1

figure
subplot(2,1,1)
plot(rVect(T1:T))
hold on
plot(rVectComp(T1:T),'g')
title('Random Walk: mean rate of the poisson spike train')
xlabel('time in ms')
ylabel('mean rate') 
axis([0 T-T1 0 max(max(rVect), max(rVectComp))])
tickloc = get(gca, 'xTick');
ticklabels = str2mat(T1+tickloc);
set(gca,'XTickLabels', ticklabels)
hold off

subplot(2,1,2)
plot(acorr(Lr:Lr+xwindow-1))
hold on; plot([0 xwindow], [0 0], 'c'); hold off
title('Auto correlation of the random walk')
xlabel('time in ms')
axis([0 xwindow 0 max(acorr)])

end

% Rem: Compare /spike/local/matlab/toolbox/signal/xcorr.m





-- 
Terrence Brannon * address@hidden * http://lnc.usc.edu/~brannon
USC, HNB, 3614 Watt Way, Los Angeles, CA 90089-2520 * (213) 740-3397
Vi is a *VI*le, de*VI*lish, de*VI*ce. C-u 5000000 M-x all-hail-emacs



reply via email to

[Prev in Thread] Current Thread [Next in Thread]