# EEVblog Electronics Community Forum

## Electronics => Beginners => Topic started by: Simon on March 09, 2018, 07:03:57 am

Title: Reconstructing a waveform from its harmonics.
Post by: Simon on March 09, 2018, 07:03:57 am
I am set a question by my assignment that gives me a spreadsheet showing values of a signal at a time. Processed through Excel and the Fourier analysis tool this gives me the magnitudes of various frequency components. I am then asked to recompose the original waveform from these components. Presumably these all start at the same point in time? As all the information I have is the harmonic frequency and it's magnitude. So if a waveform were to start earlier or later rather than all of the cycle start together then it would not work out would it?
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Benta on March 09, 2018, 08:00:03 am
If you don't have information of the phase of the signals, you'll not be able to reconstruct the waveform.
I don't know what your "Excel and Fourier analysis tool" is, but it should give you frequency and magnitude as well as phase information. Otherwise you're lost...
Title: Re: Reconstructing a waveform from its harmonics.
Post by: ataradov on March 09, 2018, 08:50:02 am
On a side note, for audio signals phase does not matter, it all sounds the same.

But keep in mind that it is better to add audio signals in a way that minimises peak amplitude to avoid clipping.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Benta on March 09, 2018, 09:08:33 am
On a side note

That's what I call spreading noise in a thread...

Totally irrelevant :(
Title: Re: Reconstructing a waveform from its harmonics.
Post by: ataradov on March 09, 2018, 09:12:39 am
Totally irrelevant :(
Why do you think it is irrelevant? It is very relevant if we are talking about audio applications. Original questions does not mention the topic of the assignment.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 09, 2018, 09:37:39 am
If you don't have information of the phase of the signals, you'll not be able to reconstruct the waveform.
I don't know what your "Excel and Fourier analysis tool" is, but it should give you frequency and magnitude as well as phase information. Otherwise you're lost...
If you have done Fourier over time sample sets, when doing the reverse with the same step size, you will get the same output in theory, such is used in audio compression.  However, I don't think this is what Simon is asking about.  I believe he has a fixed single set of samples, with a single Fourier analysis of that 1 complete chunk.  Yes, the reverse can be closely approximated, depending on the sample size and depth of the Fourier analysis, though, there will be loss.

Now, onto Simon's gut of the question.  The most accurate point in the Fourier should be the center of your sample set.  IE, if you do an analysis of 1000 samples.  When reversing the Fourier, the center at sample 500 should be the most accurate, where as you go further before and after sample 500, the error in reproduction will grow.  This is assuming you are using a true Fourier conversion of the entire sample set from beginning to end.  This will not be true for some sequential Fourier conversion algorithms designed/used in sound or streamed sampled signals.

To answer Simon's question, does Excel's Fourier analysis tool equally weigh all the samples in his sample set.  If yes, then, using an equivalent reverse tool, the reconstructed samples will be 'in-phase' or, most accurate from the center sample, progressively loosing refinement as you spread out to the left and right of center.  Now, if your sample set is, say, only 200 samples or less, with integer values from -100 to +100, every value may be perfectly reconstructed with a well enough defined Fourier analysis and reconstruction.  Doing this with 10000 samples, with random integers from -10000 to +10000, you will not be able to get the true data back unless you have an absurd size of points & definition in your Fourier, but it is doubtful.  But you will get an approximation.

Such tools are used to predict future trends in many applications, such as the stock market, and those new bloody HFT (search 'high frequency trading') machines equipped with tons of NVIDIA commercial graphics cards doing nothing but FFT an top of FFT again and again with real-time stock data to gain an edge on the stock market.  It should be illegal.

Title: Re: Reconstructing a waveform from its harmonics.
Post by: Benta on March 09, 2018, 09:44:51 am
It is very relevant if we are talking about audio applications.

We're not. Where on earth did you find a reference to audio in the original question?
Title: Re: Reconstructing a waveform from its harmonics.
Post by: ataradov on March 09, 2018, 09:47:52 am
Where on earth did you find a reference to audio in the original question?
Where did you find the reference to something else? The question is not clear. Since it is an assignment, it should have all the information required to complete it. Audio DSP applications often ignore the phase, assuming it is 0, so I just provided another option.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Benta on March 09, 2018, 09:49:18 am
:palm:  When you only have a hammer, everything looks like a nail...
Title: Re: Reconstructing a waveform from its harmonics.
Post by: amspire on March 09, 2018, 09:53:10 am
But keep in mind that it is better to add audio signals in a way that minimises peak amplitude to avoid clipping.
It would be a good idea to use floating point rather then integer when adding the harmonics to avoid any clipping.

Reconstructing the waveforms is a simple numerical addition of each harmonic waveform for each point in time - providing you have the phase and amplitude data for the harmonics. For simple periodic waveforms, the phase and amplitude of harmonics can be constant.

I haven't used the Excel Fourier analysis tool, but doesn't it give the results as a complex number when the phase is not zero?

Say you get the third harmonic as 0.5 +i0.22.

That means to reconstruct the third harmonic waveform, you use 0.5cos(3omegaf) + 0.22sin(3omegaf). (My attempt at an omega character failed - just replace omega with 2 x pi).

Or you can use the Inverse Fourier transform tool to rebuild the waveform.

Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 09, 2018, 09:57:38 am
Presumably these all start at the same point in time? As all the information I have is the harmonic frequency and it's magnitude. So if a waveform were to start earlier or later rather than all of the cycle start together then it would not work out would it?

Excel's Fourier is giving you a bunch of cosine waves (ie, the frequency of each sine wave (the cycle period of your data)) and amplitudes (the strength of the sine wave).  It's giving you a single snapshot of your data.  So, if your data has 100 points.  Start at point 50, and sum all your cosines, in both directions, 50 to 100 and 50 to 0, with point 50 being cosine(0) of frequency band.

(I hope it's cosine, and not sine.  but, if you give it a try for a small 20 samples of data, working from 10 to 20 and 10 to 0, you should find out pretty quick by looking at the results.)
Title: Re: Reconstructing a waveform from its harmonics.
Post by: amspire on March 09, 2018, 11:01:22 am
In my previous post, I thought that Excel gave the Fourier Transform results as complex numbers. Looking at a Youtube video, it does. I don't have Excel installed myself.

So you do have amplitude and phase. Just sum the waveforms as I described previously.

Just make sure that when you do the Fourier transform, you select a sampling period that is an exact multiple of the waveform. In other words, go from, say, rising zero crossing to at the start of the FFT sample period to the sample before the rising zero crossing at the end of the FFT samples. The sampling period can be one waveform period or multiple periods. Use as much of the data as possible, but if you do a FFT of 2.35 waveform periods, you will get a poor result.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 09, 2018, 11:34:43 am
The discrete Fourier transform of a real series is a complex series.  This complex series may be described as the sum of a sine and cosine via Euler's relation.

There are two ways to do this:

Take the inverse discrete transform via the FFT (the fast way)

Convert the complex value at each frequency in the transform to a sine and cosine wave at each frequency and add them up (the slow way)

I'd be *very* wary of Excel.  A friend of mine published enough papers on Excel numerical errors to get tenure.  Use Octave or MATLAB for things like this.

The point of the exercise is to understand that the Fourier transform and its inverse are both integrals in the continuous case and sums in the discrete case.  The forward and inverse transforms differ by a scaling factor (i prefer sqrt(N) which is symmetric) and the sign of the exponent of the exponential.  Both signs are used for the forward and inverse transforms by different groups of people.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 09, 2018, 07:25:08 pm
Attached are the questions and the spreadsheet they provide, so I have run the excel analysis tool as requested, the harmonic distortion I make to be something like 89%. I don't know if the fact that results are given in complex numbers effectively give me more information about phase angles. it looks like as usual the questions open more cans of worms than I was taught to close by the module so I'm back on the road again.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: amspire on March 09, 2018, 08:17:14 pm
Attached are the questions and the spreadsheet they provide, so I have run the excel analysis tool as requested, the harmonic distortion I make to be something like 89%. I don't know if the fact that results are given in complex numbers effectively give me more information about phase angles. it looks like as usual the questions open more cans of worms than I was taught to close by the module so I'm back on the road again.
The first harmonic is w0  = 2 x pi x 17.57... rad/sec    (J3)

The equation for harmonic "n" is

Vn (t) = (Real part of Components/1024)cos( n x w0 x t) + (Imaginary part of Components/1024)cos( n x w0 x t)

Do it for each harmonic and add them together for each value of t. Looks like you have to divide the components by 1024 first.

The other way is to run the Inverse Fourier Transform (IFT probably).
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 10, 2018, 12:28:10 am

The point of the exercise is to understand that the Fourier transform and its inverse are both integrals in the continuous case and sums in the discrete case.  The forward and inverse transforms differ by a scaling factor (i prefer sqrt(N) which is symmetric) and the sign of the exponent of the exponential.  Both signs are used for the forward and inverse transforms by different groups of people.

The point of the exercise is for them to pretend they gave me something hard and for me to pretend I know how to do it. The result as they have been so lackadaisical that they have actually given me quite a complex waveform. The harmonics are not strictly speaking harmonics as they are not multiples of the fundamental. Presumably the fundamentalist the first peak at 52 Hz. What appear to be the second and third harmonic are not multiples of 52 Hz. In actual fact when I have tried to recreate the waveform in a graphical calculator after about five cycles the wave form starts to change. So this is not a repetitive cycle it varies over time which just makes things more complicated. They have taken real-life data which is random and are trying to abstract it into a waveform that perfectly repeats every cycle the result is that as always with this stupid university this is a big mess.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: amspire on March 10, 2018, 01:40:07 am
I think they want to see the problems of reconstructing an abitrary waveform. The inverse fourier transform will generate a repetative waveform that is close to the original. It cannot be perfect since the samples start and end at different voltages, but with the number of harmonics, you should get a decent waveform.

The fact that the result is not perfect means you cannot just cheat and just repeat the original samples. They can check you did the exercise.

If you do the whole thing by adding the harmonics together, you will end up with DC (the zero frequency) plus 1023 different sinewaves with different phases. You have to evaluate every sinewave at each of 1024 points and add the 1023 results together. Luckily, in the question, they are not that cruel - they say to just use the principal harmonics. 17.578...Hz is the fundamental harmonic, and I would probably do all the harmonics to the 18th, as the low harmonics will give the fundamental shape. If you only do the 5 biggest harmonics, you will get a crude result. The higher harmonics will flatten lines, remove ringing and sharpen edges.

Or as I said, you can use the built in Inverse Fourier transform function to get the same result.

My problem with the spreadsheet is for the initial samples, it does not mention any time units, but it has to be the period of the first harmonic. So when you are calculating the inverse transform, you will do it for t0=0 to t1023=1/17.587... seconds. That must have been the timespan of the of the original 1024 samples.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 10, 2018, 01:46:44 am
So I'm a little confused as to why 17.5 Hz is the fundamental. I thought that the Fourier analysis showed you the strength of any particular frequency in a waveform. And in this case the first strongest waveform is at 52.73 Hz is there anything in particular I'm missing in this whole mess? Isn't the first significant frequency the fundamental? Why would fundamental be at 17.5 Hz? From what I can tell it just happens to be related to the amount of samples they have taken? I'm rereading their explanation of how to use Excel tool maybe they have hidden some clue there as to how I am supposed to solve this particular problem

What I could really do with is a shed load of time to study the subject properly instead I've been given a crash course and then this assignment so I can just move on and get my silly piece of paper. The fact that a silly piece of paper doesn't actually mean anything is of no interest to anybody I just need a silly piece of paper. The result is that I going round in circles trying to understand the subject properly rather than just pass the test.

Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 10, 2018, 02:04:11 am
. I don't know if the fact that results are given in complex numbers effectively give me more information about phase angles. it looks like as usual the questions open more cans of worms than I was taught to close by the module so I'm back on the road again.

You seem to expect them to ask a question and tell you the answer.  This is all *very* basic stuff.

Perhaps you should review the definition of the discrete and continuous Fourier transforms.

The discrete transform is defined on the semiclosed interval [-Pi:Pi} and periodic outside that interval.  It repeats on [Pi:2*Pi), etc.  There is no requirement that the signal be periodic inside [-Pi:Pi).

The subtlety of the semiclosed interval and its consequences are often neglected, but I shall leave that to the reader. along with the proper treatment of the amplitudes of the first and last  sample and the effects of series length and window choice.

As remarked before, the appropriate tool is Octave, MATLAB or similar.  I am a little disturbed that you were encouraged to use Excel for such work.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: amspire on March 10, 2018, 02:13:25 am
So I'm a little confused as to why 17.5 Hz is the fundamental. I thought that the Fourier analysis showed you the strength of any particular frequency in a waveform. And in this case the first strongest waveform is at 52.73 Hz is there anything in particular I'm missing in this whole mess?
There is no law that says the first fundamental has to be the biggest. If you look at every frequency, they exactly equal 17.5... x2, x3, x4, x5 up to x1022. That is why 17.5... is the fundamental and every other frequency is a harmonic.

The other thing if the inverse transform will try and make a repetitive waveform looking like the original samples but repeated. What frequency will this waveform have? It has to be 17.5... Hz. There is no lower frequency. It definitely cannot be higher  - the 17.5... component would then prevent the second waveform repetition from beeing the same as the first. That means the original 1024 samples must have been taken during one 17.5... Hz period.
Quote
Isn't the first significant frequency the fundamental? Why would fundamental be at 17.5 Hz? From what I can tell it just happens to be related to the amount of samples they have taken? I'm rereading their explanation of how to use Excel tool maybe they have hidden some clue there as to how I am supposed to solve this particular problem

What I could really do with is a shed load of time to study the subject properly instead I've been given a crash course and then this assignment so I can just move on and get my silly piece of paper. The fact that a silly piece of paper doesn't actually mean anything is of no interest to anybody I just need a silly piece of paper. The result is that I going round in circles trying to understand the subject properly rather than just pass the test.
It looks like Excel may not have an Inverse Fourier Transform, but you can look on Youtube tutes for clues. I do not use Excel. You may have to load the Data Analysys pack into Excel, and there may be both FFT and DFT. I do not know.

You can also use the sum of the cos + sin equations I mentioned not long ago, but that will need a bit if Excel skill. You have to do formulas with a variable in excel and loop it over 1024 values of t.

If you don't want to do any of it, that is fine with me. It is actually worth learning.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 10, 2018, 04:18:58 am
. I don't know if the fact that results are given in complex numbers effectively give me more information about phase angles. it looks like as usual the questions open more cans of worms than I was taught to close by the module so I'm back on the road again.

You seem to expect them to ask a question and tell you the answer.  This is all *very* basic stuff.

Perhaps you should review the definition of the discrete and continuous Fourier transforms.

The discrete transform is defined on the semiclosed interval [-Pi:Pi} and periodic outside that interval.  It repeats on [Pi:2*Pi), etc.  There is no requirement that the signal be periodic inside [-Pi:Pi).

The subtlety of the semiclosed interval and its consequences are often neglected, but I shall leave that to the reader. along with the proper treatment of the amplitudes of the first and last  sample and the effects of series length and window choice.

As remarked before, the appropriate tool is Octave, MATLAB or similar.  I am a little disturbed that you were encouraged to use Excel for such work.

I don't expect answers I'm just trying to understand. Perhaps you should take a UK qualifications course in you would find out what a mess we are in here. I have gone round and round in circles with my material which has done nothing but add to the confusion and send me off in various directions looking for other material. This is a homestudy course that I do around a full-time job it has become the thing that absorbs all of my free time and I am still getting nowhere. Yes the choice of Excel might be unusual, welcome to UK education. The course material is quite old and I'm sure lots of other useful programs may not have even been available when it was first written.

I have just bought another entire book I could read on the subject but then in actual fact I need to get on with this crap before I'm kicked off the course for taking too long. But every time I try and solve one problem suddenly I discover there's a whole world out there that needs studying and that the course material thus far has not prepared me for it. I'm quite willing to learn but I only have so much time and it seems that every time I come to these assignments I spend more time trying to figure out what the heck they are on about then I spent studying the material in the first place that is supposed to teach me how to do the assignment. I don't have Matlab I don't understand these programs they are again another thing I would have to learn and I don't necessarily have the time right now. I've been looking at this for the last few evenings it is now going to absorb my entire weekend, for what?
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 10, 2018, 04:26:46 am
So I'm a little confused as to why 17.5 Hz is the fundamental. I thought that the Fourier analysis showed you the strength of any particular frequency in a waveform. And in this case the first strongest waveform is at 52.73 Hz is there anything in particular I'm missing in this whole mess?
There is no law that says the first fundamental has to be the biggest. If you look at every frequency, they exactly equal 17.5... x2, x3, x4, x5 up to x1022. That is why 17.5... is the fundamental and every other frequency is a harmonic.

The other thing if the inverse transform will try and make a repetitive waveform looking like the original samples but repeated. What frequency will this waveform have? It has to be 17.5... Hz. There is no lower frequency. It definitely cannot be higher  - the 17.5... component would then prevent the second waveform repetition from beeing the same as the first. That means the original 1024 samples must have been taken during one 17.5... Hz period.
Quote
Isn't the first significant frequency the fundamental? Why would fundamental be at 17.5 Hz? From what I can tell it just happens to be related to the amount of samples they have taken? I'm rereading their explanation of how to use Excel tool maybe they have hidden some clue there as to how I am supposed to solve this particular problem

What I could really do with is a shed load of time to study the subject properly instead I've been given a crash course and then this assignment so I can just move on and get my silly piece of paper. The fact that a silly piece of paper doesn't actually mean anything is of no interest to anybody I just need a silly piece of paper. The result is that I going round in circles trying to understand the subject properly rather than just pass the test.
It looks like Excel may not have an Inverse Fourier Transform, but you can look on Youtube tutes for clues. I do not use Excel. You may have to load the Data Analysys pack into Excel, and there may be both FFT and DFT. I do not know.

You can also use the sum of the cos + sin equations I mentioned not long ago, but that will need a bit if Excel skill. You have to do formulas with a variable in excel and loop it over 1024 values of t.

If you don't want to do any of it, that is fine with me. It is actually worth learning.

I think Excel does do the reverse transform however as per the question I am supposed to graphically add up the harmonics. I'm still trying to establish what the fundamental is,  the great big spike at 52 Hz or four some mysterious reason 17.5 Hz just because that is the step in the analysis. I was given the whole spreadsheet mostly filled out so once again I'm told half the story and supposed to figure it out. I have already shown this to an experienced subcontractor we use at work who is also a member of this forum and he was completely baffled as to what the hell they are on about. Half the problem with these questions is that they are half cocked and not properly asked. I have to interpret them and try work out what they actually want.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rstofer on March 10, 2018, 05:12:05 am
Column J gives you the DC component (J-2), the first harmonic frequency (J-3) and all subsequent harmonic frequencies up to 1023.  There is no question about the fundamental frequency, it is given.

Column H gives you the magnitude of each harmonic from DC to 1023.  It is the square root of the sum of the squares of the Fourier values in column D divided by 1024.  This is the magnitude of the harmonic component.  It does not include phase.  You should be able to get the phase from column D by taking the arctan(imaginary/real).  I'm a little shaky on that...  If you don't need phase (as discussed above), column H has what you need for magnitude and column J has the frequency.

If you scan down column H, you can see the heavy hitter harmonics.

Your final function will have a DC offset because the magnitude at f=0 is not zero.

It should be pretty straightforward to get the magnitude and phase along with the frequency right out of the spreadsheet columns.

I think...
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 10, 2018, 05:42:48 am
OK I understand what they want and why they used Excel.

Evaluate each frequency in the transform at each time.  Graph it in time, add it to the graph of the previous frequencies.  You'll have to convert the exponentials to a cosine or sine and phase term.

A quick summary:

There are as many frequencies in the FFT as there are samples.  Half of the frequencies (-1 for even lengths) are negative.  The negative frequencies are the complex conjugate of the positive frequencies. The first value is DC.   The middle of an even length series is Nyquist.  For an odd length series the Nyquist is repeated.  It is common to compute and store the positive frequencies of a real series in the same array as the real series.  The algorithm is modified to accommodate this by computing the complex conjugate from the positive frequency values..  DC and the positive frequencies come first followed by the negative frequencies in reverse order for a general complex to complex transform.

With no window function (aka a rectangular, boxcar window) all the frequency samples are convolved with sinc(x) (i.e. sine(x)/x)  If a triangular, aka Bartlett, window is applied the frequencies are convolved with sinc(x)**2.  Wikipedia has a good page on this.  If you convolve any arbitrary function with a spike of unit area (a Dirac functional) the result is a copy of the function centered on the spike.  A Dirac functional has infinitessimal width, infinite amplitude and unit area.  A multiplication in time is a convolution in frequency and vice versa.  Because the series does not go on forever, it is implicitly multiplied by a window in time.  So smearing of the Fourier frequencies is unavaoidable.  All you can do is choose the shape of the  smearing operator.

The first bin is 0 Hz, the rest up to Nyquist are at (k/n)*(1/2*dt) for 1 <=k<=n/2.  Those frequencies are harmonically related, but they are not the signal.  They are the discrete Fourier frequencies.  They are not called "harmonics".

Never take serious courses without books and never get rid of the books.  They are your offline memory.  You can retrieve information much faster from the text you used for a course than anything else.  If there are no books for courses, a truly awful thing to do to the victims, research and find suitable texts.  I buy 3-4 books for any topic I'm trying to learn on my own.

I've not looked at the problem or spreadsheet.  I don't have Excel.  From the statements made you are being asked among other things  for THD in the presence of signals which are not harmonically related.  This is called a multitone signal and is used to evaluate nonlinearities in things like RF mixers.

Education has become a scam which is a great shame.  The best reference I have  on the FFT is "The Fast Fourier Transform and Its Applications" by  E. Oran Brigham. Apparently it is out of print and people are asking absurd (\$832 US!)  The previous edition which I also have  shows up for \$11, so get that.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 10, 2018, 05:57:57 am
I just added a plot table of the data in column 'B' as shown in my screenshot.  It is clearly a perfectly constructed textbook example waveform from the Fourier data.  If Simon does the assignment Inverse Fourier correct as expected by the course, he should be able to reconstruct the red waveform 'EXACTLY' down to the dot, there can be no error here, phase mistakes, or excuses.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 10, 2018, 06:16:49 am
I just added a plot table of the data in column 'B' as shown in my screenshot.  It is clearly a perfectly constructed textbook example waveform from the Fourier data.  If Simon does the assignment Inverse Fourier correct as expected by the course, he should be able to reconstruct the red waveform 'EXACTLY' down to the dot, there can be no error here, phase mistakes, or excuses.

Yes they show the wave on the previous sheet of the assignment. But from your expanded image of the spectrum there are more harmonics nearer 18 KHz. I'm not sure why there is a partial waveform on the end of the data, from what I read the section of data used for analysis should be one complete cycle.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rstofer on March 10, 2018, 06:50:04 am
I just added a plot table of the data in column 'B' as shown in my screenshot.

Duh!  I really missed that!

Sure, if you have f(t) given and you want f(t) back, just plot f(t).

I plotted the data in Matlab.  That is a lot harder than it looks because I first had to do some text editing on the values I copied from Excel.  Ultimately, I wound up with one 7k char line.  I just couldn't come to grips with breaking it up on continuation lines.  Clearly, Excel is the way to plot an Excel column.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 10, 2018, 07:17:16 am
There is a clue on sample 512.  It is the only row with 1 Fourier component, and, a perfect frequency of 9000hz on the dot.  Magnitude column (H) and column (I) all begin running backwards from that point on the the bottom.  Only samples 1 through 511 are valid Fourier components. over the long run. Example:

sample row 1023 H&I = sample row 1 H&I
sample row 1022 H&I = sample row 2 H&I
sample row 1021 H&I = sample row 3 H&I
sample row 1020 H&I = sample row 4 H&I
Everything merges at row 511 and 513.  The Fourier components (D...G) are really close.

Though, the sample interval (A), sample (B), and frequency (J) continue unaffected.

The final 3 peaks at 18Khz may be the fact that the sample data goes from sample #1023 = -53.50 to 0 (ie no data left) after that point.  See photo: This does not seem to be correct since if you use these higher Fourier components, your re-construction will have a high frequency waveform throughout it, and a strong visible one at that.

Your sample rate is 18000hz.  This means the maximum possible frequency in the sample is 9000.  The higher peaks are like what you see in an oversampling ADC/DAC filter response above 1/2 sampling frequency.  Peaks exist, but they aren't giving meaningful information about the waveform except for single transition step/pulses.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rstofer on March 10, 2018, 07:22:46 am
Info re: Excel and Fourier are all over the Internet and it includes a video.  The inverse transform is supported.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 10, 2018, 07:25:30 am
I'm going to have to reread the section of the module on FFT and do some more reading
Title: Re: Reconstructing a waveform from its harmonics.
Post by: mikerj on March 10, 2018, 07:46:57 am
I just added a plot table of the data in column 'B' as shown in my screenshot.  It is clearly a perfectly constructed textbook example waveform from the Fourier data.  If Simon does the assignment Inverse Fourier correct as expected by the course, he should be able to reconstruct the red waveform 'EXACTLY' down to the dot, there can be no error here, phase mistakes, or excuses.

The course paper says nothing about using an inverse Fourier.  It actually says reconstruct using the "principal harmonics" and even suggests sketching the waveforms which is clearly not going to exactly recreate the original.  Using the frequency, magnitude and phase of the three peaks (i.e. fundamental and two harmonics) gives a waveform similar to, but not exactly the same as the original as would be expected and is shown below.

Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 10, 2018, 07:57:45 am
I just added a plot table of the data in column 'B' as shown in my screenshot.  It is clearly a perfectly constructed textbook example waveform from the Fourier data.  If Simon does the assignment Inverse Fourier correct as expected by the course, he should be able to reconstruct the red waveform 'EXACTLY' down to the dot, there can be no error here, phase mistakes, or excuses.

The course paper says nothing about using an inverse Fourier.  It actually says reconstruct using the "principal harmonics" and even suggests sketching the waveforms which is clearly not going to exactly recreate the original.  Using the frequency, magnitude and phase of the three peaks (i.e. fundamental and two harmonics) gives a waveform similar to, but not exactly the same as the original as would be expected and is shown below.

Which is what I am attempting although the second and third peaks are not actually harmonics of the first as they are not an exact multiple. As pointed out earlier I need to establish the phase angle in order to get it right. if I don't I get the attached. I'll be delving into this tomorrow.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 10, 2018, 08:04:21 am
the thing that is really confusing is the harmonic distortion as like I said the second and third peaks are not harmonics of the first although if I assume they are I get a distortion of about 90%, if I simply use all the values in one cycle I get over 800% which surely is not possible. if I use 52.73 as the fundamental and go every 4 squares (multiples of 52.73) I get again around 90% even though I'm not using the values of the second and third peaks.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Vtile on March 10, 2018, 08:30:56 am
From another thread if it gives any 'heureka' moments.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 10, 2018, 08:56:55 am
In addition to the smearing from only having 1024 samples, there is wraparound because the time domain data were not zero padded to 2048 samples before computing the FFT.  This is immediately evident in the reconstruction shown.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Jay_Diddy_B on March 10, 2018, 09:17:54 am
Hi,

You can also do some simple experiments in SPICE.

Consider this model:

(http://www.eevblog.com/forum/beginners/reconstructing-a-waveform-from-its-harmonics/?action=dlattach;attach=402472;image)

I have two voltage source in series. I have a fundamental frequency 1kHz and third harmonic 3kHz. The amplitude of the 3rd harmonic is 1/9 the amplitude of the fundamental. The difference between the two is the phase relationship of the harmonic to the fundamental.

If you look at the time domain waveforms you see that they are different:

(http://www.eevblog.com/forum/beginners/reconstructing-a-waveform-from-its-harmonics/?action=dlattach;attach=402474;image)

However if you look at the FFT, they are they same. There should only be two components, the fundamental at 1khz and the harmonic at 3kHz. Since the phase information is not included in the FFT you can not reconstruct the original waveforms from the FFT. The phase relationship is needed and it is missing.

(http://www.eevblog.com/forum/beginners/reconstructing-a-waveform-from-its-harmonics/?action=dlattach;attach=402476;image)

The other FFT components are from the sampling window etc.

Regards,

Jay_Diddy_B

Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 10, 2018, 10:37:34 am
I just added a plot table of the data in column 'B' as shown in my screenshot.  It is clearly a perfectly constructed textbook example waveform from the Fourier data.  If Simon does the assignment Inverse Fourier correct as expected by the course, he should be able to reconstruct the red waveform 'EXACTLY' down to the dot, there can be no error here, phase mistakes, or excuses.

The course paper says nothing about using an inverse Fourier.  It actually says reconstruct using the "principal harmonics" and even suggests sketching the waveforms which is clearly not going to exactly recreate the original.  Using the frequency, magnitude and phase of the three peaks (i.e. fundamental and two harmonics) gives a waveform similar to, but not exactly the same as the original as would be expected and is shown below.

Which is what I am attempting although the second and third peaks are not actually harmonics of the first as they are not an exact multiple. As pointed out earlier I need to establish the phase angle in order to get it right. if I don't I get the attached. I'll be delving into this tomorrow.

Can you share with us how you got this result.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 10, 2018, 11:15:48 am

However if you look at the FFT, they are they same. There should only be two components, the fundamental at 1khz and the harmonic at 3kHz. Since the phase information is not included in the FFT you can not reconstruct the original waveforms from the FFT. The phase relationship is needed and it is missing.

I'm sorry, but that statement is wrong.  What is being shown is the amplitude spectrum, NOT the FFT.   That is, if  Jay_Diddy_B actually calculated the modulus instead of just taking the real part and plotting it.  In thirty years of heavy DSP work I've never seen wraparound produce the noise shown at high frequencies from a simple signal composed of 3 sine waves..  But the phase information gets crappy as you get close to Nyquist in addition to changing very rapidly.

The FFT of any  series, real or complex, is complex.  The phase information is contained in the relationship between the real and imaginary parts of the transform.  You determine the phase  by plotting the real and imaginary components in the XY plane with X as the real axis and Y as the imaginary axis.  In practice you calculate it using the arc tangent.  In complex signals unwrapping the phase correctly is quite challenging.

Export the time domain signal in .CSV format and read it in in Octave.  That will have the very real advantage of making you actually learn what the discrete Fourier series looks like.  You'll have to perform all the mathematical steps yourself.

If you don't acquire a skill this is all pointless and any piece of paper obtained will be worthless.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 10, 2018, 01:01:37 pm
I just did a reconstruction in Excel, see pic below.  Something is off about the way the 'Frequency' column is calculated.
If I were to fiddle with the way the  'Frequency' column is calculated, or throw off the value of PI by a slight amount, I can make my reconstruction from the 3 points much better.  Almost perfect like the bottom 2 bumps.  What you see was calculated using only 3 cosines.  The formula is visible at the top...
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 10, 2018, 01:14:34 pm
Ok, if I add in the column A# * (1000/1024), it gets more accurate at the focal point.  Maybe if I added in another 6 sines, the adjacent bands each side of the 3 peaks, things might get more accurate.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: amspire on March 10, 2018, 04:16:33 pm
I just had a quick go in Libre Calc to reconstruct the waveform.

The exercise said to use the principle harmonics, so I decided to use the first 1023 of them.  :)

Got a pretty good graph, except that it was reversed in time - it starts at the end of the waveform and ends at the start! Not sure what I did there.
(http://www.eevblog.com/forum/beginners/reconstructing-a-waveform-from-its-harmonics/?action=dlattach;attach=402532)
Other then that, is a pretty accurate match to the original.

I used time on the x axis rather then samples, and at each time interval, I just summed the cos and sin components for each harmonic.

Ended up with a 1024x1024 table with each cell having its own cos and sin sum. Each column corresponds to a time sample, so I just sum all the columns and plotted the results against time.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 10, 2018, 04:53:54 pm
Ohh yeah, those rotten little bastards...  The frequency coefficients are too perfect... Here is what I achieved using only 3 points from the FFT, not 1024:

Also:
The course paper says nothing about using an inverse Fourier.  It actually says reconstruct using the "principal harmonics" and even suggests sketching the waveforms which is clearly not going to exactly recreate the original.  Using the frequency, magnitude and phase of the three peaks (i.e. fundamental and two harmonics) gives a waveform similar to, but not exactly the same as the original as would be expected and is shown below.
Actually, after centering in on the 3 peak frequencies, fundamental + 2 harmonics, it's pretty much exact...  Take a look...
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 10, 2018, 05:10:06 pm
Note: in my Excel spreadsheet, you can change the three '0.9765625'  with  '(1000/1024)' (same value) in my sine generators.  This matches the frequency column 'J' where the readout is '=A1*18000/1024'  Note that also in my sine generators, I have 'PI()/9000', this is because the real way to write it should have been '2*PI()/18000'.  Once again I just did some shorthand.

Also, if you change the three '270' to any one new number, the waveform stays the same, it's just shifts the entire waveform to the left or right.  270 just happened to line up the waveforms perfectly.

As for the '*2' or '*-2' for the amplitude, when reading off of a spectrum, since the values have been made absolute positive only, there is a 50/50 chance that the sine wave amplitude is inverted.

The order of the multiply and divides could have been better though out before posting here, but, it works...
Title: Re: Reconstructing a waveform from its harmonics.
Post by: amspire on March 10, 2018, 05:13:43 pm
BrianHG, looks like you will get the gold star. :-+

Obviously this is the aim of the exercise - you have essentially worked out the frequencies, amplitudes and phases they used to generate the original waveform.

This is an exercise that actually has a useful purpose!
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 10, 2018, 05:38:51 pm
frequencies, amplitudes and phases they used to generate the original waveform.
Frequencies, just by looking at the points to the left and right of the center power, I made my best judgement call.
Amplitudes, I just used the signal level in the FFT.  It was good enough.  My reconstruction may have been better if I refined these numbers.
Phases, well, like I said, there is a 50/50 chance of it being positive or negative.
As for the relative offset of the entire waveform, that '270', I started with 0 and saw everything was just shifted off to the right, but the waveform pattern was perfect.  I then guessed 256, being a magic number, it was very close.  I then went up in increments of 5 and settled on 270.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 10, 2018, 06:15:05 pm
BrianHG, looks like you will get the gold star. :-+

Obviously this is the aim of the exercise - you have essentially worked out the frequencies, amplitudes and phases they used to generate the original waveform.

This is an exercise that actually has a useful purpose!

Arrrrggg, ok, this one is final.  I realized the 2 higher peaks in the waveform are exactly x5 and x7 from the fundamental.  This is why the pattern repeats forever without going all wacky.  The reconstruction only requires the base 51.2 Hz.  The other 2 waveforms are that frequency x5 and x7.  Now, my reconstruction, with adjusted amplitudes, is dead on!  This one is worth a gold star.  Take a look...
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 10, 2018, 07:27:59 pm
Which is what I am attempting although the second and third peaks are not actually harmonics of the first as they are not an exact multiple. As pointed out earlier I need to establish the phase angle in order to get it right. if I don't I get the attached. I'll be delving into this tomorrow.

Yes they are exact multiples, the second peak is exactly x5 the first 51.2Hz.  And the third peak is exactly x7 the first 51.2Hz.  This is why the double spike pattern keeps repeating and my above post proves it giving dead on results removing all doubt.  These odd multiples have their cosines amplitudes inverted, or, you can call this 180 degrees out of phase.  Harmonics are usually odd number multiples.  This is also why we have 'third overtone crystals' and very old and rare 'fifth overtone crystals'.  These crystals have just 3x the number printed on their case.  IE a 75Mhz third overtone crystal is really just a 25MHz crystal.  You attach this crystal, or even a 25Mhz crystal to an approximately tuned 75Mhz LC oscillator, and, the 25MHz crystal will tame it and lock your LC oscillator's frequency at the 3x it's value, or 75MHz.

If you need an explanation of any part of how I worked this out, or any part of my attached Excel formula, let me know.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 10, 2018, 07:58:59 pm
so the peaks are not at the frequencies shown on the frequency column? the first peak is shown at 52.73........ Hz but you make it work with a different number.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 10, 2018, 08:53:34 pm
Ok, step 1, look at waveform and FFT to determine the accuracy of the peaks.

Finally seeing the waveform of 'Sample' from column B, the repeating pattern demands that the higher frequencies always repeat in the same area of the main 52hz indefinitely.

To check this, we starting with peak #1 and peak #2.
Peak #1 is strongest at 52.7hz, but, just a little slower as you see in my illustration, however, for now, we will call this 52.7hz.
Peak #2 is strongest at 246.1hz, but looking at the strength of the points to the left and right, we can see it should be a little higher.

Now for some math.  Take 246.1 and divide by 52.7 and you get approximately 4.7.  Now, we know this is too close to 5 to be a coincidence, so we do the reverse and take 52.7 x 5 = 263.5hz.  A little too high.

Lets also check peak 3 at 351.6hz / 52.7 = 6.7.  This is also to close to 7 and also lets see the opposite.  52.7*7=368.9hz, also a little too high.

Now if you are aware that the lower the frequency, the less accurate the Fourier hz measurement since it sees fewer sine oscillation over your 1024 samples compared to your higher frequency readings.  If you understand this, this next step will make sense.  If you don't, I'll show you another way to get a more accurate value on that 52.7hz...

Ok, refine the 3 frequencies, take them high ones and divide them down to 52.7hz.
peak3 = 351.6/7 = 50.2
peak2 = 246.1/5 = 49.2
peak1 = 52.7      = 52.7

take the average  50.2+49.2+52.7 = 152.1 / 3 = 50.7hz.  (I know this is still a little off, but, it will do for now)
This time if you redo the above 2 steps at the beginning, the number have gotten really close.

peak2 246.1hz/50.7hz=4.85.  (looking at the Fourier chart, we know point #2 should be a little higher than 246.1, this will even out)
peak3 = 351.6hz/50.7hz=6.93 (Again, looking  at the Fourier chart, we know point #3 should be only a pinch higher than 351.6, this will even out)

These 2 numbers peaks have gotten really close to 5x and 7x.  In fact now, if we multiply the base 50.7hz*5, we get 253.5hz and judging by the chart, this looks like it's the exact right value.  Same with 50.7hz*7 = 354.9hz, judging on the chart, this also looks perfect.

Next post, making a superior Excel spread sheet which allows you to play with these figures.  Give me 30 minutes...
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 10, 2018, 09:32:41 pm
I see, if only my course taught me this stuff. Basically the frequency step is too large to resolve the exact frequency. I think that if this course was worth it's salt it would include lessons on the proper tools like matlab instead of trying to short cut it by hacking about with excel. I expect the fourier analysis was put into excel to keep the stock brokers hayy rather than the engineers.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 10, 2018, 09:33:55 pm
I think really all I am missing is checking the phases of the 3 peaks and giving it a go.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 10, 2018, 09:45:20 pm
I see, if only my course taught me this stuff. Basically the frequency step is too large to resolve the exact frequency. I think that if this course was worth it's salt it would include lessons on the proper tools like matlab instead of trying to short cut it by hacking about with excel. I expect the fourier analysis was put into excel to keep the stock brokers hayy rather than the engineers.

Exactly correct.
I've attached my new fixed Excel spread sheet.  After correcting my formula, it turns out your base frequency is exactly 50Hz.  Who'd thought.

You will see a few green numbers inbetween the 2 tables.  Just edit those and the red line on the reconstruction will automatically update.

You may adjust the over all offset, the base frequency, and the amplitude + it's multiplier.  I used a -2 for the x5 and x7 to invert those cosines.

If you enter 0 for a gain figure, it will turn off that particular cosine.  The gains I took from the peak value of each cosine on the Fourier chart.  Then, tweaked them.  Now that you can easily play with them, you can see the effect of using chart values VS my numbers, VS any number you like.

The formula for the reconstruction is now compacted and you should have no trouble working it out.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 10, 2018, 09:52:38 pm
Well yes as the preamble to these questions state that its' the current waveform of a VFD I guess they might just have a 50Hz supply ;) Thank you for your efforts
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 10, 2018, 10:02:04 pm
:palm: The table was off by 1 column.  Here is the fix.  (It corrects that little tiny blue dot at the right of the table and corrects the waveform offset to 270.)
Title: Re: Reconstructing a waveform from its harmonics.
Post by: IanB on March 10, 2018, 10:21:53 pm
If you have not seen this video, it is really worth watching, and then many others by the same producer.

I have only ever had a general understanding of Fourier transforms (never needed to use them), and the explanation given in this video is a revelation. Those of us that grew up with books have always thought they were the way to learn, but this really shows how to use video content to go beyond what books can do!

https://youtu.be/spUNpyF58BY
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 10, 2018, 10:24:24 pm
Well yes as the preamble to these questions state that its' the current waveform of a VFD I guess they might just have a 50Hz supply ;) Thank you for your efforts
Note that if you change you frequency column from:
=A3*18000/1024
to
=A3*18000/1030

The peaks hit their frequency much better, however, this might not be an error, just an artifact from such a small sample set.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 10, 2018, 10:33:27 pm
If you have not seen this video, it is really worth watching, and then many others by the same producer.

I have only ever had a general understanding of Fourier transforms (never needed to use them), and the explanation given in this video is a revelation. Those of us that grew up with books have always thought they were the way to learn, but this really shows how to use video content to go beyond what books can do!

https://youtu.be/spUNpyF58BY

I am subscribed to that very channel and looked for a fourier video. yes he is excellent and I am currently going through his calculus series
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 10, 2018, 10:40:55 pm
Yes I have seen that one, no math content but an interesting look
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 11, 2018, 01:42:57 am
I see, if only my course taught me this stuff. Basically the frequency step is too large to resolve the exact frequency. I think that if this course was worth it's salt it would include lessons on the proper tools like matlab instead of trying to short cut it by hacking about with excel. I expect the fourier analysis was put into excel to keep the stock brokers hayy rather than the engineers.

That's the traditional L2 (least summed squared error) transform view and you should have been taught that in the first lesson.

However, it turns out that you can compensate for the short time series length using what's called a sparse L1 (least summed  absolute error)  pursuit.  That's about 40 semester hours of mathematics from where you are now though.  No one knew that when I was in grad school 30 years ago.  It was only discovered around 2004.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 11, 2018, 01:52:53 am
The problem is that they are trying to condense it down and the material is actually quite old. I find them seeming to skip stuff. A work colleague who is going to do the mechanical equivalent has already found the same I did with the maths bridging module you do before any course.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 11, 2018, 02:13:48 am
The Fourier transform goes back to 1810 although some of the mathematical details were not resolved until almost 100 years later.  The major work on the discrete case was done in the 30's by Wiener and Shannon.  So the age of the material is not an issue.  Quality  of instruction is.

The first lesson on the FFT should have explained the layout of the values in the frequency domain, how to determine the phase in  the complex plane, the effect of series length on frequency resolution and the relationship between multiplication and convolution between the two domains.  It should have also covered the periodicity outside the interval [-Pi:Pi), resampling by FFT and the need to pad the time series to prevent wraparound.

If you're spending money on this I strongly urge you to look elsewhere if those things were not done.  Such instruction is worse than useless, it misleads the student.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 11, 2018, 07:29:23 am
The Fourier transform goes back to 1810 although some of the mathematical details were not resolved until almost 100 years later.  The major work on the discrete case was done in the 30's by Wiener and Shannon.  So the age of the material is not an issue.  Quality  of instruction is.

If you're spending money on this I strongly urge you to look elsewhere if those things were not done.  Such instruction is worse than useless, it misleads the student.

My employer is wasting their money on this because qualifications are everything in this tin pot country and education standards have been reduced to the lowest common denominator.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 11, 2018, 07:32:56 am
In my new Excel, in getting that global 'x-offset' value of 270, turn off COSines #2 & #3, then align it so that the COS on the table starts like a sine.

COS( (270)*(50hz)*PI()/9000 ) =
COS( (13500 )*PI() / 9000 ) =
COS( PI()  * 1350 / 9000 ) =
COS( PI() * 3/2 )
COS( PI() * 1.5 )

Also, if you change all the COSines to SINes in my formula and make the multiplier for sine #3 a positive, the correct offset becomes 0.  Clearly a constructed waveform as the phases are perfectly lined up to a quadrant of PI.

Title: Re: Reconstructing a waveform from its harmonics.
Post by: rstofer on March 11, 2018, 07:36:55 am
Your courses are causing many of us to look back at things we might have known - four or more decades ago.  As well, we are looking at the new tools (Maxima, Octave, Matlab) and learning how much easier these problems are when using a computer as opposed to a slide rule.

I look forward to your homework problems.  They are helping me fill in some blanks.

Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 11, 2018, 07:38:26 am
I'm just going to do sine of the real parts and cosine of the imaginary parts on the 3 main frequencies which I think is what my "monkey see monkey do" course material coupled with the sazily laid out exercises seem to expect.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 11, 2018, 07:41:32 am
Your courses are causing many of us to look back at things we might have known - four or more decades ago.  As well, we are looking at the new tools (Maxima, Octave, Matlab) and learning how much easier these problems are when using a computer as opposed to a slide rule.

I look forward to your homework problems.  They are helping me fill in some blanks.

The thing is that I am not learning an awful lot here as it is reduced to "monkey see monkey do" and as evident from this thread it can take a combination of seasoned engineers to unravell the mess I am often given. Hopefully once I am through this and kept my employer happy I can start to learn to apply it properly.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 11, 2018, 08:19:39 am
So attached is the monkey see monkey do version. Next I will try the same with the corrected frequencies on a 50Hz fundamental.

Blue is using sine on the real parts, green is using cosine on the real parts, the blue seems to be right but out of phase
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 11, 2018, 12:14:00 pm
I was asked to sit on the external advisory board of the geoscience department where I got my MS.  During my 3 year tenure I tried numerous times to engage the faculty in a discussion of the mathematics requirements and very specifically asked about the mathematics component of the online courses in GIS that they offered.  I never got *any* replies.

But when I asked about the memorial fund to my MS supervisor in mid December, I got a reply in minutes.  What they did not know was that I had raised the subject with my supervisor several years before he died and he blistered my ears for suggesting such a thing.  The department had dropped mineralogy as a requirement so that kids could get "environmental sciences" degrees without being troubled by difficult subjects like what the earth was made of.  The most outrageous part was he taught all the hard rock courses.  I was one of 3 students in the igneous petrology class.  During  our labs he would sit and teach himself whole earth geophysics to prepare for the class he was teaching.  The stipend set up in his honor goes to students going into the oil industry!   I paid my way through grad school except for a \$500 stipend.  I went into the oil industry because when I graduated in 1982 there were no mining jobs in the US and very few anywhere else.  Ultimately I moved into reflection seismology and learned a lot of DSP.

Ultimately I concluded that the only interest the faculty and I had in common was my money.  I declined to give them any.  The faculty's sole concern was making the courses easy so that they would have lots of students and nice offices.  Actually teaching was not even on their radar.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 11, 2018, 12:34:23 pm
So attached is the monkey see monkey do version. Next I will try the same with the corrected frequencies on a 50Hz fundamental.

Blue is using sine on the real parts, green is using cosine on the real parts, the blue seems to be right but out of phase

SPOILER (you should have realized this by now):
For the correct final product, use sine for the fundamental, negative sine for the 5x tone, and sine for the 7x tone.

These phase differences are understood because:

3   0.848      -7463.29135403605-14445.5266079862i            15.87850   3.98478   52.734375
at 52hz, a - multiplied by a - equals a positive, so for the 50hz, add a sine.

14   1.126      -5940.59149956592+6735.79475621755i            8.77068   2.96153   246.093750
at 246hz, a - multiplied by a + equals a negative, so for the 246hz, subtract a sine.

20   -0.568      -1429.15358218379-6241.73751283557i            6.25319   2.50064   351.562500
at 351hz, a - multiplied by a - equals a positive, so for the 351hz, add a sine.

so, to construct the exact final waveform, this is all you need:
(50hz Sine at 15.9 magnitude) - (250hz Sine at 8.8 magnitude) + (350hz Sine at 6.3 magnitude)
Title: Re: Reconstructing a waveform from its harmonics.
Post by: amspire on March 11, 2018, 01:54:52 pm
Simon, with your course, ideally you do want fantastic teachers, but if you are expecting to learn this stuff by just listening, it will not stick anyway. Listening to a lecture will not make you feel comfortable or at home using the things you were taught now in 10 years time. If you can dive in and have some fun playing with the new ideas now, then in 10 years, you will think - "Great - Fourier Transforms - love it!".

You have to get in and start crunching numbers for yourself - just like people have done in this thread. We weren't even doing the course, but we had some fun. Build and test circuits. Every time you go into areas like Fourier Transforms, Laplace Transforms, Maxwell's Equations, Classical Filter theory, Bode plots and stability, Semiconductor Theory and so on it gives a new perspective to your understanding so you can start to see how electronics is working from new directions.

No matter how good or bad the lectures seem to you, if you can take the ideas from the current subject home and start to have some fun, you do start having some really big "Wow!" moments along the way and you do feel far more confident. You never want to let any course limit how much you learn. There is no reason why you can't be better then the lecturers - any lecturers. It is the same as thinking that no football player can ever be better then the coach.

There are plenty of Wow! moments with Fourier Transforms. If you put a pure sinewave into a circuit with terrible distortion, you get a mess out. But it looks very different when you look at a Fourier transform of the distorted output.

The lecturers are leading you on a path up a mountain, but it is up to you to look out at the ever-expanding view for yourself. It is your journey, not the lecturers. If you are staring at your feet the whole time you climb the mountain, you never see anything for yourself and you will never get much out of the course other then a piece of paper.

Richard
Title: Re: Reconstructing a waveform from its harmonics.
Post by: IanB on March 11, 2018, 02:25:05 pm
Yes I have seen that one, no math content but an interesting look

When you say "no math content" I am very much afraid you have missed the point.

For me, watching that video I saw 100% maths content. Maths is all about the concepts and ideas and how they lead to deeper insights. If you think of maths as equations, you are in danger of seeing engineering as lathes and drills instead of the products they produce.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 11, 2018, 02:42:14 pm
Sorry for  :horse: , but, here is the last Excel file, using strictly 3 sines, with the add or subtract amplitude values decoded from my above phase decoding.  The reconstruction is now such a close match, that the difference is within 1/10th an amplitude value.  Don't bother zooming in on the graph, it shows all red at any zoom.

You can now also individually edit the frequency of each sine wave.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Tomorokoshi on March 11, 2018, 04:38:14 pm
Sorry for  :horse:

Not at all. It's been very interesting to follow. Perhaps there should be an aliasing a dead horse icon?
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Tomorokoshi on March 11, 2018, 04:52:00 pm
You have to get in and start crunching numbers for yourself - just like people have done in this thread. We weren't even doing the course, but we had some fun. Build and test circuits. Every time you go into areas like Fourier Transforms, Laplace Transforms, Maxwell's Equations, Classical Filter theory, Bode plots and stability, Semiconductor Theory and so on it gives a new perspective to your understanding so you can start to see how electronics is working from new directions.

And those are just some of the topics you may encounter, although those certainly contain some of the highest densities of math. Going through school may seem to be slow now, but they are actually zooming through topics very quickly. It takes time to be away from that to realize just how much of a cursory approach there is to a lot of education, necessarily so because there is so much that has to be covered in just a few short years.

Try not to get too caught up on if your instructors are good or not. It's their individual style and capability. Some are natural educators, many are not. You will encounter those disparities in work also. Use the available resources to get up to speed on anything that isn't clear. This forum, their office hours, anything.

If it becomes the case that you would need to use any of those mathematical disciplines later on for a project, you are already at an advantage by knowing they exist; you can research their use later. If you need it for a job, you may get enough time to do it there. I've had projects that span 2 degrees worth of time.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 11, 2018, 07:43:24 pm
Yes I have seen that one, no math content but an interesting look

When you say "no math content" I am very much afraid you have missed the point.

For me, watching that video I saw 100% maths content. Maths is all about the concepts and ideas and how they lead to deeper insights. If you think of maths as equations, you are in danger of seeing engineering as lathes and drills instead of the products they produce.

I meant it is not explaining how to do much but more about how they work.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 11, 2018, 07:46:03 pm
Simon, with your course, ideally you do want fantastic teachers, but if you are expecting to learn this stuff by just listening, it will not stick anyway. Listening to a lecture will not make you feel comfortable or at home using the things you were taught now in 10 years time. If you can dive in and have some fun playing with the new ideas now, then in 10 years, you will think - "Great - Fourier Transforms - love it!".

You have to get in and start crunching numbers for yourself - just like people have done in this thread. We weren't even doing the course, but we had some fun. Build and test circuits. Every time you go into areas like Fourier Transforms, Laplace Transforms, Maxwell's Equations, Classical Filter theory, Bode plots and stability, Semiconductor Theory and so on it gives a new perspective to your understanding so you can start to see how electronics is working from new directions.

No matter how good or bad the lectures seem to you, if you can take the ideas from the current subject home and start to have some fun, you do start having some really big "Wow!" moments along the way and you do feel far more confident. You never want to let any course limit how much you learn. There is no reason why you can't be better then the lecturers - any lecturers. It is the same as thinking that no football player can ever be better then the coach.

There are plenty of Wow! moments with Fourier Transforms. If you put a pure sinewave into a circuit with terrible distortion, you get a mess out. But it looks very different when you look at a Fourier transform of the distorted output.

The lecturers are leading you on a path up a mountain, but it is up to you to look out at the ever-expanding view for yourself. It is your journey, not the lecturers. If you are staring at your feet the whole time you climb the mountain, you never see anything for yourself and you will never get much out of the course other then a piece of paper.

Richard

What teachers? what lectures? I have what appears to be lecturers note for module material and I study at home alone with no help. I have never been to the university itself. Apparently in the UK you can take a yea at uni at home around a day job.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 11, 2018, 07:51:11 pm
So attached is the monkey see monkey do version. Next I will try the same with the corrected frequencies on a 50Hz fundamental.

Blue is using sine on the real parts, green is using cosine on the real parts, the blue seems to be right but out of phase

SPOILER (you should have realized this by now):
For the correct final product, use sine for the fundamental, negative sine for the 5x tone, and sine for the 7x tone.

These phase differences are understood because:

3   0.848      -7463.29135403605-14445.5266079862i            15.87850   3.98478   52.734375
at 52hz, a - multiplied by a - equals a positive, so for the 50hz, add a sine.

14   1.126      -5940.59149956592+6735.79475621755i            8.77068   2.96153   246.093750
at 246hz, a - multiplied by a + equals a negative, so for the 246hz, subtract a sine.

20   -0.568      -1429.15358218379-6241.73751283557i            6.25319   2.50064   351.562500
at 351hz, a - multiplied by a - equals a positive, so for the 351hz, add a sine.

so, to construct the exact final waveform, this is all you need:
(50hz Sine at 15.9 magnitude) - (250hz Sine at 8.8 magnitude) + (350hz Sine at 6.3 magnitude)

I'm confused. the instuctions I was given tell me to divide the complex answers by the total amount of samples and use sin on the complex part and cosine on the real part and add the waves together....
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 11, 2018, 08:27:10 pm
I'm confused. the instuctions I was given tell me to divide the complex answers by the total amount of samples and use sin on the complex part and cosine on the real part and add the waves together....

Yes, putting a sine and cosine together, with identical periods in each like this, will manipulate the phase of your output waveform.

Ok, looking at only one Fourier component line in your Excel spread sheet, the 52.7hz line #3, tell me exactly how you would plot this one and only sine tone with the Fourier real & imaginary component which is currently in your spread sheet at sample #3:

Samp#  Data        Fourier component                                                Magnitude i^2                    Frequency
3           0.848      -7463.29135403605-14445.5266079862i            15.87850          3.98478   52.734375

I will add another column with your sine generator in my spreadsheet and additional color line on the reconstruction plot to compare.  (I'm off to bed now, I'll do it first thing when I get up.)  (LOL, we'll force Excel to do more...)
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 11, 2018, 08:32:07 pm
If I was using just a sine I'd have to calculate the angle from the complex result and use the modulus so I get the combined magnitude and the correct angle from one sine wave instead of combining the sine and cosine waves as shown in the course.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 12, 2018, 08:31:51 am
instead of combining the sine and cosine waves as shown in the course.
This is exactly what I asking you to give me, the combination of the 2.  I will plug in the formula you used into Excel to generate a new addition to the waveform display.  The idea here is to plot your courses method of reconstruction, for 1 frequency band, to see if that 1 sine result sits on the corresponding 1 frequency band which I have decoded with perfect phase.  Basically, since I have already perfectly decoded the 3 primary bands, I can turn off the other 2 bands and plot my 50hz in Excel on-top of your course's method to see if they are aligned.  Once done, we can switch to the 2 other sines individually and see how they line up, or skew, or be completely wrong.  The complex waveform you are regenerating can't give you this insight.

Summing the complete sine/cosine Fourier components should give the same results as other bands have no signal strength, except for those 3 spikes right up at the 18000hz.  You can also try your reconstruction ignoring all the bands above 9000hz.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 12, 2018, 08:43:02 am
The course suggests using individual cosine for real parts and sini for imaginary parts, there is a mention of calculating the modulus and phase angle as well. The problem here is that due to the lack of resolution in the frequency analysis there is that inaccuracy in pinpointing the peak frequencies so replotting with those will lead to a non perfect waveform with each cycle being different. I have described it in my answer as heterodyning.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 12, 2018, 09:47:28 am
So attached is the monkey see monkey do version. Next I will try the same with the corrected frequencies on a 50Hz fundamental.

Blue is using sine on the real parts, green is using cosine on the real parts, the blue seems to be right but out of phase

The construction of the your Blue line beginning at 0.25 is correct.  What you see to the left is like looking back in time.  This is still considered correct as the Fourier requires some number of samples in time to correlate the proper phase.

However, the amplitude is wrong by exactly half.  Either you reference sample data is 2x what it should be, or the Fourier was done wrong, or, when decoding magnitude, you need to double you output result.

Hint: The vertical axis title in your 'Waveform Spectrum' table in your Excel file is " i2  /amps2 ".  What do you think that '2' is after the amps.  I didn't write that, you did.  It is still possible that the mistake lies somewhere else.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: amspire on March 12, 2018, 10:18:39 am
What teachers? what lectures? I have what appears to be lecturers note for module material and I study at home alone with no help. I have never been to the university itself. Apparently in the UK you can take a yea at uni at home around a day job.
Are you saying you are not in contact with tutors? That would be tough. Still, for me, I always found courses really hard when I was just trying to catch up. Whenever I got ahead of the subject matter in my own time just through self interest, the course was easy and fun.

Are you going to attend the university after this year?
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 12, 2018, 12:47:46 pm
Export column 2 as a CSV to a.csv
Export column 4 asa CSV to b.csv

Start Octave.

A=fft(a);
plot( abs(A));
hold
# look at the plot
plot(abs(B));
# the amplitude spectra overlay to within roundoff.

You will see that the amplitude spectrum is symmetric about the 512th sample in the complex series.  The frequency values above the 512th value are wrong in the spreadsheet.

The truncation of the series, the fact that the sine waves are not multiples of the Fourier series frequencies and wraparound effects make exactly reproducing the time series from 3 sine waves impossible.  I suggest you sort the Fourier series by magnitude and then build up a plot adding the next lower magnitude frequency.  You can probably stop after 7 or 8 series.  Use 2*Pi*k/1024 for the frequencies where k is the sample index.  Those are the correct frequencies.  You can't actually convert to Hz unless you know what dT is.

I did all this in Windows 7 Pro using the official Octave binary and the Windows snip tool. Plus a bit of awk under Cygwin to extract the columns from the full CSV file.

The last plot is the 3 largest components of the Fourier series.  Each curve adds another component.  The individual components are not shown except the first.  The rest of the significant components are left as an exercise.

Hint:  Set all but the 4 largest components to zero and inverse transform.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 12, 2018, 07:47:30 pm
What teachers? what lectures? I have what appears to be lecturers note for module material and I study at home alone with no help. I have never been to the university itself. Apparently in the UK you can take a yea at uni at home around a day job.
Are you saying you are not in contact with tutors? That would be tough. Still, for me, I always found courses really hard when I was just trying to catch up. Whenever I got ahead of the subject matter in my own time just through self interest, the course was easy and fun.

Are you going to attend the university after this year?

I can email but that is not the same as being there and they can change with no warning. No I do not plan to actually go to uni. I am doing a HNC which is a year 1 uni course, then I can do a HND which is year 2, the third year gets you a degree, I dont know if I need to actually go there to do that but I plan to stop at a HND at most.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 12, 2018, 07:50:07 pm
So attached is the monkey see monkey do version. Next I will try the same with the corrected frequencies on a 50Hz fundamental.

Blue is using sine on the real parts, green is using cosine on the real parts, the blue seems to be right but out of phase

The construction of the your Blue line beginning at 0.25 is correct.  What you see to the left is like looking back in time.  This is still considered correct as the Fourier requires some number of samples in time to correlate the proper phase.

However, the amplitude is wrong by exactly half.  Either you reference sample data is 2x what it should be, or the Fourier was done wrong, or, when decoding magnitude, you need to double you output result.

Hint: The vertical axis title in your 'Waveform Spectrum' table in your Excel file is " i2  /amps2 ".  What do you think that '2' is after the amps.  I didn't write that, you did.  It is still possible that the mistake lies somewhere else.

The amps they give is the square. I made a column of amps. I used the Fourier transformed data for the graph, no idea that is without looking at it again.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 12, 2018, 11:44:41 pm
The spectral plot in the spreadsheet has been interpolated  with a sin(x)/x interpolator.  Many graphing programs do that when there are only a small number of samples in the display.  The displays I posted have not been.  The spreadsheet plot is actually closer to the true picture.  The actual peaks in the spectrum fall between the frequency domain samples.  You can also produce that result by zero padding the series and doing the transform.  Try padding the time series with 10240 - 1024 zeros and do the transform.

In any case the sums of 1, 2 & 3 terms are *exact*.  If you continue the result will converge to the time series to within round off error.

I've handed you 3/4ths of the answer.  I did so only because you were being misled by well meaning people who did not know what they were doing. I'm a retired PhD level  oil industry reflection seismologist.  I made a large part of my living by  knowing the Fourier transform *really* well.

Once you know the transform array layout and understand that sampling rate controls the maximum frequency of the result and the series length controls the spacing of the transform values all the rest is practice which I've not had since Octave went full MATLAB clone and the syntax I'm used to changed.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 13, 2018, 12:06:00 am
I used microsoft mathematics to do my graph so data points should not be a problem as I simply plotted sine and cosine curves with thos amplitudes and frequencies, obviously the lack of data points in the first place will make perfect reconstruction a challenge and require human input.

I was hoping to learn Fourier properly on this course bu in reality they have tried to come up with material that is a cut down version of the full story and then assignments that are easy to do so that I pass. My problem is that I overthink everything and expect to learn something. On future modules I probably wont waste my time on the material and buy my own books. As soon as I am done with this module all 1600 pages of it are going in the waste paper, I have or can buy better books that if anything have indexes.....
Title: Re: Reconstructing a waveform from its harmonics.
Post by: IanB on March 13, 2018, 01:37:31 am
I was hoping to learn Fourier properly on this course bu in reality they have tried to come up with material that is a cut down version of the full story and then assignments that are easy to do so that I pass. My problem is that I overthink everything and expect to learn something. On future modules I probably wont waste my time on the material and buy my own books. As soon as I am done with this module all 1600 pages of it are going in the waste paper, I have or can buy better books that if anything have indexes.....

I think you might be expecting too much from an HNC level course. Learning Fourier transforms properly would be quite painful for students on a degree course. At HNC level I imagine they are just trying to get across an appreciation of the concept with one or two practical examples to show how it works.

It's admirable that you are trying to learn it more deeply, but I doubt that is what is being expected of you.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 13, 2018, 03:51:23 am
I used microsoft mathematics to do my graph so data points should not be a problem as I simply plotted sine and cosine curves with thos amplitudes and frequencies, obviously the lack of data points in the first place will make perfect reconstruction a challenge and require human input.

I was hoping to learn Fourier properly on this course bu in reality they have tried to come up with material that is a cut down version of the full story and then assignments that are easy to do so that I pass. My problem is that I overthink everything and expect to learn something. On future modules I probably wont waste my time on the material and buy my own books. As soon as I am done with this module all 1600 pages of it are going in the waste paper, I have or can buy better books that if anything have indexes.....

The time series is reconstructable to numerical precision from the coefficients in the Fourier coefficients in the spreadsheet.  I verified that in the FFT plots I made.  The spreadsheet values exactly overlay the FFT done with Octave.  Therefore, if you do the inverse transform with all the spreadsheet coefficients you will exactly reconstruct the time series. Of the 1024 Fourier coefficients, only about 20 are needed to get very close to the time series which is the entire point of the exercise aside from the THD stuff which seems quite out of place to me, but I don't know what the course purports to teach.

I'm confused as to the origin of the spectrum plot in the spreadsheet.  It is *not* sampled the same as the Fourier coefficients.  Did you make the plot or was that provided by the course?

I think you will be way ahead if you buy 2-3 books on a subject, read them and *then* enroll in the course.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 13, 2018, 04:09:30 am
Here are some plots from Ronald Bracewell's 2nd edition which is arguably the classic textbook on the Fourier transform.

If you know the major transform pairs well you can usually do the transform in your head and draw it on a cocktail napkin by breaking the series into a sum of things for which you know the transforms.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 13, 2018, 04:13:11 am
And some more.  There's another page of them in the book.  Bracewell presumes a good understanding of calculus, but it's well written.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 13, 2018, 05:04:57 am

I'm confused as to the origin of the spectrum plot in the spreadsheet.  It is *not* sampled the same as the Fourier coefficients.  Did you make the plot or was that provided by the course?

I think you will be way ahead if you buy 2-3 books on a subject, read them and *then* enroll in the course.

They provided the graph, it populates itself when you run the excel tool (didn't I say something about "monkey see monkey do" ? yes it's that bad).

I have a couple of books now but no time to read them in order to keep up with the timescales I am already behind on and they seem to be closing an eye on it as kicking me off means losing a few thousand pounds, about 1000 a year.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 13, 2018, 05:13:56 am
I think you might be expecting too much from an HNC level course. Learning Fourier transforms properly would be quite painful for students on a degree course. At HNC level I imagine they are just trying to get across an appreciation of the concept with one or two practical examples to show how it works.

It's admirable that you are trying to learn it more deeply, but I doubt that is what is being expected of you.

The problem is I dont know how much I am supposed to learn, i was given a ton of math I struggled with and was then shown how to use excel. The problem is it feels a bit like a smoke screen and if I give an adequate smoke screen back i get a pass.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rstofer on March 13, 2018, 06:02:08 am

I think you might be expecting too much from an HNC level course. Learning Fourier transforms properly would be quite painful for students on a degree course. At HNC level I imagine they are just trying to get across an appreciation of the concept with one or two practical examples to show how it works.

It's admirable that you are trying to learn it more deeply, but I doubt that is what is being expected of you.

Yup!  Slide rules didn't help that much...  The problem wasn't in solving the integral, it was in visualizing the results.  3Blue1Brown does a magnificent job of this.

I had my grandson watch the video linked above.  He was stoked at the magic of being able to extract frequency components, which leads to using my signal generator and DS1054Z to display the FFT of a square wave and I'll probably duplicate the setup with my Analog Discovery 2 (better presentation).

My signal generator will add harmonics - I need to set up an experiment with that.  I can turn a harmonic frequency spike on/off at will!  I can even adjust the magnitude of the harmonics as well as the phase.  Wait till he sees this!

Simon, your homework problems are great fun, keep posting them!
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 13, 2018, 06:19:28 am
Yes I remember explaining the basis of fuorier to a friend and showing him a sine and its 3rd harmonic added together with a sig gen and scope to show the start of a square wave. then I went on to show it in a graphical calculator to the 40+ harmonic.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 13, 2018, 06:38:41 am
They provided the graph, it populates itself when you run the excel tool (didn't I say something about "monkey see monkey do" ? yes it's that bad).

I thought you created the spreadsheet, but this explains why things have turned out the way they did.  Either those who made the question deliberately thrown everything slightly out of whack on purpose, or, they thought that this example was the best choice of sample set & fourier size can achieve.  I doubt they were expecting you to sum all the first 100 or so fourier values unless they provided you with the instructional tools and software to do such a large set of points.

Very 'sneakily' within the hidden comment in cell 'J3' in the spreadsheet, there is a red arrow which only shows this 'comment' when your mouse is held on that point for a second, which then will exclusively tell you that your waveform's base is EXACTLY 50Hz.  I completely missed that and might have arrived at my solution much sooner if I knew that.  If I was doing a fourier here with this info, I'd do the fourier with only the first 720 samples instead of the full 1024 and would have had a perfect textbook 'monkey see - monkey-do' reconstruction first shot as the fourier frequency bands would hit perfectly on 50hz, 250hz, 350hz exactly.

(http://www.eevblog.com/forum/beginners/reconstructing-a-waveform-from-its-harmonics/?action=dlattach;attach=403171)
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rstofer on March 13, 2018, 06:39:44 am
Here are some plots from Ronald Bracewell's 2nd edition which is arguably the classic textbook on the Fourier transform.

Is this "The Fourier Transform and Its Applications"?

The year might be important because, according to Alibris, there are several editions starting in 1965 and working up to 2005 with prices from \$20 to \$400:

https://www.alibris.com/The-Fourier-Transform-and-Its-Applications-Ronald-N-Bracewell/book/2429291?matches=90 (https://www.alibris.com/The-Fourier-Transform-and-Its-Applications-Ronald-N-Bracewell/book/2429291?matches=90)
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 13, 2018, 09:40:26 am
Transform graphs to memorize:

boxcar <=> sinc

Gaussian <=> Gaussian

sine <=> positive and negative spikes

cosine <=> pair of spikes with same sign

squarewave <=> decaying series of odd order harmonic spikes

closely spaced spikes <=> widely spaced spikes

triangle <=> sinc**2

Hilbert operator

These are the things you have to deal with the most..  Other transforms popup from time to time, but generally you can get a pretty close approximation from some combination of these.  So if you're discussing it in the cafeteria or a bar after work you can convey what is going on.

I have The Fourier Transform and Its Application" 2nd ed.  I'm pretty sure they all have the dictionary of transforms.  It's one of the reasons it was so popular.  It's mathematically rigorous, though not at the level of "Operational Mathematics" by Churchill.  The latter consumed much of my life for two semesters.

Book prices have gotten crazy.  Publishers like to push out new editions even though they are not justified in order to obsolete older editions.  But it makes the old edition cheap.  If you're building a personal library that's the way to go.

As 720 is not prime, there are FFTs which exist.  However, the most common transforms are the radix 2 transforms popularized by Cooley and Tukey and those are restricted to powers of 2 lengths.  Prime factor routines will handle 720.  My favorite is an algorithm attributed to Glassmann. The FORTAN version is only two pages with lots of white space.  Probably the best is Dave Hale's prime factor algorithm which uses a series of tests to select the fastest transform larger than the input series.

I don't mean to beat up on anyone, but the proper way to address the coarse sampling in the frequency domain is to pad the end of the series with zeros.   Adding 19,456 zeros will give sub Hertz resolution in the frequency domain.  That will also make clear the implicit sinc function imposed by truncating the series to 1024 values.

I did 3/4ths of the problem because Simon was being misled. both by the person who prepared the spreadsheet and forum members who don't quite know as much as they think they do.

I ran an "orphan home for lost problems" at large oil companies.  My tools of the trade for a lot of it were Octave, gnuplot, awk and CWP/SU.  The latter is a seismic processing package.  I supported it for many years but got weary of John's renaming my contributions. I thought authors were entitled to choose the names of their own programs.   It's somewhat buggy, but it's the best of the lot. Madagascar has potential if Sergey ever gets after documenting and debugging it.  The function fit routine in gnuplot is the best Marquardt-Levenberg L2 solver  I've ever used.  If you know what you're doing it will fit things nothing else will short of a sparse L1 pursuit.  The latter being the current sate of the art method for a vast array of problems.  However, it makes the traditional Fourier-Wiener-Shannon math look simple.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 17, 2018, 03:50:57 am
Well I am sure you will all be surprised to know that I got a distinction on this assignment. Standards are really much lower than I thought. One question went unanswered and I blagged a few by explaining how I arrived at the answer without using the expected techniques.

My new module "digital and analogue electronics" looks like a bit of a joke from the assignments that I can mostly do without the study material.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rstofer on March 17, 2018, 04:04:34 am
Congratulations!

I have used Fourier Analysis exactly once since I graduated in '73.  I was looking at the 11th and 13th harmonics generated by a 10 MW 12 pulse rectifier.  It was interesting to get the expected FFT and not at all useful to the transformer manufacturer when I was questioning the heating effects.

Title: Re: Reconstructing a waveform from its harmonics.
Post by: rstofer on March 17, 2018, 04:15:10 am
I have The Fourier Transform and Its Application" 2nd ed.  I'm pretty sure they all have the dictionary of transforms.  It's one of the reasons it was so popular.  It's mathematically rigorous, though not at the level of "Operational Mathematics" by Churchill.  The latter consumed much of my life for two semesters.

Book prices have gotten crazy.  Publishers like to push out new editions even though they are not justified in order to obsolete older editions.  But it makes the old edition cheap.  If you're building a personal library that's the way to go.

I have bought quite a few used books from Alibris and some new ones.  As you say, the prices are completely out of sight for new texts.  For my grandson's library, we are buying all textbooks as 'new' and planning to hold on to them forever.  I still have most of my college texts and I wish I hadn't sold a couple of them.  I also have duplicate copies of his textbooks.  Gotta try and keep up!

I have a couple of years to brush up before my grandson gets to signal processing.  In fact, his proposed major of computer engineering may not even get that far; I haven't seen the entire curriculum.  What I have seen of the lower division stuff is 4 computer science classes and only one circuit analysis course.  I don't know what the upper division stuff will look like.

He's vacillating between computer engineering and civil engineering.  Robots or dirt work.  I know which choice I would make.

Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 17, 2018, 04:23:20 am
well I'm just skipping through resistor colour codes, so exciting this university level education.............
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 17, 2018, 07:04:33 am
He's vacillating between computer engineering and civil engineering.  Robots or dirt work.  I know which choice I would make.

Civil engineering has the advantage that much of it can't be sent offshore.

I'm of the opinion that whatever the field, an MS is needed to do professional work.  Traditionally the MS has always been the professional degree in  geology.  A BS would just get you a lab technician job. And by the time I was in school, law was also a 2nd degree field just as medicine had become.  Now I look at how much math you need for any engineering field and I just don't see any way that someone can learn that and learn an engineering discipline in 4-5 years.  Sadly, all the universities, even Stanford, are producing an increasing number of crap graduates.   And according to some, "rigor is racist", though I suspect they would not like the consequences of applying that to aircraft engineering.

I'm glad Simon got through his travails OK.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rstofer on March 17, 2018, 11:23:22 am
He's vacillating between computer engineering and civil engineering.  Robots or dirt work.  I know which choice I would make.

Civil engineering has the advantage that much of it can't be sent offshore.

This is true for all of the professional engineering fields.  An ideal career is one where you have to lay hands on the product.  Your field is also a good example!

Quote

I'm of the opinion that whatever the field, an MS is needed to do professional work.  Traditionally the MS has always been the professional degree in  geology.  A BS would just get you a lab technician job. And by the time I was in school, law was also a 2nd degree field just as medicine had become.  Now I look at how much math you need for any engineering field and I just don't see any way that someone can learn that and learn an engineering discipline in 4-5 years.  Sadly, all the universities, even Stanford, are producing an increasing number of crap graduates.   And according to some, "rigor is racist", though I suspect they would not like the consequences of applying that to aircraft engineering.

I'm glad Simon got through his travails OK.

I went through the same thought  process when I decided to go for an MSEE.  It was a sweet deal because my employer paid the bills.

One of the reasons for the 4 year internship for budding Professional Engineers is that you CAN'T really learn the profession in school.

There are a number of fields where rigor is required.  Nuclear (weapons or energy) is one of them.  Aviation, space flight (although there are stories...) and some others.  All of the professional engineering fields.  Automotive is another, we can't have steering wheels falling off - hey Ford!  Get it fixed!

Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 17, 2018, 11:51:43 am
Computer and electronics engineering can certainly be sent offshore.  They may not be any good, but they have "credentials".  I encountered a pair of Indian CS grads who spent 4 hours trying to redirect stderr from a program for which they did not have the source into a file.  They called to me as I was passing by.  It took me 5 minutes to write a program that wrote to stderr and stdout and a program to call it with stderr redirected to a file.

They'd been hired because a manager didn't want to hire me.  He told me to my face when we met at my interview.  He ultimately became my primary client in the company.  The Indians and everything they produced went away.  Unfortunately, India is not the only place producing such breathtakingly incompetent graduates.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rstofer on March 17, 2018, 12:13:11 pm
Computer and electronics engineering can certainly be sent offshore.

They can and they are.  Even with all of that, the Bureau of Labor Statistics shows phenomenal job growth in these fields.  I have been pushing a little toward robotics and I will eventually nudge toward AI.  That's where I see the job growth.  You will either work on robots or be replaced by them.  Even burger flippers are becoming an endangered species.

OTOH, many graduating engineers don't actually work in their major.  One chip designer I met had a degree in Astrophysics.  Here he was designing chips (I don't recall if he was doing analog or digital).  At the BS level, all you really know how to do is work the math.  Turns out, math is useful in just about every field.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 17, 2018, 12:39:38 pm
I'm a strong advocate of a liberal arts undergraduate program.  Not the fru-fru stuff popular now, but the liberal arts degree of 100 years ago which was roughly equal parts history, literature, mathematics and science.  My undergraduate degree was a bit short on math, just algebra and trig which bored me to tears as I had taught myself algebra in 5th & 6th grade and trig in 7th and 8th.  But lots of science and literature.  I read 4-5 full length novels a week.  About half were for a class and the others were because I'd read the author for a class and wanted to read more.  I made up for the math deficiency in my MS.  I was required to take Calculus I and it was so much fun I took II & III and DiffEq.  When I went to Austin fo pursue a PhD most of my effort was focused on math.  Now I look at "new" stuff and typically find it's just a familiar bit of math in new clothes.  Sparse L1 pursuits being the big exception.  It really is new.  People were doing it, but the rigorous justification didn't exist.  Much as it took the mathematicians a long time to  justify Fourier and Heaviside.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: BrianHG on March 17, 2018, 12:43:32 pm
Well I am sure you will all be surprised to know that I got a distinction on this assignment. Standards are really much lower than I thought. One question went unanswered and I blagged a few by explaining how I arrived at the answer without using the expected techniques.

My new module "digital and analogue electronics" looks like a bit of a joke from the assignments that I can mostly do without the study material.
Congratulations.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: amspire on March 17, 2018, 12:59:52 pm
My new module "digital and analogue electronics" looks like a bit of a joke from the assignments that I can mostly do without the study material.
It is pretty normal to have an introductory course in Electronics - not everyone who starts an electrical engineering degree knows what an opamp or a 2-input NAND gate is. Hopefully, you will quickly get into the real electronics design courses. From the 2nd year on, the course usually gets a lot tougher.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 17, 2018, 06:42:32 pm
My new module "digital and analogue electronics" looks like a bit of a joke from the assignments that I can mostly do without the study material.
It is pretty normal to have an introductory course in Electronics - not everyone who starts an electrical engineering degree knows what an opamp or a 2-input NAND gate is. Hopefully, you will quickly get into the real electronics design courses. From the 2nd year on, the course usually gets a lot tougher.

No I am doing a HNC, that is 1 year of uni. I wanted to do opamps, transistors, EMC and electronic design, but these are all level 5 modules and I am only allowed to do one for a HNC and the other 3 have to be level 4 which is the mamby pamby rubbish. I am just repeating my A levels........ once I am near the end I should speak to my employer about a HND (second year) and basically i just carry on to do another 8 modules presumably this time the level 5's are allowed.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 17, 2018, 06:43:59 pm
here, have a laugh on the UK education system.....
Title: Re: Reconstructing a waveform from its harmonics.
Post by: amspire on March 17, 2018, 07:59:33 pm
here, have a laugh on the UK education system.....
Pretty mind-numbing. The IC informations seems to be from the 1970's. 1 million transistors is a large scale memory chip and 1-100 million transistors needs a whole wafer.  :-DD

According to that table, a single 15 Billion transistor nVidia Tesla chip would need 150 wafers to make! I don't even want to think about the biggest ram and SSD chips.

I do hate exams based on courses like that because they usually do not want accurate answers. If they asked if a diode was an active or passive device and you said it can be both active and passive, you would probably be marked as wrong.

It did start to get into some actual formulae at the end.

Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 17, 2018, 08:06:13 pm
Well I am just reading about simetrix 6 with screenshots in windows XP, they do point out that the program might be a later version due to constant updates and indeed the version I downloaded is 8. It would be good to get to grips with "a" PSPICE program.

The first assignment i need to do is attached. the only question I can't answer off the top of my head I could probably learn about in 10 minutes on google.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: amspire on March 17, 2018, 08:58:01 pm
The nicest Spice program for beginners would be LTSpice. It is an excellent free tool.

http://www.linear.com/designtools/software/ (http://www.linear.com/designtools/software/)

I think there is a Student PSpice that can be used for free in a limited way.

The best opensource SPICE is probably ngSpice. There is a variant CUSPICE that can use recent models of nVidia GPU's to accelerate the calculations, but for the type of circuits in your course, Spice running on a CPU is totally fine.

Spice basically runs from a text file, and it may be your course will require you to run it this way.

The Spice with a GUI such as LTSpice automatically translate the circuit to a Spice text file, and automatically graphs the output. You can insert raw Spice directives from the GUI.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 17, 2018, 09:08:33 pm
They use simetrix which is similar to LTspice which I have also used and found to be unrefined and clunky. They explained the concept of the concept of the text file (netlist ?) but no they are not that archaic. They failed te explain clearly that PSPICE is the simulator core that a number of programs use and provide an interface to.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 17, 2018, 10:28:17 pm
is it me or are they making hard work out of explaining op amps ? never heard it called "open loop amplification" before.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 17, 2018, 11:03:14 pm
The explanation of the schmitt trigger comparator/op amp circuit is the most fucked up thing I have ever seen.........
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Mechatrommer on March 17, 2018, 11:04:10 pm
is it me or are they making hard work out of explaining op amps ? never heard it called "open loop amplification" before.
https://en.wikipedia.org/wiki/Open-loop_gain the graph plot usually available in most opamp datasheet. we can estimate the opamp respond at desired closed loop gain (i'm not sure i'm not EE at any Degree)

here, have a laugh on the UK education system.....
i know your pain. the material mostly for kids who are eager to learn something. for adult who has touched something, those materials will be boring. just be patience ;)

I wanted to do opamps, transistors, EMC and electronic design, but these are all level 5 modules and I am only allowed to do one for a HNC and the other 3 have to be level 4 which is the mamby pamby rubbish.
be carefull of what you expect. solely just designing some opamps and transistors can be learnt from home alone with internet. i will expect you will be faced with something like, stability compensation in phasor or laplace domain trying to solve all holes and poles in number equations. not for the faint hearted. you may as well join the club of Donna Riley's campaign... Rigor is not good! ;D Good luck!
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 17, 2018, 11:10:09 pm
But this is year 1 at university.......... i did all this in my A levels........ and the explanations are confusing at best. yes I know opamps in general and yes the stability analysis will be a challenge but for what else does one go to university ? With a thorough grounding in op amps I can design a low drop out regulator without it oscillating. As i am i rely on intuition.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Mechatrommer on March 17, 2018, 11:26:33 pm
As i am i rely on intuition.
we know you can design something, even military grade, but this is not how academic institutions work, take your time to get acquainted. ;)
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Mechatrommer on March 17, 2018, 11:38:18 pm
the only problem with education (at least at my place during my time) i saw is the facilitators, lecturers, teachers etc failed to relate what they are teaching with real life problems and application (contextual learning) but this is not entirely their fault, maybe due to lack of budget, time constraint, goverment or education policies etc. if someone can relate between theories and applications more, the gap between practitioners who never went to school, and students who never went to field can be closed together. having said that, practitioners should keep track what theories behind what they are doing to get some idea, students also should be exposed to real world field/work/problem environment more during their learning in college/university... the education is not at fault, usually the economy and politics is... imho..
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 17, 2018, 11:46:30 pm
yes well the problem in the UK is that universities have to self fund. and the government wants to trumpet how many more graduates they produced than the last administration so they allow a race to the bottom that solves both problems. the courses are easier so more students can complete them so the government get the figures they want and the universities get the money they need from students
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rhb on March 18, 2018, 12:11:31 am
The fundamental problem is the "everyone should go to university" model combined with the denigration of books in favor of electronic media.  So instead of the students having carefully vetted texts, they have sloppily produced videos and notes.  The result is ever more poorly trained graduates going out to train even more poorly trained graduates.  It's become a scam for the benefit of the faculty and staff.

Moreover, some people don't know the subject well enough to actually teach. I enrolled in an upper division  graduate level  electrostatics class.  The 2nd or 3rd meeting the instructor was deriving the equations for a charged particle in free space.   He was referring to his notes the whole time which is always a bad sign.  At one point he wrote out an equation which I didn't understand where it had come from.  So I asked him how he got that from the previous equation. "Oh, that's the way you do it."  After sitting in stunned silence for a few minutes I figured out that the transition was via a trig substitution.  I didn't need the course for anything.  I just picked it because it looked as if it would be interesting.  So after class, I went directly to the admin office and dropped the class. I did not get my doctorate because of a personality conflict that arose with my supervisor.  But a classmate who did not know Snell's law did get his.  I seem to recall he did a post doc at Stanford before finding a job.

The object of education is to convey the logic of the topic.  This guy was just writing his class notes on the board.  This was 30 years ago at UT Austin which is very highly ranked school.  I rather fear there are many more, even worse, examples now.

From your comments, you should definitely get a copy of "The Art of Electronics" and read it cover to cover a couple of times.   Don't bother with the problems on the first reading.  That's just for surveying the territory.  On the 2nd reading work selected problems and build circuits that interest you. Keep it all in a notebook with a sewn binding.  There's a lab manual for AoE, but I read that it is poorly edited and full of errors.  Read a bunch of articles  Jim Williams and Bob Pease wrote for EDN and other trade magazines.  Especially read, "Max Wien, Mr. Hewlett and a Rainy Sunday Afternoon".

Collect a personal library covering the material.  For example, get 2-3 books on op amps, 2-3 on network analysis, etc.  Look for books referenced by other books, especially H & H. I used to visit 3 used books stores every weekend when I lived in Dallas.  Over the course of 10 years I built a very good library doing that.  It's still a significant investment, but I've made my money back many times over.  The reason for multiple books is everyone leaves something out or bungles an explanation.  If you watch a really good professor as I have had the privilege of doing, they will cover the same thing from multiple few points during their presentation.

The ultimate goal is not to know the answer.  No one can remember everything.  The goal is to be able to find the answer to whatever questions come along.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: Simon on March 18, 2018, 05:16:30 am

The ultimate goal is not to know the answer.  No one can remember everything.  The goal is to be able to find the answer to whatever questions come along.

Maybe that is why they gave me a merit for using intuition instead of the techniques i was supposed to.
Title: Re: Reconstructing a waveform from its harmonics.
Post by: rstofer on March 18, 2018, 05:23:39 am
But this is year 1 at university.......... i did all this in my A levels........ and the explanations are confusing at best. yes I know opamps in general and yes the stability analysis will be a challenge but for what else does one go to university ? With a thorough grounding in op amps I can design a low drop out regulator without it oscillating. As i am i rely on intuition.

Another way to look at it:  Take the easy courses when you can.  There will certainly be more difficult courses coming along.
It's kind of like my grandson's Calc I homework.  In every problem set there are a couple of 'give away' problems that can be solved by inspection.  Then there are the 'other' problems that take an entire sheet of paper.  We chuckle when we get the 'give away' problems and whine and snivel over the 'others'.