Home > database >  Generation of a square wave in excel with frequency and voltage as input
Generation of a square wave in excel with frequency and voltage as input

Time:10-24

This is an exercise for electric circuits that I have to for uni and basically I have been given the frequency and the Voltage to generate a square graph. Frequency is 2kHz so the Period(T) is 0.0005s and the Voltage is 5V.

The graph should look like that(i drew that in AutoCad for presentation purposes): enter image description here

Any ideas on how I can draw this in excel?

CodePudding user response:

The chart type is important here. You will accomplish this using the `XY (Scatter) chart type, but by specifically choosing the XY scatter that has linear lines, and also has no markers for data points.

Start with your Data table:

X Y
0 5
0.00025 5
0.00025 -5
0.0005 -5
0.0005 5
0.00075 5
0.00075 -5
0.001 -5
0.001 5
0.00125 5
0.00125 -5

Select the data (exclude the X/Y header row, just the numbers) and go to the Insert menu, and go to the chart section of the ribbon. Click the down arrow next to the scatter chart icon and select the one that has no point markers and does have straight lines. It's the 5th and final option on my version.

Both axis may have the wrong intervals. Click the horizontal axis and change the major units to .00025. Click the vertical axis and change the major units to 5.

CodePudding user response:

You could create two formulas to generate the square wave sequence and then graph them using Scatter Plot.

For time, you can use:

=INT( SEQUENCE( 24 )/ 2 ) / 2 / 2000 * ( 1 - MOD( SEQUENCE( 24,,0 ), 2 )*0.00001 )

where 2000 is the target frequency of 2kHz. (yes, this can be simplified but it is more clear to show it this way.)

This formula generates a series of time values that repeat at each transition time (e.g., 0.00025, 0.0005, 0.00075...). The first repetition will have 0.00001 seconds shaved off it. This forces Excel to graph the transition as a near vertical line whereas if you did not do this you would end up with a sloping (saw tooth) line.

You can put that formula into a column of cells that represents time. Let's say in this case, you put the formula in cell B4 and you put the name of the series ("t") in cell B3.

Now you can create the voltage formula. In cell C4 you can do:

= 5 * ( 1 - 2*( INT( 2*B4#*2000 ) - 2*INT( B4#*2000 ) ) )

again, 2000 is the target frequency; B4# references the entire series of time values. Put the series name "V" in cell C3.

NB: if your question is really "how to create a formula that takes in f, v and t, then this is the answer with the form:

= v * ( 1 - 2 * ( INT( 2 * t * f ) - 2 * INT( t * f ) ) )

These two series can now be graphed as an XY Scatter Plot. Go to Insert and in Charts choose the Scatter with Straight Lines.

enter image description here

Then format to taste.

The output would be something like this: enter image description here

  • Related