From help-octave-request at bevo dot che dot wisc dot edu Sat Dec 27 15:21:33 2003 Subject: Re: Syntax befuddlement From: Joe Koski To: "Henry F. Mollet" , Octave_post Date: Sat, 27 Dec 2003 14:20:55 -0700 Henry, Duh! Why didn't I think of that! Thanks for the suggestion. I should have done your experiment myself, first. When I try it I get: octave:1> x=rand(1,8) x = 0.59183 0.29134 0.73197 0.63839 0.13084 0.81752 0.33805 0.69539 octave:2> t=[0.002:0.001:0.007] t = 0.0020000 0.0030000 0.0040000 0.0050000 0.0060000 0.0070000 octave:3> fnormhat=0.5*(angle(-x(t+1).*conj(x(t-1)))+pi)/(2*pi) error: invalid vector index = -1 error: evaluating argument list element number 1 error: evaluating binary operator `.*' near line 3, column 28 error: evaluating argument list element number 1 error: evaluating binary operator `+' near line 3, column 43 error: evaluating binary operator `*' near line 3, column 13 error: evaluating binary operator `/' near line 3, column 47 error: evaluating assignment expression near line 3, column 9 Which is a duplicate of the errors that I get from within the routine. When I make t an integer I get your result. octave:6> t=[2:7] t = 2 3 4 5 6 7 octave:7> fnormhat=0.5*(angle(-x(t+1).*conj(x(t-1)))+pi)/(2*pi) fnormhat = 0.50000 0.50000 0.50000 0.50000 0.50000 0.50000 I'm not sure that the 0.5 is the correct answer, either. I know how to calculate frequency (it's the difference of successive phase angles in radians divided by something like 2*pi*dt). I can look at other similar routines for guidance. I just thought that maybe they had an elegant, quick method for doing it, that I didn't understand. Everywhere else in those MatLab routines, t is a real, not an integer. More experiments are in order. Thanks for the suggestion. Joe Koski on 12/27/03 12:55 PM, Henry F. Mollet at mollet at pacbell dot net wrote: > Thanks for earlier expose on octave for Mac/Fink/DarvinPort. > > I've checked below statement with a simple-minded test using a real x and t > and it worked but it may not be a meaningful test: > octave:1> x=rand (1,10) > x = > Columns 1 through 7: > 0.925892 0.410042 0.170498 0.240161 0.811388 0.024802 0.997211 > Columns 8 through 10: > 0.773300 0.687108 0.668670 > octave:2> t = [2:9] > t = > 2 3 4 5 6 7 8 9 > octave:4> fnormhat=0.5*(angle(-x(t+1).*conj(x(t-1)))+pi)/(2*pi) > fnormhat = > 0.50000 0.50000 0.50000 0.50000 0.50000 0.50000 0.50000 0.50000 > Henry > > on 12/26/03 8:14 PM, Joe Koski at jkoski11 at comcast dot net wrote: > >> I'm trying to use a MatLab routine that I found on the net for calculating >> instantaneous local frequency after a Hilbert transform. The hilbert.m >> routine (called from octave-forge) completes successfully. The amplitude of >> the signal is correctly calculated from the results. In attempting to >> calculate frequency and convert the remainder of the MatLab routine to >> octave, I get errors during execution terminating with: >> >> error: invalid vector index = -1 >> >> The statement that is being evaluated at the time of the error is >> >> fnormhat=0.5*(angle(-x(t+1).*conj(x(t-1)))+pi)/(2*pi); >> >> where x is a real column vector (representing data) of length 256, and t is >> a real row vector (representing time "instants," but with the first and last >> values truncated) of length 254. >> >> When I try this with the --braindead option, the routine gives no errors, >> but then no results are returned, either. The date on this script is 1994 >> and it's currently posted on the web, so it probably really does work in >> MatLab. >> >> As an old Fortran programmer, the statement syntax seems very strange to me. >> >> My questions: >> >> How can one real array with increments (t+1, t-1) be an index for another >> real array (x)? Or does that indicate a functional relationship? >> >> Is this standard octave? >> >> Are there tricks for getting MatLab scripts like this to execute correctly >> in octave? >> >> Alternatively, are there an equivalent octave-forge routines that would >> avoid the problem? >> >> If it would help, I could include more of the routine. >> >> Thanks. >> >> Joe Koski >> >> >> >> ------------------------------------------------------------- >> Octave is freely available under the terms of the GNU GPL. >> >> Octave's home on the web: http://www.octave.org >> How to fund new projects: http://www.octave.org/funding.html >> Subscription information: http://www.octave.org/archive.html >> ------------------------------------------------------------- > > > > ------------------------------------------------------------- > Octave is freely available under the terms of the GNU GPL. > > Octave's home on the web: http://www.octave.org > How to fund new projects: http://www.octave.org/funding.html > Subscription information: http://www.octave.org/archive.html > ------------------------------------------------------------- > ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------