VERSION 5.00
Begin VB.Form frmMain 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Modulation"
   ClientHeight    =   5865
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   10320
   Icon            =   "frmMain.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   391
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   688
   StartUpPosition =   1  'CenterOwner
   Begin VB.CommandButton cmdPSK 
      Caption         =   "Phase Shift Keying"
      Height          =   495
      Left            =   5760
      TabIndex        =   10
      Top             =   5280
      Width           =   1335
   End
   Begin VB.CommandButton cmdFreqS 
      Caption         =   "Frequency Shift Keying"
      Height          =   495
      Left            =   4320
      TabIndex        =   9
      Top             =   5280
      Width           =   1335
   End
   Begin VB.CommandButton cmdPulse 
      Caption         =   "Pulse Code Modulation"
      Height          =   495
      Left            =   2880
      TabIndex        =   7
      Top             =   5280
      Width           =   1335
   End
   Begin VB.CommandButton cmdFreq 
      Caption         =   "Frequency Modulation"
      Height          =   495
      Left            =   1440
      TabIndex        =   2
      Top             =   5280
      Width           =   1335
   End
   Begin VB.CommandButton cmdAmp 
      Caption         =   "Amplitude Modulation"
      Height          =   495
      Left            =   120
      TabIndex        =   1
      Top             =   5280
      Width           =   1215
   End
   Begin VB.PictureBox pic 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00000000&
      BeginProperty Font 
         Name            =   "Courier New"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0000FF00&
      Height          =   5160
      Left            =   0
      ScaleHeight     =   340
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   684
      TabIndex        =   0
      Top             =   0
      Width           =   10320
      Begin VB.Label lbCar 
         BackStyle       =   0  'Transparent
         Caption         =   "-"
         ForeColor       =   &H00FF0000&
         Height          =   375
         Left            =   8400
         TabIndex        =   8
         Top             =   4560
         Width           =   1815
      End
      Begin VB.Label derViation 
         BackStyle       =   0  'Transparent
         Caption         =   "-"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   12
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00FF00FF&
         Height          =   1095
         Left            =   0
         TabIndex        =   6
         Top             =   3960
         Width           =   7455
      End
      Begin VB.Label lbOut 
         BackStyle       =   0  'Transparent
         Caption         =   "-"
         ForeColor       =   &H0000FFFF&
         Height          =   375
         Left            =   8400
         TabIndex        =   5
         Top             =   4080
         Width           =   1935
      End
      Begin VB.Label lbIn 
         BackStyle       =   0  'Transparent
         Caption         =   "-"
         ForeColor       =   &H0000FF00&
         Height          =   375
         Left            =   8400
         TabIndex        =   4
         Top             =   3600
         Width           =   1815
      End
      Begin VB.Label lbMatter 
         BackStyle       =   0  'Transparent
         Caption         =   "-"
         ForeColor       =   &H000000FF&
         Height          =   615
         Left            =   0
         TabIndex        =   3
         Top             =   3360
         Width           =   5415
      End
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Const A = 40
Const DegToRad = (22 / 7) / 180

Private Sub cmdAmp_Click()

    Dim X1 As Single, Y1 As Single
    Dim Xa As Single, Ya As Single
    Me.Caption = "Amplitude Modulation"
    Dim i As Single
    pic.Cls
        Ya = A
    For i = 0 To 440 Step 10
        X1 = i
        Y1 = A + A * Sin(DegToRad * i)
        pic.ForeColor = vbGreen
        pic.Line (X1, Y1)-(Xa, Ya)
        Xa = X1
        Ya = Y1
        drawSinAM X1, Y1
        
    Next
    lbIn.Caption = "___  Modulating Signal"
    lbOut.Caption = "___  Modulated Signal"
    lbCar.Caption = ""
    
    lbMatter.Caption = "Amplitude Modulation : Modulation in which the Amplitude of the carrier wave is varied in accordance with the Amplitude of the Modulating signal"
    derViation.Caption = "vm = Vm Sin(Wm*t) -> Modulating Signal" & vbCrLf & _
    "vc = Vc Sin(Wc*t) -> Carrier Signal" & vbCrLf _
    & vbCrLf & " VC = Vm Sin(Wm*t) * Sin(Wc*t) -> Modulated Signal"
    
End Sub
Private Sub drawSinAM(x As Single, amp As Single)
    Dim X2 As Single, Y2 As Single
    Dim Xb As Single, Yb As Single
    
    X2 = x
    Xb = x
    Yb = 2 * A
    Dim i As Single
    pic.ForeColor = vbYellow
    For i = 0 To 360
        X2 = X2 + (10 / 360)
        Y2 = 2 * A + (10 + amp) * Sin(DegToRad * i)
        pic.Line (X2, Y2)-(Xb, Yb)
        Xb = X2
        Yb = Y2
    Next

End Sub
Private Sub cmdFreq_Click()

    Dim X1 As Single, Y1 As Single
    Dim Xa As Single, Ya As Single
    
    pic.Cls
    Me.Caption = "Frequency Modulation"
    Dim i As Single
    
        Ya = A
        
    For i = 0 To 360 Step 10
        
        Y1 = A + A * Sin(DegToRad * i)
        pic.ForeColor = vbGreen
        pic.Line (i, Y1)-(Xa, Ya)
        Xa = i
        Ya = Y1
        
        drawSinFM i, Y1 / A
    Next
    
    lbIn.Caption = "___  Modulating Signal"
    lbOut.Caption = "___  Modulated Signal"
    lbCar.Caption = ""
    lbMatter.Caption = "Frequency Modulation : Modulation in which the Frequency of the carrier wave is varied in accordance with the Amplitude of the Modulating signal"
    derViation.Caption = "vm = Vm Sin(Wm*t) -> Modulating Signal" & vbCrLf & _
    "vc = Vc Sin(Wc*t) -> Carrier Signal" & vbCrLf _
    & vbCrLf & " VC = Vc Sin((Wc+ Alpha* Vm * Sin(Wm*t)) * t) -> Modulated Signal"
    
End Sub

Private Sub drawSinFM(x As Single, freq As Single)
    Dim X2 As Single, Y2 As Single
    Dim Xb As Single, Yb As Single
    Dim i As Single
    Xb = x
    Yb = 2 * A
    X2 = x
    i = 0
    pic.ForeColor = vbYellow
    While ((X2 - x) <= 10)
        
        Y2 = 2 * A + A * Sin((freq + 0.9) * i * DegToRad)
        pic.Line (X2, Y2)-(Xb, Yb)
        Xb = X2
        Yb = Y2
        X2 = X2 + 0.025
        i = i + 1
    Wend
       
End Sub
Private Function Bin(xStr As String) As String
    Dim i As Integer
    Dim strStr As String
    
    
    For i = 1 To Len(xStr)
        Select Case Mid$(xStr, i, 1)
        Case "0"
            strStr = strStr + "0000"
        Case "1"
            strStr = strStr + "0001"
        Case "2"
            strStr = strStr + "0010"
        Case "3"
            strStr = strStr + "0011"
        Case "4"
            strStr = strStr + "0100"
        Case "5"
            strStr = strStr + "0101"
        Case "6"
            strStr = strStr + "0110"
        Case "7"
            strStr = strStr + "0111"
        Case "8"
            strStr = strStr + "1000"
        Case "9"
            strStr = strStr + "1001"
        Case "A"
            strStr = strStr + "1010"
        Case "B"
            strStr = strStr + "1011"
        Case "C"
            strStr = strStr + "1100"
        Case "D"
            strStr = strStr + "1101"
        Case "E"
            strStr = strStr + "1110"
        Case "F"
            strStr = strStr + "1111"
        End Select
        
    Next
    If Len(strStr) < 8 Then strStr = "0000" + strStr
    Bin = strStr
    
End Function

Private Sub cmdPSK_Click()
    Dim X1 As Single, Y1 As Single, Y2 As Single
    Dim Xa As Single, Ya As Single
    
    Dim i As Single, j As Integer
    Dim strStr As String
    pic.Cls
    Me.Caption = "Phase Shift Keying"
    For i = 0 To 360 Step 40
        
        Y1 = 2 * A * ((i / 80) - (i \ 80))
        pic.ForeColor = vbGreen
        pic.CurrentX = i
        pic.CurrentY = 0
        pic.Print 1 - (Y1 \ 40)
        pic.Line (i, Y1)-(i + 40, Y1)
        
        X1 = i
        Ya = 3 * A
        If Y1 = 0 Then
            pic.ForeColor = vbYellow
            For j = 180 To 1260
                X1 = X1 + (40 / 1080)
                Y2 = 3 * A + A * Sin(DegToRad * j)
                pic.Line (X1, Y2)-(Xa, Ya)
                Xa = X1
                Ya = Y2
            Next
        Else
            pic.ForeColor = vbCyan
            For j = 0 To 1080
                X1 = X1 + (40 / 1080)
                Y2 = 3 * A + A * Sin(DegToRad * j)
                pic.Line (X1, Y2)-(Xa, Ya)
                Xa = X1
                Ya = Y2
            Next
        End If
    Next
       
    lbIn.Caption = "___ Modulating Signal"
    lbOut.Caption = "___  Sampled Signal"
    lbCar.Caption = ""
    
    lbMatter.Caption = "Phase Shift Keying : A digital-to-analog modulation technique. Data is transmitted by shifting the phase of the carrier signal in accordance with the binary '1' or '0'"
    derViation.Caption = ""

End Sub

Private Sub cmdPulse_Click()
    Dim X1 As Single, Y1 As Single
    Dim Xa As Single, Ya As Single
    Dim i As Single
    Dim strStr As String
    pic.Cls
    Me.Caption = "Pulse Code Modulation"
    For i = 0 To 360 Step 20
        
        Y1 = 2 * A * ((i / 40) - (i \ 40))
        pic.ForeColor = vbGreen
        pic.Line (i, Y1)-(i + 20, Y1)
        
        Y1 = A + A * Sin(i * DegToRad)
        pic.ForeColor = vbBlue
        pic.Line (X1, Y1)-(Xa, Ya)
        If ((i / 40) - (i \ 40) <> 0) Then
            pic.ForeColor = vbYellow
            pic.Line (X1 + 20, Y1 + 1.5 * A)-(Xa, Y1 + 1.5 * A)
            pic.ForeColor = vbWhite
            pic.Line (Xa, 4.5 * A)-(Xa, 4 * A)
            pic.CurrentX = Xa
            pic.CurrentY = 4 * A
            pic.Print CStr(Hex(CInt(Y1)))
            strStr = strStr + Bin(CStr(Hex(CInt(Y1)))) + " "
            
        End If
        Xa = X1
        Ya = Y1
        X1 = X1 + 20
    Next
    pic.ForeColor = vbYellow
    pic.CurrentX = 0
    pic.CurrentY = 5 * A
    pic.Print strStr
    
    lbIn.Caption = "___  Sampling Signal"
    lbOut.Caption = "___  Sampled Signal"
    lbCar.Caption = "___ Modulating Signal"
    
    lbMatter.Caption = "Pulse Code Modulation : Modulation in which the Modulating Signal is sampled, and the magnitude of the sample is digitized for transmission"
    derViation.Caption = ""
    
End Sub

Private Sub cmdFreqS_Click()
    Dim X1 As Single, Y1 As Single, Y2 As Single
    Dim Xa As Single, Ya As Single
    
    Dim i As Single, j As Integer
    Dim strStr As String
    pic.Cls
    Me.Caption = "Frequency Shift Keying"
    For i = 0 To 360 Step 40
        
        Y1 = 2 * A * ((i / 80) - (i \ 80))
        pic.ForeColor = vbGreen
        pic.CurrentX = i
        pic.CurrentY = 0
        pic.Print 1 - (Y1 \ 40)
        pic.Line (i, Y1)-(i + 40, Y1)
        
        X1 = i
        Ya = 3 * A
        If Y1 = 0 Then
            pic.ForeColor = vbYellow
            For j = 0 To 1800
                X1 = X1 + (40 / 1800)
                Y2 = 3 * A + A * Sin(DegToRad * j)
                pic.Line (X1, Y2)-(Xa, Ya)
                Xa = X1
                Ya = Y2
            Next
        Else
            pic.ForeColor = vbCyan
            For j = 0 To 1080
                X1 = X1 + (40 / 1080)
                Y2 = 3 * A + A * Sin(DegToRad * j)
                pic.Line (X1, Y2)-(Xa, Ya)
                Xa = X1
                Ya = Y2
            Next
        End If
    Next
       
    lbIn.Caption = "___ Modulating Signal"
    lbOut.Caption = "___  Sampled Signal"
    lbCar.Caption = ""
    
    lbMatter.Caption = "Frequency Shift Keying : A digital-to-analog modulation technique. Data is transmitted by shifting between two close frequencies with '1' represented by one frequency and '0' by the other."
    derViation.Caption = ""
    
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim i As Integer
lbIn.Caption = ""
lbOut.Caption = ""
lbCar.Caption = ""
    
lbMatter.Caption = ""
derViation.Caption = ""

For i = 10 To 25
    pic.Cls
    pic.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
    pic.CurrentY = pic.ScaleHeight \ 2
    pic.FontSize = i
    pic.Print "Developer: Pradeep K Rao"
    
    pic.Print "Home Page: www.freewebs.com/pradeepkrao"
    pic.Refresh
    Sleep (200)
Next
End Sub
