MATLAB Answers

Ted oscar

fortran to matlab?

Asked by Ted oscar
on 28 Dec 2011
C  SUBROUTINE:  LREMV
C THIS SUBROUTINE CAN REMOVE THE DC COMPONENT AND SLOPE OF AN ARRAY OF C DATA IF DESIRED
C------------------------------------------------------------------
      SUBROUTINE LREMV (XX, NNN, ISWCH, DC, SLOPE)
C
C INPUT:  XX = INPUT DATA ARRAY
C         NNN = NUMBER OF POINTS IN DATA ARRAY
C         ISWCH = 0 DO NOT REMOVE DC COMPONENT OR SLOPE
C               = 1 REMOVE THE DC COMPONENT
C               > 1 REMOVE THE DC COMPONENT AND SLOPE
C OUTPUT: DC = DC COMPONENT OF DATA
C         SLOPE = SLOPE OF DATA
C
        IMPLICIT DOUBLE PRECISION (A-H,O-Z)
        DIMENSION XX(16384)
C
C ESTABLISH CONSTANTS
C
      FLN = FLOAT(NNN)
      DC = 0.0
      SLOPE = 0.0
C
      DO 10 I=1,NNN
        DC = DC + XX(I)
        SLOPE = SLOPE + XX(I)*FLOAT(I)
  10  CONTINUE
C
C COMPUTE STATISTICS
C
      DC = DC/FLN
      SLOPE = 12.0*SLOPE/(FLN*(FLN*FLN-1.0)) - 6.0*DC/(FLN-1.0)
C
C DETERMINE KIND OF TREND REMOVAL
C
      IF (ISWCH-1) 60, 40, 20
C
C REMOVE TREND (MEAN AND SLOPE)
C
  20  CONTINUE
      FLN = DC - 0.5*(FLN+1.0)*SLOPE
      DO 30 I=1,NNN
        XX(I) = XX(I) - FLOAT(I)*SLOPE - FLN
  30  CONTINUE
      GO TO 60
C
C REMOVE THE DC COMPONENT
C
  40  CONTINUE
      DO 50 I=1,NNN
        XX(I) = XX(I) - DC
  50  CONTINUE
C
  60  RETURN
      END

  1 Comment

Sebastian Schaefer on 28 Dec 2011

What is your question? Do you want to implement this algorithm with MATLAB code? How far have you got? An alternative would be to compile this code to a Fortran mexfile for MATLAB.

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 28 Dec 2011
 Accepted answer

  7 Comments

Derek O'Connor on 29 Dec 2011

Ah! The good old days, with FORTRAN's computed GO TO. How have we managed to do without it for the last 40 years? I'd love to know when this subroutine was written.

Walter Roberson
on 29 Dec 2011

5-3-84 or earlier according to the source. See pdf page 308 of http://dspace.mit.edu/bitstream/handle/1721.1/33805/15674832.pdf?sequence=1

They were extracted from Programs for Digital Signal Processing, which was published (IEEE Press) 1979, revised 1981, so with the 1984 source date we can safely assume a later revision date for the section, but we cannot tell where in 1979 to 1984 that particular routine was written.

Only 25 to 30 years, Derek ;-)

Besides, it isn't a Computed GOTO, it is an Arithmetic IF
http://www-linac.kek.jp/cont/langinfo/web/Fortran/docs/lrm/lrm0128.htm#arith_if_stmt

Ted oscar
on 29 Dec 2011

actually, i am the fortran and matlab beginner,so i don't understand this programs for what.BTW, thank you for your help


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today