# A game with Fourier coefficients/transform

1. Dec 19, 2011

### Bassalisk

So I am playing this game.

Guess the signal from its amplitude spectrum(FFT). Signal is periodic. I am currently playing with square wave and what are its characteristics. I am using MATLAB function square to do this.

I set the sampling to 500 Hz.

So above 250 Hz I get aliasing.

So far I got this:

When I use frequencies that are well below 250Hz, 150Hz for example, I get a clear delta in amplitude spectrum at 150 Hz.

http://pokit.org/get/c9a4f5cd7e2b0fc3d461c113f8c2e833.jpg [Broken]

Another example is for 100 Hz

http://pokit.org/get/821f8411db350e1ac31c2ec168251b68.jpg [Broken]

I concluded that at even Frequencies I get a delta in 0.(even frequencies like 100 120 Hz etc). Why is that?

And for frequencies between like 100Hz 150Hz I get all these little harmonics, like so:

http://pokit.org/get/e3ca4d9d81017657a4965ce5db9577d1.jpg [Broken]

Can anybody explain this to me? Why do I get these small harmonics? This is closely related to the sampling which is at 500 Hz, and most weird case of all:

At 240 Hz:

http://pokit.org/get/a49e3210ca2067d5b7a20ce61038d659.jpg [Broken]

I am completely baffled with these small harmonics!!!

Can any signal wizard, relate these small harmonics with sampling rate?

Thanks

Last edited by a moderator: May 5, 2017
2. Dec 19, 2011

### AlephZero

You explained it all yourself.

Find out what is the frequency spectrum of a square wave, and what aliasing does, and everything will be explained.

If you want to try to understand it just by drawing pictures, try setting the sampling frequency higher, e.g. about 20 times the signal frequency, and DON'T make the two frequences simple ratios of each other. Try something like 2000 Hz and 103 Hz.

3. Dec 19, 2011

### Bassalisk

Yes, when I don't make the simple ratios, I get all these small harmonics. And when the ratio is "nice" I get fewer harmonics.

Can you give me a clue why is this so?

4. Dec 19, 2011

### sophiecentaur

What you are seeing are not referred to as "harmonics" (which are multiples of a fundamental frequency). They are referred to as alias components.
There are fewer visible components when there is a simple ratio between sampled and sampling frequencies because many of them occur at the same frequency. When the frequencies have a more complicated relationship, all these artefacts occur at different frequencies so each one is visible in its own right.
If you do this in real time, you can see the products moving about, combining and splitting as you change the frequency of the sampled signal.

5. Dec 19, 2011

### AlephZero

Did you try the numbers I suggested? If you did, you should be able to see the "genuine" harmonics of the square wave (at 1, 3, 5, 7 ... times the fundamental frequency, with amplitudes 1, 1/3, 1/5, 1/7, ....) and also see how the harmonics that don't fit on the plot are "reflected off the ends of the plot", which is called aliasing.

The pictures you already posted are probably misleading you, because the two different things are too mixed up together and sometimes several different "peaks" are plotted on top of each other, so you can't easily make sense of the plot.

6. Dec 20, 2011

### Bassalisk

Yes I did. I am trying to interpret the graphs. I noticed some things about aliasing. Just I need to understand, somehow WHY do these small harmonics occur like they do.

Sophie said its because aliasing, just need to understand how is that happening, why all those small components.

7. Dec 20, 2011

### sophiecentaur

Try calling them spectral components. Not all spectral components are harmonics!.

When you sample a signal you are effectively Modulating the sampling signal with the signal that is being sampled.

If you Amplitude Modulate an RF sinewave (a 'carrier wave') with another sinewave (a much lower frequency signal, often referred to as the baseband signal), the resulting spectrum will be a peak at the carrier frequency with two sidebands, spaced above and below carrier frequency and separated from the carrier by the modulating sinewave frequency. Ordinary AM signals have identical (mirror image) upper and lower sidebands with the same spectrum as the baseband signal.

Sampling can be looked upon as modulating, not an RF sinewave but a high frequency string of pulses or even squarewaves with the baseband signal. The string of pulses will consist of a 'comb' of harmonics (using the term in the correct context here) and when you modulate it, each of the harmonics will have sidebands. The baseband information is duplicated as sidebands on each of the harmonics.

If you reduce the sampling frequency to the point where the spacing between its harmonics is smaller than the maximum frequency of the baseband signal then the structures will start to overlap and sometimes the lines will coincide (so some will seem to have disappeared). When you want to reconstruct the original signal from the samples, the components are all mixed up. The term 'foldback' is sometimes used because the high baseband frequencies can turn up as low frequency 'aliases'. That's why they say (Nyquist) that you must always sample at at least twice the highest frequency contained in the baseband signal if you want to avoid the possibility of aliasing.

If you are starting with a baseband signal that is a square wave, it will have a complex spectrum with many harmonics which will extend way up to the sampling frequency. If you sample it without some pre-filtering (Nyquist filtering) then you will get aliasing. Start with a sinewave at baseband and then a low-pass filtered squarewave. This should then start to make sense.

Sometimes - or even always - it is better to invest in some basic theory before launching into simulations. Maths has no 'common sense' and only does exactly what you have told it to do! Numerical analysis can be even worse.

8. Dec 20, 2011

### AlephZero

The don't "occur". They aren't real. They are just an artefact of the way you are processing the data. If you want to use FFTs to do anything serious, you filter them out of the data before you do the FFT.

Make a table of sin(0.1t) for t = 0, 1, 2, 3, .....
Repeat, for sin(-0.1 t)
Repeat, for sin(6.38318 t) (6.38318 = 2 pi + 0.1)
Repeat, for sin(6.18318 t)

That's all there is to it. If all you have is the sampled data, you can't tell the difference between sine waves at 0.1 Hz and 6.38318 Hz (or 2 k pi + 0.1 Hz for any integer value of k). The FFT algorithm can't tell the difference either.

9. Dec 20, 2011

### Bassalisk

All that you said, I am very familiar with. Why aliasing happens etc. The question had hard base with understanding Discrete Fourier transform.

Assistant explained it to us today, why do we see all those little components even though a square wave has only non-even harmonics.

Turns out that this happens:

http://pokit.org/get/a239350497d574772f569e47b4bbc8e9.jpg [Broken]

This only happens if the frequency is just right, sometimes they overlap perfectly and we get all uneven.

I will study this further and tell you the results.

Although the theory it self is very important, and we can't live without the basics, sometimes a view from a another angle helps you see things others wouldn't normally. I am determined to pursue my BSc in studying just signals, because they are fun and a lot of things from around you can be explained with them.

Last edited by a moderator: May 5, 2017
10. Dec 20, 2011

### jim hardy

that's what makes digital oscilloscopes frustrating.

i think Mother Nature is analog.

11. Dec 20, 2011

### Bassalisk

Not once I found myself laying around and thinking how would computers look like if we made them work with analog signals.

But still, Planks Length? Constant? Its sad that our universe is discrete...

12. Dec 20, 2011

### Studiot

Hello, Bass and congrats on your random award - you deserve it.

A few thoughts, extending your Fourier game.

Firstly distortion is any unwanted signal that was not present in the input, but appears in the output.

It used to be taught (wrongly) that any difference could be represented by Fourier analysis.

This is not true.

I suggest you look up

Intermodulation Distortion (first cousin to the aliasing Sophie C mentioned)

Transient Intermodulation Distortion

Slew Rate Limiting.

Further is is again often (wrongly) taught that an infinite Fourier series will add up to a perfect square wave.

Again this is not true.

Here I suggest you look up Gibbs Phenomenon.

go well

13. Dec 20, 2011

### Bassalisk

Thank you. I will do that. I am building this image of how signals and systems work, and each day I learn something new. This slew rate, I saw that somewhere at op amps, but it was too advanced for me to understand at the point I saw it.

Transient intermodulation. Hmm can I take a wild guess?

I've learnt that there exists something called passband. Is overlapping of these passband, transient intermodulation? (This is strictly out of my intuition, probably wrong)

14. Dec 20, 2011

### sophiecentaur

Is this anything more than yet another example where the use of discontinuities in a mathematical treatment of a physical situation gives a non-physical / practical outcome? This is another reason to treat the bare results of Matlab etc with respect, if not suspicion, I think. Suitable pre-filtering of a signal, before modulation / analysis / sampling etc. is an essential consideration.

15. Dec 20, 2011

### jim hardy

ahhh,, one of my old musings too.

i wondered , what if somebody had followed Bool and developed a base three algebra?

There's no reason to limit logic to simply two states, why not use three - "TRUE" (1), "FALSE"(0), and "DON'T CARE"(indeterminate). We already have tri-state buffers so the hardware is already here. Base 3 computing will simplify artificial intelligence because it mimics human logic - yes, no, maybe....

Well now, once we exceed two logic levels it's only natural to push onward to an infinite number of them , and voila - we're back to the analog computer of the 1940's only with better electronic integrators.

Do they still teach analog computers? That was my favorite lab and in early 60's the fastest electronic way to solve differential equations.

So is the universe really discrete? I say it's just as with Heisenberg's principle of indeterminacy - there's doubtless shorter distances than Planck length just you can't measure them..

old jim

16. Dec 21, 2011

### Bassalisk

I am not familiar with courses where they teach analog computers. But yes, that maybe state or "don't care state" would be useful. But I think they couldn't make one at the time. 1 and 0 was a holy grail. And mathematics was worked out for it, quite nicely at the time(I think).

17. Dec 21, 2011

### sophiecentaur

Binary logic and arithmetic are not 'fundamental, by any means. They were almost an arbitrary choice in modern computers - based on the fact that the circuitry is so convenient. Many logical problems have to be re-arranged before they can be solved just with binary logic - hence the frequent use of 'IF trees" and "Case statements", or equivalent, in computing languages.

Look back to the mid 20th Century and you will see there were many calculating machines based on decimal units and, when you get into a house hallway, there are usually more than just two doors.. . . . In fact, most real life choices are more than binary.

18. Dec 21, 2011

### Studiot

I know we are wandering, but the purpose of tristate circuitry is simple.

If we have two logic outputs connected to one logic input and one output tries to go low and one high what happens?

Alternatively if a single logic output can only assume high or low and is connected to two logic inputs it will always activate/deactivate both inputs .

Either situation can be avoided by having a don't care (actually high impedance) state that doesn't trigger following inputs or fight with other connected outputs.

19. Dec 21, 2011

### sophiecentaur

The scenarios you are suggesting are no longer 'Logic' but the resulting output will depend upon the particular technology involved.

20. Dec 21, 2011

### jim hardy

hmmm turns out somebody did it , waaay back when...

http://en.wikipedia.org/wiki/Ternary_computer

et al