DFT変換

 投稿者:しばっち  投稿日:2010年10月30日(土)20時10分46秒
  !'DFT変換(テストルーチン)

OPTION BASE 0
LET  N = 8
DIM RR(N, N), II(N, N)
RANDOMIZE
PRINT "初期値"
FOR I = 0 TO N - 1
   FOR J = 0 TO N - 1
      LET  RR(I, J) = INT(RND * 256)
      PRINT RR(I, J);
   NEXT J
   PRINT
NEXT I
PRINT "DFT2D変換"
CALL DFT2D (N, RR, II, 1) !'離散フーリエ2D変換
PRINT "実数部"
FOR I = 0 TO N - 1
   FOR J = 0 TO N - 1
      PRINT RR(I, J);
   NEXT J
   PRINT
NEXT I
PRINT
PRINT "虚数部"
FOR I = 0 TO N - 1
   FOR J = 0 TO N - 1
      PRINT II(I, J);
   NEXT J
   PRINT
NEXT I
PRINT
!'フィルター処理(ここを実行すると元の数列には戻らない)
!'FOR I = 0 TO N - 1
!'   FOR J = 0 TO N - 1
!'      READ M
!'      LET  RR(I, J) = RR(I, J) * M
!'      LET  II(I, J) = II(I, J) * M
!'   NEXT J
!'NEXT I
PRINT "DFT2D逆変換"
CALL DFT2D(N, RR, II, 0) !'離散フーリエ2D逆変換
PRINT "実数部"
FOR I = 0 TO N - 1
   FOR J = 0 TO N - 1
      PRINT RR(I, J);
   NEXT J
   PRINT
NEXT I
PRINT
PRINT "虚数部"
FOR I = 0 TO N - 1
   FOR J = 0 TO N - 1
      PRINT II(I, J);
   NEXT J
   PRINT
NEXT I
PRINT
DATA 1,1,1,0,0,1,1,1  !'LPF(8*8)
DATA 1,1,1,0,0,1,1,1
DATA 1,1,0,0,0,0,1,1
DATA 0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0
DATA 1,1,0,0,0,0,1,1
DATA 1,1,1,0,0,1,1,1
DATA 1,1,1,0,0,1,1,1
END

EXTERNAL  SUB DFT (M, XR(), XI())
OPTION BASE 0
DIM RR(M), II(M)
LET  P = 8 * ATN(1) / M
FOR J = 0 TO M - 1
   FOR I = 0 TO M - 1
      LET  RR(J) = RR(J) + XR(I) * COS(P * J * I) - XI(I) * SIN(P * J * I)
      LET  II(J) = II(J) + XR(I) * SIN(P * J * I) + XI(I) * COS(P * J * I)
   NEXT I
NEXT J
MAT XR=RR
MAT XI=II
END SUB

EXTERNAL  SUB IDFT (M, XR(), XI())
OPTION BASE 0
DIM RR(M), II(M)
LET  P = 8 * ATN(1) / M
FOR J = 0 TO M - 1
   FOR I = 0 TO M - 1
      LET  RR(J) = RR(J) + XR(I) * COS(-P * J * I) - XI(I) * SIN(-P * J * I)
      LET  II(J) = II(J) + XR(I) * SIN(-P * J * I) + XI(I) * COS(-P * J * I)
   NEXT I
NEXT J
FOR I = 0 TO M - 1
   LET  XR(I) = INT(RR(I) / M + .5)
   LET  XI(I) = INT(II(I) / M + .5)
NEXT I
END SUB


EXTERNAL  SUB DFT2D(M, RR(,), II(,), FL)
OPTION BASE 0
DIM XR(M), XI(M)
FOR Y = 0 TO M - 1
   FOR X = 0 TO M - 1
      LET  XR(X) = RR(X, Y)
      LET  XI(X) = II(X, Y)
   NEXT X
   IF FL<>0 THEN CALL DFT (M, XR, XI) ELSE CALL IDFT (M, XR, XI)
   FOR X = 0 TO M - 1
      LET  RR(X, Y) = XR(X)
      LET  II(X, Y) = XI(X)
   NEXT X
NEXT Y
FOR X = 0 TO M - 1
   FOR Y = 0 TO M - 1
      LET  XR(Y) = RR(X, Y)
      LET  XI(Y) = II(X, Y)
   NEXT Y
   IF FL<>0 THEN CALL DFT (M, XR, XI) ELSE CALL IDFT (M, XR, XI)
   FOR Y = 0 TO M - 1
      LET  RR(X, Y) = XR(Y)
      LET  II(X, Y) = XI(Y)
   NEXT Y
NEXT X
END SUB
 

戻る