?
Solved

Urgent - Implementing equations to that show interactions between electromagnetic waves

Posted on 2003-03-25
12
Medium Priority
?
288 Views
Last Modified: 2010-04-07
I have recently got code that shows me how to show a 70mm length of a 8 - 12 Ghz wave. This works extrmely well in my project. I now have to use a couple of equations that allow me to change the frequency of the wave.

If I start with an 8Ghz wave the wavelength is given by this equation;

   wavelenth = 3 * 10^8 / frequency

This frequency is changed between 8 and 12 GHz using a scroll bar. However when this wave enters a waveguide the frequency changes. This following equation governs how the wave changes;

   new wavelength in waveguide = original wavelenth / sqrt ( 1 - [( original wavelength / 0.04572)^2]

i then need to use other equations to show how when this wave is reflected back onto itself a standing wave is produced (a wave that appears to be stationary).

These equations I can provide if you feel you may be able to assist me in this department, but any help in just implementing the above equation will be much appreciated.

Thanks.
Nick
0
Comment
Question by:nickclaridge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 2

Expert Comment

by:Jzaltheral
ID: 8203847
So are you just looking for the code that will take whatever the frequency is and calculate the wavelength and the wavelength in the waveguide?

Jzal
0
 

Author Comment

by:nickclaridge
ID: 8204021
Yeah essentially thats right. I have code to show the 8 - 12Ghz wave in a picture box. I can show you this if needed. but i will need to show the waveguide wavelength in the picture box. But if you can show me how the equation above can be implemented that'll be great
0
 
LVL 2

Expert Comment

by:Jzaltheral
ID: 8204307
To make everything more modular I would use two functions and put them in a code module in the application.

Public Function ComputeWavelength (dblFrequency as Double) as Double

   ComputeWaveLength = 3 * 10^8 / dblFrequency

End Function

Public Function ComputeWaveGuideWavelength (dblFrequency as Double) as Double

   Dim dblOrigWaveLength as Double

   dblOrigWaveLength = ComputeWaveLength(dblFrequency)

   ComputeWaveGuideWavelength = dblOrigWaveLength / sqr ( 1 - (( dblOrigWaveLength / 0.04572)^2))

End Function

You could then call them by passing in just the frequency - something like...

      currentlength = ComputeWaveLength (frequncy)

or

      waveguidewavelength = ComputeWaveGuideWavelength(frequency)


Also - I'm not sure if SQR is the squareroot function for VB - i could be thinking VBA there and I'm not somewhere where I can check that, so you may want to check the VB Help File to make sure of the name of the function.

Jzal
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:nickclaridge
ID: 8204557
Thanks for that. Thats very helpful. Could you tell what you mean by passing in just the frequency? sorry i'm new to programming and Visual Basic. Sorry I am going to give you the points no matter what but if I show you this code quickly would you be able to tell me where i would make the modifications to display the waveguide wavelength.

Option Explicit

Private Wavelength As Double
Private GunDiodeFrequency As Double
Const GHZFactor As Integer = 100
Const AMPLITUDE As Single = 1.5
Const WIDTHmm As Double = 70        'mm wide window
Const PI As Single = 3.14159

Private Sub Form_Load()
  Me.Show
  Me.PicWave.AutoRedraw = True  
  Me.scrGunDiode.Enabled = False
  Me.scrGunDiode.Min = 8 * GHZFactor
  Me.scrGunDiode.Max = 12 * GHZFactor
  Me.PicWave.Scale (0, AMPLITUDE * 1.1)-(WIDTHmm, -AMPLITUDE * 1.1)
  Me.scrGunDiode.Value = 10 * GHZFactor
  Me.scrGunDiode.LargeChange = GHZFactor / 2
  Me.scrGunDiode.Enabled = True
End Sub

Private Sub DrawWave()
  Me.PicWave.Cls
  ' number of sine waves per box = 70mm/wavelength(mm), ie 2.33 for 10ghz
  Dim NumWaves As Single
  Dim Wavelength As Double
  Dim GHZFreq As Double
  Dim x As Single
  Dim y As Double
  Dim Freq As Single
  GHZFreq = scrGunDiode.Value / GHZFactor
  Wavelength = 300 / GHZFreq
  NumWaves = WIDTHmm / Wavelength
  For x = 0 To WIDTHmm Step 0.1
     y = Sin(x * NumWaves * (360 / WIDTHmm) * PI / 180) * AMPLITUDE
     Me.PicWAve.PSet (x, y), vbRed
  Next x
  Me.Label1 = CStr(Val(scrGunDiode.Value / GHZFactor)) & " GHz"
End Sub

Private Sub scrGunDiode_Change()
  DrawWave
End Sub

Private Sub scrGunDiode_Scroll()
  DrawWave
End Sub
0
 
LVL 2

Accepted Solution

by:
Jzaltheral earned 800 total points
ID: 8204678
What I mean by passing in the frequency is when you call one of the functions, you only have to pass it the frequency (as a double)

In other words - you would pass it the frequency value of the wave you're working with so that it can computer the wavelength

For example

Let's say you store your frequency values in a control called FreqControl.

When you call the function to compute the wavelength you would do this.

 wavelength = ComputeWavelength(FreqControl)

This passes the value of FreqControl to the function that computes the wavelength.

As for displaying the waveguide wave, I would think you could just dupe your DrawWave function, changing it to use the waveguide wavelength instead of the original wavelength, but honestly, that's just a guess.
0
 

Author Comment

by:nickclaridge
ID: 8204731
Thanks for that. Thats been really helpful.
0
 
LVL 2

Expert Comment

by:Jzaltheral
ID: 8204748
You're very welcome.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8206562
'FORM CODE
'---------


Option Explicit

Private Sub Form_Load()
   Me.Show
   Me.SourceWavePB.AutoRedraw = True
   Me.OutputWavePB.AutoRedraw = True
   Me.scrGunDiode.Enabled = False
   Me.scrGunDiode.Min = LowEndGHZ * GHZFactor
   Me.scrGunDiode.Max = HighEndGHZ * GHZFactor
   Me.SourceWavePB.Scale (0, MaxAmplitude * 1.1)-(WIDTHmm, -MaxAmplitude * 1.1)
   Me.OutputWavePB.Scale (0, MaxAmplitude * 1.1)-(WIDTHmm, -MaxAmplitude * 1.1)
   Me.scrGunDiode.LargeChange = GHZFactor / 2
   Me.scrGunDiode.Enabled = True
   SetInitialWave
   Me.scrGunDiode.Value = 10 * GHZFactor 'start with 10GHz
   DoEvents
End Sub

Private Sub scrGunDiode_Change()
   ProcessFreq
End Sub

Private Sub scrGunDiode_Scroll()
   ProcessFreq
End Sub



--------------
MODULE CODE
--------------
Option Explicit
Public Const GHZFactor As Integer = 100
Public Const MaxAmplitude As Single = 1.5
Public Const WIDTHmm As Double = 70        'mm wide window
Public Const PI As Single = 3.14159
Public Const LowEndGHZ As Integer = 8
Public Const HighEndGHZ As Integer = 12

Public Type Wavetype
   Amplitude As Single
   Phase As Single
   wavelength As Single
End Type

Private SourceWave As Wavetype
Private OutputWave As Wavetype

Private Sub PlotWave(Wave2Plot As Wavetype, PlotPic As PictureBox)
   Dim x As Single
   Dim y As Double
   Dim WAmp As Single
   Dim NumWaves As Single
   Dim WPhase As Single
   PlotPic.Cls
   NumWaves = WIDTHmm / Wave2Plot.wavelength
   WAmp = Wave2Plot.Amplitude
   WPhase = Wave2Plot.Phase
   For x = 0 To WIDTHmm Step 0.1
      y = WAmp * Sin((x * NumWaves * (2 * PI / WIDTHmm)) + WPhase) 'put phase shift here
      PlotPic.PSet (x, y), vbRed
   Next
End Sub

Public Sub SetInitialWave()
   SourceWave.Phase = 0
   SourceWave.Amplitude = MaxAmplitude
   OutputWave.Phase = 0
   OutputWave.Amplitude = MaxAmplitude

End Sub

Public Sub ProcessFreq()
   Form1.Label1 = CStr(Val(Form1.scrGunDiode.Value / GHZFactor)) & " GHz"
   SourceWave.wavelength = Freq2Wave(Form1.scrGunDiode / GHZFactor)
   PlotWave SourceWave, Form1.SourceWavePB
   OutputWave.wavelength = ModifyWavelength(SourceWave.wavelength)
   PlotWave OutputWave, Form1.OutputWavePB
End Sub

Private Function ModifyWavelength(ByVal OriWavelen As Single) As Single
   Dim tmpterm As Single
   Dim tmpresult As Single
   tmpterm = (OriWavelen / 1000 / 0.04572) ' correction in equation term?
   tmpresult = Sqr(1 - (tmpterm ^ 2))
   tmpresult = OriWavelen / tmpresult
   ModifyWavelength = tmpresult
End Function

Private Sub ModifySourceWave()
   SourceWave.wavelength = Freq2Wave(scrGunDiode.Value / GHZFactor)
   
End Sub

Private Function Freq2Wave(FreqInGHZ As Single) As Single
   Freq2Wave = 300 / FreqInGHZ
End Function

0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8206647
You will need a second picture box on the form with the same properties as the first one (but not a control array of them).  You'll probably be able to figure out what to name them...

This code outputs both waves simultaneously for you so you can verify what you're looking at.

There is a new data structure WAVETYPE that has the amplitude, wavelength and phase for each structure.

Oh, the phase has to be converted to radians first (90deg=pi/2) if it were used.  For this demo code, the phase and amplitudes are fixed early on, but clearly you can see that those components can change as a result of wave computations...

This is so that you can have multiple waves with their properties encapsulated into one unit each.

The plotting function is nothing really new, except the calling of it:  You pass it the parameters of the wave and the picturebox to draw it in.
This way, you can have a dozen boxes, and a dozen different output waves, and just pass the right wave/display box to the function.

If you want to make multiple equation modifications to your input wave (maybe view different stages of a modification?), you would just define a new variable of type WAVETYPE and set the wavelength, amplitude and phase values for it, and pass that into whatever box you want to draw it in.

Hopefully its not too confusing - I extrapolated from your path you were leading down to include future modifiable material, if you want to go that way.  If its all done and complete as you wanted, congrats.
0
 

Author Comment

by:nickclaridge
ID: 8206728
Hi again....It may take me some time to figure out exactly what you mean (sorry, like I said I'm not a programmer), but I'm sure its probably what I need.

What your saying is that I'll have two picture boxes...one with the original wave and one with the modified wave.

Should I remove all the code from the form module that you gave me yesterday? Or is this an addition? In specific how would I implement the equation in the other question I posted to create a wave diagram in my second picture box.

Thanks, Nick
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8206919
Start a new project for this new code.
Paste the form code into the form, the module code into a new module.

Stick two picture boxes on the form, a scrollbar and a lable, and name them appropriately.

It would take a bit of work to modify the previous program, but less work for you to impliment changes into this new one I hope.  Starting as a clean new project you won't be chasing down compile errors all night


And thanks again for the points.
0
 

Author Comment

by:nickclaridge
ID: 8207302
Hi again its called a 'run-time error 5' in the ModifyWavelength function at the line

tmpresult = Sqr(1 - (tmpterm ^ 2))

Why is this?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question