harmonics of a square wave in excel, what formula and how

Discussion in 'Homework Help' started by ninjaman, Feb 25, 2015.

  1. ninjaman

    Thread Starter Member

    May 18, 2013

    I have another assignment for my course. I have to use a circuit in multisim to create a square wave
    go to simulate > analysis > fourier and show the harmonics and values

    I cant get this to export to my version of excel at the moment but it puts all the values into a spreadsheet.

    from there I have to create sine waves of the fundamental and odd harmonics to make up a square wave.
    im not sure how to do this.

    I have this formula: Vsin(2(pi)ft) + v/3sin(6(pi)ft) + v/5sin(10(pi)ft) and so on for about ten harmonics.

    im not sure what formula to use. my lecturer was talking about creating each wave form, so the fundamental first, create a bunch of values that will show a sine wave. for this he used "time"

    the frequency of the fundamental is 1kHz. so 1millisecond is the periodic time. so break this 1millisecond into 50 parts(arbitrary number) then use the first formula : Vsin(2(pi)ft) with "t" being each increment. this should create a sine wave. I had a problem with my wave. it looked more wibbly wobbly then supposed to.
    it didn't look sine wave shape. I used Vmag and Time in milliseconds to create the graph.

    not sure what I did wrong here.

    any help would be great

    simon bradley
  2. Kermit2

    AAC Fanatic!

    Feb 5, 2010
  3. Veracohr

    Well-Known Member

    Jan 3, 2011
    Sounds right to me. What does "wibbly wobbly" mean exactly?

    Your time column should increment by .001/50 = .00002.
  4. MrAl

    Distinguished Member

    Jun 17, 2014

    If you want to do a simulation with your chosen sources, all you do is add all the sine sources together. The main amplitude is important so you might want to look closely at that to get a 1v peak square wave.

    For example, if the fundamental is sin(t), then the third harmonic is sin(3*t), and fifth is sin(5*t), but the amplitudes are 1, 1/3, and 1/5 for those three, and if you really want 1v peak then you have to multiply those by 4/pi.

    So you just create three different sine sources, and make the frequency of the second one 3 times the first and 1/3 the amplitude, then the third source make sin(5*t) and the amplitude 1/5 times the first amplitude. The remaining harmonics are all sin(n*t) with amplitude 1/n times the first amplitude.

    To allow for frequency changes, use sin(w*t) and sin(3*w*t) and sin(5*w*t) and keep the amplitudes the same as before. w=2*pi*f.

    The simulation of these kinds of tasks all look like a square wave with imperfections that resemble small wiggles and/or larger wiggles which can be called wobbles. At the ends there is always some overshoot too (see the Gibbs Effect).
  5. ninjaman

    Thread Starter Member

    May 18, 2013
    im struggling to get a square wave. this is the first, third, fifth, seventh, ninth and eleventh upload_2015-3-3_22-33-6.png this is what I got after adding each one =3rd+5th+7th+9th+11th(I put the cell letters/numbers) this next to a column of time

    im using the 1/3 of fundamental, with 3kHz and 6*pi
    1/5 of fundamental, with 5kHz and 10*pi
    1/7 of fundamental, with 7kHz and 14*pi
    1/9 of fundamental, with 9kHz and 18*p1

    is this correct? this is how my tutor showed me.
  6. WBahn


    Mar 31, 2012
    The word description is a bit hard to follow but is generally right. I don't know what "with 5kHz and 10*pi" means.

    I have no idea how you are generating your plot, but it isn't even close. The first six harmonics of the square wave look like this:


    Set up your columns as follows:

    Column A: time
    Column B: sum of harmonics
    Column C: fundamental (i.e., first harmonic)
    Column D: third harmonic.
    Column H: eleventh harmonic.

    In Row 1 put:
    Column A: 0.01 // This is the time increment
    Column B: =4/pi() // This is the overall scaling factor
    Column C: 1 // This is the harmonic number, which we will take to be the frequency in Hz.
    Column D: 3
    Column H: 11

    In Row 2 put:
    Column 1: 0 (the starting time)
    Column 2: =B$1*SUM(C2:H2) // Add all of the harmonics and scale
    Column 3: =SIN(2*PI()*C$1*$A2)/C$1 // Calculated the value of this harmonic at this time value

    Now copy cell C2 across from column D2 through H2. This will calculate the values for all of the harmonics.

    You are almost ready to copy everything downward except that the time column is hard set to 0. So:

    Now copy Row 2 down to Row 3.
    Now set cell A3 to =A2+A$1.

    Now copy Row 3 downward from row 4 to row 102.

    Now highlight the first two columns (A2:B102) and plot those using a scatter plot.

    Fix the problems pointed out by JoeJester
    Last edited: Mar 7, 2015
    KJ6EAD likes this.
  7. ninjaman

    Thread Starter Member

    May 18, 2013

    the formula that I have is Vmax SIN 2PIft + V/3 SIN 6PIft + V/5 SIN 10PIft and so on.

    this is the formula im using, c9 Vmax, SIN(2PI()*frequency*time)
    time magnitude
    0.00001 1.5989480217
    0.00002 3.1915857261
    0.00003 4.7716276997
    0.00004 6.3328382387
    0.00005 7.8690559584
    0.00006 9.3742181092
    0.00007 10.8423845038
    0.00008 12.2677609603
    0.00009 13.6447221688
    0.0001 14.9678338926
    0.00011 16.2318744142
    0.00012 17.4318551431
    0.00013 18.5630403036
    0.00014 19.6209656246
    0.00015 20.6014559584

    this is what one lot looks like

    im sorry WBahn, I know it is frustrating that you put in the effort to explain something only to have a student say, "sorry but my tutor wont understand that"
    he has specified how he wants it done. I don't know what im doing wrong. im not getting the square wave though

    this is what I am getting

    any help would be really appreciated.
    I have left college now, I don't want to go back as im not feeling too good about things there. so the help here would be great!!!

    many thanks

    all the best

  8. WBahn


    Mar 31, 2012
    Your plot doesn't match your data. Look at the your data values and you see that they are increasing monotonically from t=10us to t=160us, yet your plot is bouncing around all over the place. So what you plotting can't be the data you are showing. Start out by plotting JUST the fundamental. Make sure that it makes sense. Then plot JUST the second harmonic and make sure that IT makes sense. Then add those two terms together and make sure that THAT makes sense. My guess is that you will find your error by the time you get that far. If not, keep going and asking if the partial result makes sense at each stage.

    If your tutor can't follow the spreadsheet approach I recommended, then you might consider getting a different tutor.
  9. bertus


    Apr 5, 2008
  10. JoeJester

    AAC Fanatic!

    Apr 26, 2005

    Shouldn't that be SIN(2*PI()*C$1*$A2)/C$1 // as Time zero occupies cell A2 and not A1.

    I had the graph starting at an amplitude of 0.5 vice 0 with your original formula. Also, I had to increase the number of cells down to row 102 so the total samples were 100.
  11. WBahn


    Mar 31, 2012
    It's possible. I set up the spreadsheet with some other bells and whistles in order to turn on and turn off whichever harmonics I wanted and I also had things shifted down and to the right from A1. So I just translated things mentally when I made the post. I didn't save the spreadsheet and I don't feel like redoing it, but I'm pretty sure you are correct and I've updated the post.

    I think what I had actually gave 100 samples, but we need 101 samples due to the fence post problem.
  12. JoeJester

    AAC Fanatic!

    Apr 26, 2005

    It's possible you did have, I just noticed the error when I was duplicating your instructions.


    When I replicated WBahn's work, it did make what was expected when working with so few of the odd harmonics. If you wanted a squarer square wave, you would need to include a lot more odd harmonics.

    In fact, when I simulated the instructions you received, the output resembles the excel graph as produced by WBahn. VF1 is the sum of the circuit. All the other waves represents sine waves from the fundamental to the eleventh harmonic.


    On edit ...

    Ninjaman, look at this link ... http://recordingology.com/in-the-studio/distortion/square-wave-calculations/

    Following those formula's, the excel graph looks like

    Last edited: Mar 8, 2015
  13. ninjaman

    Thread Starter Member

    May 18, 2013

    I have now got this
    using this formula
    the 2*PI() stays constant throughout the other formulas. my lecturer showed a different way that doesn't seem to work. which is why I was confused.

    im off college for the rest of the year due to some mental health issues and cant go back into college. I emailed my lecturer and he didn't seem bothered and asked how I would complete the year. didn't really offer any help either with my course work. so the help i get here is appreciated!!!

    this is my assignment

    Assignment Brief: For this assignment you will need to investigate complex waveforms. You are required to determine the Fourier series used to construct a square wave. And prove that this wave can be constructed from individual sine waves.

    Method (tasks):

    Research and determine the Fourier series associated with a square wave
    . this is can do on the internet without a problem
    Obtain readings from Multisim to show frequency and magnitude of sine waves. this I can do

    Plot these values on an excel graph

    Research and measure THD
    this I can do

    Draw conclusions on uses
    not sure what he means here, I will email him

    Assessment Evidence:

    Present finding within a formal report

    Front cover


    Contents page

    Relevant research

    Determine Fourier series mathematically, graphically and measure in simulation
    I think the formula I used is different than the fourier one on the internet

    Determine THD mathematically and measure in simulation
    not sure how to do this

    Technical conclusion, comparison of values/ waves produced by different methods / research into use of Fourier analysis

    Bibliography & list of sources

  14. Veracohr

    Well-Known Member

    Jan 3, 2011
    I assume you mean you don't know how to determine it mathematically since you said above you could measure it. The Fourier series gives you the relative amplitude of each harmonic, so calculate the amplitudes and use them.
  15. ninjaman

    Thread Starter Member

    May 18, 2013
    i have to do a technical conclusion on the results that i have obtained from this assignment. i never know what to write for a technical conclusion, this is what i put. any suggestions would be great.

    • Compare and discuss all results in a technical conclusion.
    This assignments aim was to show the use of the Fourier series to create a square wave from individual sine waves. The simulation software allows for any number of harmonics in analysis mode, a maximum of nine were chosen to keep calculations simple. The simulation software provides the magnitudes for each harmonic and exporting this information to a spreadsheet program simplified creating the square wave and formulas. The spreadsheet will allow for any number of sine waves making a more accurate looking square wave, whereas the voltage adder on multisim only allows for three inputs resulting in a less accurate square wave. The total harmonic distortion for three inputs is 41.43% which is 1.47% less than the spreadsheet square wave.
    “In audio systems, lower distortion means the components in a loudspeaker, amplifier or microphone or other equipment produce a more accurate reproduction of an audio recording.” Wikipedia.(2015).

    • The simulation software provides a measuring instrument for total harmonic distortion which is used for accurate measurement although this information is available in the previous Fourier analysis.
    When using the total harmonic distortion formula the more harmonic components the higher the distortion percentage.
  16. WBahn


    Mar 31, 2012
    As you add more components you get closer to the desired signal, but you are claiming that the distortion increases as you do this. Does that make any sense? What you are saying is that if we were to use an infinite number of terms we would have a perfect replica of the intended waveform yet have infinite distortion.
    ninjaman likes this.
  17. crutschow


    Mar 14, 2008
    If you are talking about total harmonic sinewave distortion, then any deviation from a sinewave will certainly add to the distortion percentage.
    If you are talking about distortion from the ideal square-wave than added harmonics will reduce that distortion.
    ninjaman likes this.
  18. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    Perhaps a technical conclusion might also make mention of the Gibb's Phenomenon.
  19. MrAl

    Distinguished Member

    Jun 17, 2014

    The harmonic amplitudes for a square wave are very easy to calculate:
    A(k)=(4/pi)/k, for k odd only.

    I dont think it gets any simpler than that.
    If you want to derive this formula yourself then you have to use Fourier.