波形表示

 投稿者:しばっち  投稿日:2011年11月13日(日)19時59分28秒
  サンプル波形の表示

!'XSIZE/(SAMPLING/FREQ)=表示周期(3周期)
LET XSIZE=600
CALL GINIT(XSIZE,400)
SET WINDOW  0 , XSIZE-1 , -1.5,1.5
LET SAMPLING=8000 !'サンプリング周波数
LET FREQ=40 !'周波数
SET TEXT FONT "" , 18
FOR MODE=1 TO 7
   FOR I=1 TO XSIZE
      LET X1=FREQ*(I-1)/SAMPLING*2*PI
      LET X2=FREQ*I/SAMPLING*2*PI
      LET Y1=SIN(X1)
      LET Y2=SIN(X2)
      CALL LINE(I-1,Y1,I,Y2,7)
      SELECT CASE MODE
      CASE 1
         PLOT LABEL,AT XSIZE/2,1.3 : "のこぎり波"
         LET Y1=SAW(X1)
         LET Y2=SAW(X2)
         CALL LINE(I-1,Y1,I,Y2,4)
      CASE 2
         PLOT LABEL,AT XSIZE/2,1.3 : "方形波"
         LET Y1=SQUAREW(X1)
         LET Y2=SQUAREW(X2)
         CALL LINE(I-1,Y1,I,Y2,6)
      CASE 3
         PLOT LABEL,AT XSIZE/2,1.3 : "三角波"
         LET Y1=TRIANGLEW(X1)
         LET Y2=TRIANGLEW(X2)
         CALL LINE(I-1,Y1,I,Y2,5)
      CASE 4
         PLOT LABEL,AT XSIZE/2,1.3 : "パルス波"
         LET Y1=PULSEW(X1)
         LET Y2=PULSEW(X2)
         CALL LINE(I-1,Y1,I,Y2,1)
      CASE 5
         PLOT LABEL,AT XSIZE/2,1.3 : "台形波"
         LET Y1=TRAPEZOIDALW(X1)
         LET Y2=TRAPEZOIDALW(X2)
         CALL LINE(I-1,Y1,I,Y2,3)
      CASE 6
         PLOT LABEL,AT XSIZE/2,1.3 : "階段状"
         LET Y1=STEPWISE(X1,4)
         LET Y2=STEPWISE(X2,4)
         CALL LINE(I-1,Y1,I,Y2,2)
      CASE 7
         PLOT LABEL,AT XSIZE/2,1.3 : "ワイヤストラス"
         LET Y1=WEIERSTRASS(X1,15)
         LET Y2=WEIERSTRASS(X2,15)
         CALL LINE(I-1,Y1,I,Y2,8)
      END SELECT
   NEXT I
   WAIT DELAY 3 !'表示時間(秒)
   CLEAR
NEXT MODE
END

EXTERNAL  FUNCTION PULSEW(X) !'パルス波 PULSE WAVE
IF ABS(ABS(SIN(X))-1)<.000001 THEN LET PULSEW=SGN(SIN(X)) ELSE LET PULSEW=0
END FUNCTION

EXTERNAL  FUNCTION SQUAREW(X) !'方形波 SQUARE WAVE
LET SQUAREW=SGN(SIN(X))
END FUNCTION

!'EXTERNAL  FUNCTION SQUAREW(X,N)
!'FOR I=1 TO N
!'   LET S=S+SIN((2*I-1)*X)/(2*I-1)
!'NEXT I
!'LET SQUAREW=S*4/PI
!'END FUNCTION

EXTERNAL  FUNCTION TRIANGLEW(X) !'三角波 TRIANGLE WAVE
LET NN=MOD(X,PI)
IF NN>PI/2 THEN LET NN=PI-NN
LET TRIANGLEW=NN/(PI/2)*SGN(SIN(X))
END FUNCTION

!'EXTERNAL  FUNCTION TRIANGLEW(X,N)
!'FOR I=1 TO N
!'   LET S=S+SIN(I*PI/2)*SIN(I*X)/I/I
!'NEXT I
!'LET TRIANGLEW=S*8/PI/PI
!'END FUNCTION

EXTERNAL  FUNCTION SAW(X) !'のこぎり波
LET  SAW=MOD(X,PI)/(PI/2)-1
END FUNCTION

!'EXTERNAL  FUNCTION SAW(X,N)
!'FOR I=1 TO N
!'   LET S=S+SIN(I*X)/I
!'NEXT I
!'LET  SAW=S/(PI/2)
!'END FUNCTION

EXTERNAL  FUNCTION TRAPEZOIDALW(X) !'台形波 TRAPEZOIDAL WAVE
LET  NN=X-INT(X/PI)*PI
IF NN>PI/2 THEN LET  NN=PI-NN
LET  TRAPEZOIDALW=MIN(1,MAX(-1,NN*SGN(SIN(X))) )
END FUNCTION

!'EXTERNAL  FUNCTION TRAPEZOIDALW(X,N)
!'LET ALPHA=1
!'FOR I=1 TO N
!'   LET S=S+SIN((2*I-1)*ALPHA)/(2*I-1)^2*SIN((2*I-1)*X)
!'NEXT I
!'LET TRAPEZOIDALW=S*4/(ALPHA*PI)
!'END FUNCTION

EXTERNAL  FUNCTION STEPWISE(X,NN) !'階段状
LET STEPWISE=INT(NN*SIN(X))/NN
END FUNCTION

EXTERNAL  FUNCTION WEIERSTRASS(X,N) !'ワイヤストラス
LET B=11
FOR I=0 TO N
   LET S=S+.5^(I+1)*SIN(B^I*X)
NEXT I
LET WEIERSTRASS=S
END FUNCTION

EXTERNAL  SUB GINIT(XSIZE,YSIZE)
SET BITMAP SIZE XSIZE,YSIZE
SET POINT STYLE  1
SET COLOR MODE "REGULAR"
SET COLOR MIX(0) 0,0,0
SET COLOR MIX(1) 0,0,1
SET COLOR MIX(2) 1,0,0
SET COLOR MIX(3) 1,0,1
SET COLOR MIX(4) 0,1,0
SET COLOR MIX(5) 0,1,1
SET COLOR MIX(6) 1,1,0
SET COLOR MIX(7) 1,1,1
CLEAR
END SUB

EXTERNAL  SUB LINE(XS,YS,XE,YE,C)
SET COLOR C
PLOT LINES
PLOT LINES: XS,YS;XE,YE
END SUB
 

戻る