## DST変換

投稿者：しばっち  投稿日：2010年10月30日(土)20時12分2秒
 !'DST変換(テストルーチン) DECLARE EXTERNAL  FUNCTION C PUBLIC NUMERIC N LET  N = 8 OPTION BASE 0 DIM X(N), Y(N), S(N, N) RANDOMIZE PRINT "初期値" FOR I = 0 TO N - 1    LET  X(I) = INT(RND * 256)    PRINT USING "####":X(I); NEXT I PRINT CALL DST2(X, N, Y) !'離散SINE変換 PRINT "DST2" FOR I = 0 TO N-1    PRINT Y(I); NEXT I PRINT CALL DST3(Y, N, X) !'離散SINE逆変換 PRINT "DST3" FOR I = 0 TO N-1    PRINT USING "####":X(I); NEXT I PRINT PRINT "初期値" FOR I = 1 TO N - 1    LET  X(I) = INT(RND * 256)    PRINT USING "####":X(I); NEXT I PRINT CALL DST4(X, N, Y) !'DST4変換 PRINT "DST4" FOR I = 1 TO N - 1    PRINT Y(I); NEXT I PRINT CALL DST4(Y, N, X) !'DST4逆変換 PRINT "DST4" FOR I = 1 TO N - 1    PRINT USING "####":INT(X(I) + .5); NEXT I PRINT PRINT "初期値" FOR I = 1 TO N - 1    LET  X(I) = INT(RND * 256)    PRINT USING "####":X(I); NEXT I PRINT CALL DST1(X, N, Y) !'DST1変換 PRINT "DST1" FOR I = 1 TO N - 1    PRINT Y(I); NEXT I PRINT CALL DST1(Y, N, X) !'DST1逆変換 PRINT "DST1" FOR I = 1 TO N - 1    PRINT USING "####":INT(X(I) + .5); NEXT I PRINT PRINT "初期値" FOR I = 1 TO N    FOR J = 1 TO N       LET  S(I, J) = INT(RND * 256)       PRINT USING "####":S(I, J);    NEXT J    PRINT NEXT I PRINT PRINT "２次元ＤＳＴ" CALL DST2D(S, N) FOR I = 1 TO N    FOR J = 1 TO N       PRINT S(I, J);    NEXT J    PRINT NEXT I PRINT PRINT "２次元逆ＤＳＴ" CALL IDST2D(S, N) FOR I = 1 TO N    FOR J = 1 TO N       PRINT USING "####":INT(S(I, J)+.01);    NEXT J    PRINT NEXT I PRINT END EXTERNAL  FUNCTION C (X) IF X = 0 OR X = N THEN LET  C = SQR(.5) ELSE LET  C = 1 END FUNCTION EXTERNAL  SUB DST1 (A(), N, B()) FOR K = 1 TO N - 1    LET  S = 0    FOR I = 1 TO N - 1       LET  S = S + A(I) * SIN(I * K * PI / N)    NEXT I    LET  B(K) = S * SQR(2 / N) NEXT K END SUB EXTERNAL  SUB DST2 (A(), N, B()) FOR K = 1 TO N    LET  S = 0    FOR I = 1 TO N       LET  S = S + A(I) * SIN((2 * I - 1) * K * PI / 2 / N)    NEXT I    LET  B(K) = S * SQR(2 / N) * C(K) NEXT K END SUB EXTERNAL  SUB DST3 (A(), N, B()) FOR K = 1 TO N    LET  S = 0    FOR I = 1 TO N       LET  S = S + C(I) * A(I) * SIN((2 * K - 1) * I * PI / 2 / N)    NEXT I    LET  B(K) = INT(S * SQR(2 / N) + .5) NEXT K END SUB EXTERNAL  SUB DST4 (A(), N, B()) FOR K = 1 TO N    LET  S = 0    FOR I = 1 TO N       LET  S = S + A(I) * SIN((2 * I - 1) * (2 * K - 1) * PI / 4 / N)       LET  B(K) = S * SQR(2 / N)    NEXT I NEXT K END SUB EXTERNAL  SUB DST2D (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 DST2 (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 DST2(X, N, Y)    FOR I = 1 TO N       LET  S(J, I) = Y(I)    NEXT I NEXT J END SUB EXTERNAL  SUB IDST2D (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 DST3 (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 DST3 (X, N, Y)    FOR I = 1 TO N       LET  S(J, I) = Y(I)    NEXT I NEXT J END SUB