|
!'HADAMARD変換(テストルーチン)
RANDOMIZE
INPUT PROMPT "MATRIX 2*2(2) 4*4(4) 8*8(8) ": N
DIM X(N, N)
PRINT "初期値"
FOR I = 1 TO N
FOR J = 1 TO N
LET X(I, J) = INT(RND * 256)
PRINT USING "####":X(I, J);
NEXT J
PRINT
NEXT I
PRINT
PRINT "アダマール2D変換"
CALL HADAMARD2D(X, N)
FOR I = 1 TO N
FOR J = 1 TO N
PRINT X(I, J);
NEXT J
PRINT
NEXT I
PRINT
!'フィルター処理(ここを実行すると元の数列には戻らない)
!'FOR I = 1 TO 8
!' FOR J = 1 TO 8
!' READ V
!' LET X(I, J) = X(I, J) * V
!' NEXT J
!'NEXT I
DATA 1,0,1,0,1,0,1,0 !'LPF(8*8)
DATA 0,0,0,0,0,0,0,0
DATA 1,0,1,0,1,0,1,0
DATA 0,0,0,0,0,0,0,0
DATA 1,0,1,0,1,0,1,0
DATA 0,0,0,0,0,0,0,0
DATA 1,0,1,0,1,0,1,0
DATA 0,0,0,0,0,0,0,0
CALL HADAMARD2D(X, N)
PRINT "アダマール2D逆変換"
FOR I = 1 TO N
FOR J = 1 TO N
PRINT USING "####":INT(X(I, J) + .5);
NEXT J
PRINT
NEXT I
END
EXTERNAL SUB HADAMARD (X(), N, L())
DIM M(N, N)
2 DATA 1,1
DATA 1,-1
4 DATA 1,1,1,1
DATA 1,-1,1,-1
DATA 1,1,-1,-1
DATA 1,-1,-1,1
8 DATA 1,1,1,1,1,1,1,1
DATA 1,-1,1,-1,1,-1,1,-1
DATA 1,1,-1,-1,1,1,-1,-1
DATA 1,-1,-1,1,1,-1,-1,1
DATA 1,1,1,1,-1,-1,-1,-1
DATA 1,-1,1,-1,-1,1,-1,1
DATA 1,1,-1,-1,-1,-1,1,1
DATA 1,-1,-1,1,-1,1,1,-1
SELECT CASE N
CASE 2
RESTORE 2
FOR I = 1 TO N
FOR J = 1 TO N
READ M(I, J)
LET M(I, J) = M(I, J) / SQR(2)
NEXT J
NEXT I
CASE 4
RESTORE 4
FOR I = 1 TO N
FOR J = 1 TO N
READ M(I, J)
LET M(I, J) = M(I, J) / 2
NEXT J
NEXT I
CASE 8
RESTORE 8
FOR I = 1 TO N
FOR J = 1 TO N
READ M(I, J)
LET M(I, J) = M(I, J) / SQR(8)
NEXT J
NEXT I
END SELECT
CALL MUL (X, M, L, N)
END SUB
EXTERNAL SUB HADAMARD2D(S(,), N)
DIM X(N), Y(N)
FOR J = 1 TO N
FOR I = 1 TO N
LET X(I) = S(I, J)
NEXT I
CALL HADAMARD (X, N, Y)
FOR I = 1 TO N
LET S(I, J) = Y(I)
NEXT I
NEXT J
FOR J = 1 TO N
FOR I = 1 TO N
LET X(I) = S(J, I)
NEXT I
CALL HADAMARD (X, N, Y)
FOR I = 1 TO N
LET S(J, I) = Y(I)
NEXT I
NEXT J
END SUB
EXTERNAL SUB MUL (A(), B(,), C(), N)
FOR I = 1 TO N
LET S = 0
FOR K = 1 TO N
LET S = S + A(K) * B(K, I)
NEXT K
LET C(I) = S
NEXT I
END SUB
|
|