Practice English Speaking&Listening with: Sampling, Aliasing and Nyquist

Normal
(0)
Difficulty: 0

Hi this is Dan Bullard with another instructional video this time on

sampling aliasing and Nyquist. I've been teaching sampling for years and years

and I understand aliasing better than most people in the electronics industry

so this time I'll try to show you how ailasing really works and why there are

important constraints on sampling. We'll start with an overview of sampling. In

order to sample you must know the sampling formula. The ratio of the test

frequency to the sample frequency is equal to the ratio of the number of

cycles of the test frequency to the number of samples or math form Ft

over Fs is equal to M over N. In our formula Ft is the test frequency,

that is the waveform we're going to use to test our device or our circuit. Fs

is the sampling frequency, that is how fast we're going to run the sampler. M is

the number of cycles of Ft and N is the number of samples. Let's start off

with a really simple example. Here we have a single cycle of a 1 megahertz

waveform and we want to capture 16 samples. In order to capture 16 samples

of a 1 megahertz waveform in just one cycle, we're going to have to capture at

what frequency? The answer is obviously 16 megahertz since we'll have to run our

sampler 16 times faster than the test frequency in order to capture 16 samples

over just one cycle of the test frequency. Let's try changing our M to 2

now, so we're going to take 16 samples over 2 cycles of our 1 megahertz

test frequency. Take a close look at the first cycle of the waveform. You can see

there are 8 unique samples, but the second cycle has 8 samples that are

identical to the first set. That makes that second set of samples

redundant. In other words, if M and N are not Mutually Prime, and 2 and 16, that is

an M of 2 and an N of 16 are not mutually prime, then some of the samples

will be redundant. The true number of samples can be found by reducing the M/N

ratio to the least common denominators. There is a reason to use redundancy

though, for waveform averaging which can be used to reduce noise by taking

multiple passes of the waveform. It separates the quantizing noise from

other noise and each doubling of samples reduces noise by 3 dB, so there is a

benefit to using redundancy, there is a benefit to taking a redundant set of

samples; you can reduce noise, which can be cheating if you're doing

signal-to-noise measurements, but there are also many many downsides, and that's

really the point of this whole instructional video; to show you what the

true downside is of using an M and N that are not Mutually Prime. Now let's

see what happens when we change our M to 3, that is we're sampling the same 1

Megahertz signal, we're going to still take 16 samples, but we're going to do it

by capturing 3 cycles of the waveform, so what will be our sample frequency? How

fast do we have to sample in order to capture 3 cycles of the 1 megahertz

signal instead of just one cycle? Well if you do the math, and you do that by cross

multiplying by the way, so 1 megahertz times 16 divided by 3 is 5.333

Megahertz, so we actually get a slower sample rate if we can capture more

cycles of the waveform. By the way, take a good close look at those 3 cycles of the

waveform. You'll notice that all 16 samples here

are unique, there are no redundant samples, so when M and N are mutually

prime you have no redundancy and so you don't have the issues that we had before

with an M of say 2 and an N of 16. Now let's try spreading our samples out even

more. We capture 16 samples over 7 cycles

of the 1 Megahertz waveform and the sample frequency calculates out to

2.29 Megahertz. Recognize that every time M goes up Fs goes down,

which is what you'd expect. Notice also that in this particular case, there's

pretty close to about two samples per cycle.

If you count it out in the first cycle you'll find there's three samples per

cycle, but in other cycles there's only two, so we're really close to having two

samples per cycle and Nyquist said something about that. Another guy named

Shannon said something about that, you might not quite remember those but we'll talk

about that later. When M is about half of N then you're going to have about two

samples per cycle. OK, we're going to keep pushing M up so we're going to

take our 16 samples over 9 cycles of the 1 Megahertz waveform, and

that makes our sample frequency drop down to 1.777 Megahertz.

Now our sample frequency isn't even twice what our test frequency was,

and again, you might remember something about Nyquist or Shannon saying

something about those things, and again we have about 2 samples per cycle

because M is about half of N, so the first cycle has about 2 samples, the

second cycle has about 2 samples, the third cycle how's about 2 samples, but

look at the center one, the one cycle right in the middle has only 1 sample,

so actually we have less than two samples per cycle.

So we're disobeying some law that Nyquist or Shannon or one of those guys

came up with. OK, let's push it a little higher, we're going to take it

all the way up to 15, so we're going to capture our 16 samples over 15 cycles of

our 1 Megahertz waveform, and we do the math and it comes out to a sample

frequency of about 1.07 Megahertz. Now, looking at this you might notice

something very interesting: It looks as though our samples are describing a

single cycle of the waveform but upside down, it's actually in reverse order. The

samples are actually in reverse order of a single cycle waveform. That's because M

is just under N. Take a wild guess what happens

if we push M to be 1 over N. So now with an M of 17 and we get again a single

cycle in our samples but it's in forward order! So when M is just 1 over N, we get

a forward ordered single cycle version of the waveform. When M is 1 under N, we

get a backwards or inverted version of the waveform. Now back to the example of

M equals 17. Notice that our sample frequency is now

below our test frequency at 0.94 Megahertz. That is incredible! We're now

sampling slower than our test frequency, and yet the signal is still visible. This

is called aliasing. It's not really the signal, it's the alias of the signal. It's

not exactly the signal that we were looking at, it just so happens that the

samples fall in an order that makes it look like we're seeing the signal in a

single cycle. This is one way of looking at aliasing, but there's a better way:

Looking in the frequency domain by performing an FFT. Passing a sampled,

time domain waveform to a Fast Fourier Transform, otherwise known as an FFT, will

result in the following: The resulting spectrum will contain N/2 + 1

spectral lines, also known as frequency bins. The spectrum will have a resolution

of Ft over M, or Fs over N. Bin 0 will contain the absolute DC offset.

Bin M will contain the peak amplitude of Ft. The harmonics of Ft will

appear in multiples of bin M. And all other bins will contain any noise

captured. With this diagram I can describe what an FFT does for you. Across

the top you can see what appears to be 9 cycles of a slightly distorted sine wave

that contains 512 samples. From sample number 0 to sample number 511. When we

perform an FFT, we get a spectrum of the waveform containing N/2 + 1

spectral lines also known as frequency bins, numbered 0 through 256. Bin 0 contains

the amplitude of the DC offset. Bin N/2 is called the Nyquist

Frequency which is on half the sample frequency, Fs. This bin is not very

useful, as you will soon see, so be careful not to allow any signal you care

about to fall into this bin. Because the time domain version of the waveform

contains 9 cycles of the waveform in the spectrum, we get the amplitude of the

fundamental frequency in bin M, in this case bin 9. Any second harmonic

energy falls into being M*2 or bin 18, because that is where

Ft*2 would fall. Any third harmonic energy would fall into bin M*3

or bin 27, because 3 times 9 is 27. You can imagine that this would be very useful

for finding Total Harmonic Distortion otherwise known as THD, because all you

have to do is set up a simple loop to scan the spectrum for any amplitudes in

multiples of bin M, because harmonics of Ft will be located in those bins.

You can look for 2 harmonics, 3, 4, 5, however many you care about simply by

setting up a loop terminator to look at all harmonics up to the highest number.

you care about. Any noise captured in the time domain waveform will be spread

across all bins, even the signal and harmonic bins. This is one reason to push

N, the number of samples as high as possible. More samples means more bins

for the noise to go into and the more accurate your signal measurements will

be because there will be less noise per bin polluting the signal bins. Of course

the noise bins themselves are valuable: You can easily calculate the signal-to-noise

level of this waveform by summing up the squares of the amplitudes of

every bin except the signal and harmonic bins, and taking the square root of the

sum of the squares, that is your total noise. Zooming in near the fundamental

bin you can see the graininess of this spectrum. That graininess, or spectral

resolution, is determined by how long it took to capture our sample set. The

longer we capture, the finer the resolution. How long we sample, known as

the unit test period, is determined by how many samples we take divided by the

sampling frequency, the reciprocal of UTP is known as a Fourier Frequency and that

controls our bin spacing. Also of course, bin spacing is controlled by our test

frequency divided by of the number of cycles. if you want very

fine resolution in your spectrum, you'll have to set M very high for any given

test frequency. Sampling your test frequency over a very large number of

cycles will take a long time. The reciprocal of that time,

UTP, defines the resolution of your spectrum. Want a 1 hertz resolution?

Juggle the sampling formula to allow you to sample for 1 second. Want 1/10 hertz

resolution? Sample for 10 seconds. You can get any resolution you want as long as

you're willing to wait for it. Of course don't forget that better resolution may

mean setting the number of samples to a very large number and every one of those

samples will have to be processed by a computer somewhere and that could take

a very long time indeed. Now we know how an FFTt works, let's take a look at an

example waveform that I created. It has a fundamental in bin 1 because

again M is 1 and it has a third harmonic which squares up the waveform.

Remember that a square wave is actually the sum of the fundamental, the third

harmonic, the fifth harmonic, the seventh harmonic, the ninth harmonic; that creates

a square wave. I've removed all but third harmonic, so we have a squared up

waveform. You can see in the spectrum I have an amplitude at bin 1, that is

bin M and in this case N is 32, and I have a smaller amplitude signal at

bin 3, that is the third harmonic that tends to square up the waveform. Now in my

spectrum diagram across the top of the page, I show that I'm going from bin 0

to bin 2*N, or from the DC bin up to bin 2 *Fs, but that's not

really the case when you do an FFT. Remember when you do an FFT you only get

bins 0 through N/2, so that area from DC to F/2, that's called

the Nyquist band, and you're not allowed to see anything beyond that, but I'm

going to fake it a little bit and show you what happens in the higher

frequencies and show you how alasing really happens. Like we did before we're

going to push M up, so here we push M up to 2. We now have 2 cycles of the

waveform, which means that when we do the FFT the

fundamental goes into bin 2, but that also causes the third harmonic to go up

to bin 6, so the third harmonic moves up at about 3 times the rate as the

fundamental. We'll have to watch out for that. Now we push it up to 3 meaning

that we have 3 cycles of the waveform. The third harmonic however is

now up to bin 9 now. We push M up to 4, so now the fundamental appears in

bin 4 of the spectrum, and of course the third harmonic shows up in four

times three or bin 12. It seems like we're going to be in trouble if M goes

up any higher because then the third harmonic will go beyond bin N /2

and will disappear. Now we push M up to 5 which means that the third harmonic

is in bin 15, right on the edge of the Nyquist bin. Remember that our N is 32 in

this case, which means that N/2 is 16, so the Nyquist bin is in bin 16 so, if

M goes up any higher, we're going to lose the third harmonic, it's going to leave

the Nyquist band. Now we push M up to 6, and look what happened! The third

harmonic went up to three times 6 or bin 18, which is higher than bin N/2

and in its place we got an alias, which is at a different place but it

represents the amplitude of the third harmonic. It's just that it's in the

wrong place which makes it an alias. So because the third harmonic has moved

beyond the Nyquist band it's in bin 18, but our Nyquist band only goes from bin

zero to bin 16, then what bin is the alias in? Well luckily you've got Dan's

rules to work it out. I developed these rules on my own, they specify how you can

tell which bin the alias went to. The diagram at the top shows the Nyquist

band from DC to Fs/2 also DC or bin 0 to N/2, that's where the

Nyquist band is and that's all you ever see when you do an FFT. Beyond the

Nyquist band are other frequencies, but we just can't see them in the spectrum when we

do our FFT. But anything up in those areas will show up in the Nyquist band,

so as the note says there, anything that appears in these bands folds back into

the Nyquist band, they fold back, and you may have heard of that term, so anything

that appears in these areas that's invisible will appear in the Nyquist

band and that's the problem. Anything that appears up in this area will fold

back into the Nyquist band and pollute it and make it difficult for us to sort out

which thing is which. OK, I only have two rules. Dan's aliasing rule #1

says; if the bin is greater than N, then the bin is equal to bin modulo N. Modulo

is the remainder operator, so in our case the answer to this question is no, in

other words, is 18 greater than 32? The answer is no, so we don't calculate the

modulo operator yet. The next rule says; if the bin is greater than N/2,

bin is equal to N-bin. In other words, is 18 greater than 16? And the

answer is yes! So what does that mean? That means that we calculate our alias

by calculating N-bin. So what is 32-18?

32-18 is 14, so going back

to the original diagram where you can see that our third harmonic is 2 steps

above 16, our alias is 2 steps below 16, and that's what's meant by folding back.

It actually bounced off of the Nyquist frequency, or folded over, folded back so

two steps above N/2 becomes 2 steps below N/2, so our alias

happens in bin 14. OK, let's see what happens when we push M up to 7, so

the fundamental is in bin 7, that means the third harmonic is in 7*3

or 21, but again 21 is not in the Nyquist band, and you can

see the alias, but what bin is it in? So back to Dan's aliasing rules.

Dan's aliasing rule #1 says; if bin is greater than N then bin equals

bin modulo N. Is 21 greater than 32? The answer is no, so that one doesn't apply.

Dan's aliasing rule #2 says if bin is greater than N/2, bin

equals N-bin. That one is true, so the alias is going to be in bin 11.

So now if we go back to the original diagram, you can see that while the

fundamental is in bin 7 and the third harmonic is way up and bin 21, the

alias of the third harmonic is down in bin 11. So as we keep pushing M up,

the fundamental will keep going up, the third harmonic will keep going up, but the

alias of the third harmonic will keep going down. So as we take M up to 8,

notice that the fundamental is in bin 8, the third harmonic is in

3*8, or bin 24 and the alias of the third harmonic appears to also be in

bin eight. Now that's a problem and that's why M and N must be mutually

prime. In this case M is 8 and N is 32,

they have a common divisor. 2! If you do that, look what happens! The amplitude of

the fundamental is now in bin 8, and the amplitude of the third harmonic's

alias is also in bin 8! They're going to cancel each other out to some degree,

and that's the real reason why you don't want common divisors between M and N.

Let's go back to Dan's aliasing rules just to make sure we understand how they

work. Again rule #1 says if bin is greater than N, bin equals bin modulo N.

Is 24 greater than 32? That is, is the third harmonic of the

fundamental, 3*8 is 24, so is 24 greater than 32? The answer is no.

So then, is bin greater than N/2? Yes it is, 24 is greater than 16 so

32-24 is 8, so the third harmonic will fall in bin 24, but the alias of the

third harmonic will fall in bin 8. Unfortunately, that bin is already

occupied by the fundamental. Now the amplitude of the

fundamental is being corrupted by the amplitude of the alias of the third

harmonic that's why we can't have common divisors between M and N. Now, earlier we

talked about reducing M and N to common divisors. So here we have an M of 8 and

an N of 32, but they have a common divisor, 8. So we can reduce it to an M of

1 and an N of 4. That's an effective N of 4, so that means out of our 32 samples

only 4 samples are unique. The rest are redundant, so the second

four samples are redundant to the first, the third four samples are redundant to

the first, and so on. That means that our number of bins is not what we think it's

going to be. Normally, the number of bins is equal to N/2+1, so we would

assume that we would have 16 unique bins plus the DC bin, but in fact the number

of effective bins in this case, because our effective N is 4, our number of

effective bins is 4 divided by 2 plus 1 or 3! So there are actually only 3

bins for things to go into. DC, that is bin 0, the fundamental bin which will be

bin 8 and then the Nyquist bin, which is bin 16. There's no place else for

any of the signal amplitudes to go! Now we're already in trouble with a waveform

that has only two signals, the fundamental and the third harmonic, but

imagine it was a square wave or some other strange waveform with more

harmonics? What would happen? Remember, there's only three bins where things can

go, so in this chart we're showing that Ft goes in bin 8, the second

harmonic, if there was one, would go into bin 16 the third harmonic we know

already goes in bin 8 and that's already occupied. I showed that as red to show

that it interferes with Ft. The fourth harmonic would go ito bin zero.

Oops that's a problem, because now we don't really know what our DC offset is,

if there is a fourth harmonic. The fifth harmonic falls into bin 8, the six

falls in bin 16, the seventh goes into bin 8 and so on. The problem now

is we've only got really three unique bins

for things to go, any harmonics will corrupt virtually anything in our

spectrum! So you want to avoid using an M and N that have common divisors, that is you

want mutually prime M and N, but some people take that to mean that you need M

to be prime. That's not the case. Here's an M that is not prime, an M of 9.

Let's see what happens with an M of 9. We end up with the fundamental in bin 9,

and the third harmonic falling in bin 3*9 or bin 27.

we can see in this diagram the alias of bin 27, the third harmonic falling back in

the Nyquist band, but it doesn't seem to have fallen on top of the fundamental.

But let's figure out where it went and why. So back to Dan's aliasing rules.

Again rule #1 says; is bin greater than N? Is 27 greater than 32? The answer is no.

So on to rule #2, is 27 greater than 16? Yes it is, so we calculate

32-27 which equals 5, so that's where the third harmonic went It aliased back into

the Nyquist band into bin 5. So our third harmonic aliases back into the Nyquist

band but didn't fall on our fundamental, and that's a good thing. But could there

be other harmonics that fall onto our fundamental? M is not prime but it is

mutually prime with N. Does it have to be prime? Let's take a look at another chart.

Here we show our M is 9, Bin 9 is where the fundamental is, Ft, the

second harmonic, if there was one, falls into bin 14, after obeying Dan's aliasing

rules 1 & 2. The third harmonic we know that falls in bin 5 after we go

through Dan's aliasing rules 1 & 2. If there was a fourth harmonic, it would

fall in bin 4. So far, none of them have fallen back into bin 9. If there was a

5th harmonic it would fall into bin 45, and then Dan's aliasing rules show that

it would drop back into the Nyquist band into bin 13 again nowhere near bin 9

the sixth harmonic would fall in bin 10, the seventh harmonic would fall in bin 1,

the eighth would fall in bin 8, so far no repeats. The ninth harmonic

would fall in bin 15, and so on and so forth. Notice that there are no repeats

in these charts, when there are no repeats the text for the bin is in black

so everything falls in its own unique bin as long as M and N are mutually

prime, but M is not a prime number, and still we don't have any repeats in our

bins. So M doesn't need to be a prime number,

it just needs to be prime relative to N. OK let's take M up to 10. Now with an

M of 10, the fundamental drops into bin 10, the third harmonic you can see it way up

there around bin 30. So it will alias back into the Nyquist band, somewhere.

You can take a wild guess, but it looks like bin two. But let's find out, so first

question is bin greater than N? 30 is not greater than 32 so no. Is 30

greater than 16? Yes, so Dan's aliasing rule #2 takes effect. 32-30 is 2

so yes indeed, that alias did fall in bin 2. Now, 10 is

not a prime number and it's not mutually Prime with N, so let's talk about

reducing M and N again, so with an M of 10 and an N of 32, we reduce that down

to an M of 5 and an effective N of 16. We still have 32 samples but the first 16

will be unique, the second 16 will be redundant. Now we know our number of bins

will be N/2+1, so our number of effective bins will be 16/2+1

or 9. So back to our chart of harmonics. Ft falls in 10. If there was a

second harmonic would fall in bin 20, but bin 20 is beyond bin 16,

so that'll alias back into bin 12. The third harmonic we already know went out

to bin 30 and that alias is back in the Nyquist band in 2. The

fourth harmonic drops into bin 8. The fifth harmonic goes into bin 14.

The 6 harmonic goes into bin 4. The seventh harmonic goes into bin 6,

and the eighth harmonic goes into bin 16. Now notice the

ninth harmonic also goes into bin 6, just like the seventh harmonic did. Those

colors match. The tenth harmonic would fall in bin 4, but we already have

something in bin 4, that's where the sixth harmonic would go. The eleventh

harmonic would fall into bin 14, but the fifth harmonic went into bin 14.

The twelfth harmonic would go into bin 8, just like the fourth harmonic did.

So the problem here is there's not enough bins for all these harmonics,

that's because M and N are not mutually prime, and we lost all of our

odd-numbered bins because we had redundant samples. Now let's push M up

to 11, so Ft goes into bin 11, the third harmonic goes up into

being 33, 3 times 11. You can see the alias of the third harmonic down in bin

1, but let's calculate and see how that works. So back to Dan's aliasing rules.

Rule #1: Is 33 greater than 32? Yes, finally! So 33 modulo 32 is equal to 1. In other

words, if you take 33 and subtract 32, the answer is 1. If the answer was still

greater than 32, you would subtract 32 again and subtract 32 again until the

result is less than 32. Then that is the remainder. So the modulo is simply taking

the remainder of a division. Now I still have to run through rule #2: Is 1

greater than 16? The answer is no, so we don't have to apply it. So Dan's aliasing

rule shows that when the third harmonic goes into bin 33, 1 above N, it aliases

back into the Nyquist band at bin 1, that is 1 over the DC bin. For the foreseeable

future, as M increases, the alias of the third

harmonic will move up towards N/2, and when it gets to a certain point, it

will bounce off of N/2, the Nyquist frequency, and work its way back down

towards DC, then it will bounce off of that and work its way back up to N/2.

So it will basically bounce back and

forth in the confined space called the Nyquist band. Now that's true not just

for the third harmonic, but for everything that we sample. Everything

that's captured by our sampler will end up in the Nyquist band. So we move M up

to 12 and now you can see the third harmonic working its way up toward N/2.

An M of 12 means common divisors between our M and our nNof 32. That's a

problem, and if you look at the time domain version of the waveform, you can

see there does appear to be some redundancy in the samples. Basically,

large portions of the waveform looks like repeats. OK, let's figure out where

our third harmonic went. The third harmonic at 3*12 or 36. Is 36,

greater than 32? The answer is yes, so 36 modulo 32 is 4. Is 4 greater than 16? The

answer is no, so the new bin number for the alias is bin 4. Because 12/32

can be reduced to 3/8, our number of effective bins is now 8/2+1 or

5. With only 5 bins in the Nyquist band for things to go into, it gets crowded

fast. Ft goes in bin 12, the second harmonic, if there was one, goes into bin

8. The third harmonic, we already saw it goes into bin 4. The fourth harmonic

goes in a bin 16 and there's only one left,

bin 0, where the DC goes and the eighth harmonic will be polluting that. So if M

and N have common divisors, it's a disaster. Your harmonic products end up

all over the place and piling on top of each other polluting each other and

making their measurements totally inaccurate. So let's move M up to 13.

Now the third harmonic is way up there, 3 times 13 or 39, and the alias of the

third harmonic is working its way up from the DC bin up towards N/2. So

where did the third harmonic go? Well, is 39 greater than 32? Yes, so 39 modulo 32

is equal to 7, and since 7 isn't greater than 16, we don't have to implement

rule number two, so the third harmonic alias is back to bin 7. As N moves up,

the fundamental moves up, the alias of the third harmonic moves up at the same

time, but three times faster. So where did the alias go? Back to Dan's rules.

3*14 is 42, the problem of course is that 42 is not in the Nyquist band, so

where does it go? Is 42 greater than 32? The answer is yes,

So 42 modulo 32 is 10. That was easy! Is 10 greater than 16? The answer is no,

so the answer is 10. So the third harmonic aliased all the way back from bin

42 down to bin 10. When we move M up to 15, you see something very interesting in

the time domain. The time domain waveform has a very strange shape, and that is due

to the fact that we are currently at just about 2 samples per cycle. Nyquist

stated that that was the minimum, two samples per cycle.

You can't transmit any information without at least two samples per cycle.

Now that doesn't mean that you can't alias. He didn't outlaw aliasing. He

simply said to transmit data you must have two samples per cycle, so with an M

of 15 our fundamental is in bin 15, just 1 below N/2. Our third harmonic

is way up in bin 45, but we can see it's alias back in the Nyquist band so again

let's go find out where it is. Is 45 greater than 32? Yes, so 45 modulo 32 is

13. Is 13 greater than 16? No so we don't have to apply that rule. So our third

harmonic is aliased all the way back from bin 45 into bin 13, and that's

pretty clear when you look at the frequency domain plot of this waveform.

Now 15 is not a prime number, so let's take a look at where the harmonics would

go if there was more than just one harmonic here. Again Ft falls in

bin 15. The second harmonic, which would be in bin 30 drops back into bin 2

when it aliases. The third harmonic we already saw goes from 45 to bin 13.

The fourth harmonic, if there was one would alias back down to bin 4. The

fifth harmonic which would be in bin 75 would alias back down to bin 11 and so on.

Notice; no repeats, every harmonic has its own bin and never falls on top of any

other harmonic or on top of the fundamental. So M does not have to be

prime, M must be mutually prime with N, and that's the only requirement. Now we

push M up to 16, and it's pretty obvious this is not going to go well.

With M on the Nyquist frequency, it's virtually invisible, you can't trust it

at all! You can see in the time domain representation of the waveform there is

no signal amplitude. That's because the signal amplitude depends entirely upon

the phase of the waveform. Unfortunately, our exact two samples per

cycle fell at both 0 degrees and 180 degrees, and with a sine wave the

amplitude is at 0 at 0 degrees and the amplitude is at 0 at 180 degrees. Bin 16

is not to be trusted because the phasing of the waveform controls what the

amplitude is going to be. With an M of 16 and an N of 32, we reduced to 1 over 2

which means our number of effective bins is equal to 2/2+1 or just 2. So

there's only two bins for things to go into, no matter how many harmonics we

have. So even if we had an impulse, with an M of 16, every single harmonic that we

got would end up in either bin 0 or bin 16 and because they would all be piling

on top of each other, we couldn't tell what our DC offset is or what any of the

harmonic amplitudes were. Now when we take M up to 17 look what happens to

the fundamental! It's now gone above N/2, which means it has an alias at N/2-1

The third harmonic has gone way up and now of course it's

aliasing back down into the Nyquist band very close to the fundamental. So by now you're

probably pretty good at this but let's go ahead and go through it. Is 17 greater

than 32? The answer is no, so is 17, the fundamental greater than 16? Yes, so

32-17 is 15. So that's why the fundamental appears in

bin 15. The third harmonic is way up in bin 51 which, again we can't see because

we can't see anything outside the Nyquist band, so 51 is greater than 32, so

51 modulo 32 is 19. But 19 is still higher than 16, N/2. So 32 minus 19

is equal to 13. So the third harmonic ends up in bin 13,

while the fundamental ends up in bin 15. Moving M up to 18 you can see that both

the alias of the fundamental and the alias of the third harmonic are working

their way back down towards DC. The fundamental alias is back down into bin

14, while the third harmonic which ends up way in bin 54, which again we can't

see, aliases back down to bin 10. Now it should be pretty obvious that 18 is

going to be a problem because it reduces to 9 over 16, so our effective number of

bins is actually only 9. So there's only 9 places for things to go, and you can

see in our harmonic chart there's a lot of repeats and there's nothing that can be

done. Don't use an M and N that are not mutually prime. Let's push M up to 19

now and watch where the aliases of both fundamental and a third harmonic go. The

fundamental is still not greater than N so then the question is, is 19 greater

than 16? The answer is yes, so we alias back into bin 13 for the fundamental. The

third harmonic however is way up in bin 57, which again we can't see, so it's

greater than 32, so it's now aliasing back into bin 25 however we can't see

bin 25 either, so we have to apply Dan's Aliasing rule #2. Is

25 greater than 16? Yes, so 32 minus 25 is equal to 7. So the third harmonic is

aliasing back into bin 7. Now we take M up to 20 which means that the

fundamental is aliasing and the third harmonic is all the way up in bin 60,

very close to 64 which is two times N. So our fundamental aliases

down to bin 12, the third harmonic aliases down to bin 4, and we knew that was

going to happen with an M of 20 we know there's common

divisors between M and N. Our effective number of bins now is 5, and so you can

see there's only 5 places where things can go. So if there are any harmonics

other than the third harmonic, it will end up falling on top of the fundamental

as well as the DC bin, as well as a Nyquist bin and we already talked about the

fact that the Nyquist bin is unreliable. With an M of 21 our fundamental alias is

back into bin 11, and our third harmonic aliases all the way back from bin 63 down

to bin 1. Now, 21 is not a prime number but it doesn't have to be. You only need

to be prime relative to N. Every harmonic has its own bin to go into, and there are

no repeats. Pushing M up to 22 shows something interesting. The third harmonic

has disappeared from our little diagram here, but that doesn't mean it's gone. I

just didn't extend the diagram beyond 2N. The third harmonic did fall back

into the Nyquist band it looks like it fell into bin 2. Let's see why. The

fundamental aliases back down to bin 10. The third harmonic aliases back down to

bin 2. Just because my diagram stops at two times N doesn't mean that

everything stops at 2*N. The frequencies go on forever. Anything that

gets captured can, and will alias back down into the Nyquist band. Pushing M up

to 23 means that our fundamental aliases back down to bin 9 and the third

harmonic will alias all the way back down to bin 5. With an M of 24 you can

tell there's going to be trouble. The fundamental will alias down and into bin 8,

and so will the third harmonic, and the effective number of bins is only 3, so

there are only three places where things can go; the DC bin, that's a no-no because

that's where our DC offset is supposed to go, bin 8 that's ok,

and then bin 16, that's bad because it's very sensitive to phase. Anything in the

Nyquist bin is unreliable, so don't count on the Nyquist bin for any testing. An M

of 25 on the other hand is just fine, even though 25 is not a prime number,

the fundamental aliases back down to bin 7. The third harmonic aliases back

down into bin 11. With an M of 26 our fundamentals going to alias

down into bin 6 and our third harmonic's going to alias down into

bin 14. Here I've expanded the modulo operator showing that

78- 32 is 46. 46 is larger than 32, so 46 minus 32 is 14, and

then, is 14 greater than 16? No, and of course 26 over 32 reduces to 13/16,

so we end up with only nine unique bins. Pushing M up to 27, you can see how

the fundamental aliases back into bin 5 and how the third harmonic aliases

back down into bin 15. Again, I expanded the modulo operator, so the

third harmonic goes in bin 81. 81 is greater than 32. 81-32 is 49. 49 is

still larger than 32 though, so 49-32 is 17, that's smaller than 32 now. Is

17 larger than 16? Yes, so 32-17 is 15. The third harmonic ends up aliasing

into bin 15. Here's another suspect M at 28. Our fundamental is going to

alias down into bin 4. The third harmonic is going to alias down into bin 12,

and 28 over 32 reduces down to 7/8 which means we're going to end up with

only 5 unique bins. We push M up to 29. The fundamental ends up aliasing back

into bin 3 and the third harmonic, which is not even visible on our chart

anymore, aliases back to bin 9. Now that we know that our fundamental aliased

into bin three, take a look at the time domain representation of the waveform.

Notice it's three cycles, just as though M were 3, except rather than

starting positive, they're going negative, so it's three cycles negative going

which means they're out of order, they're reverse order. So with an M of 29, our

waveform was sampled as though we were sampling with an M of three, except in

reverse order because the fundamental is three bins down from bin N. This is

aliasing at its best, and it is useful this way. Notice now the alias of the

third harmonic is in bin 9, just as though M were three. So the third

harmonic being in bin 9 works just the same as if the M was 3 or if the

M is 29. When we push M up to 30, take a look at the time domain

waveform. We have 2 cycles. 2 cycles of the waveform, just as if M were 2

and that's because M is actually 2 below N, and so there are 2 cycles of

inverted waveforms because they are captured in reverse order, and you can

see that the fundamental aliased back downto bin 2 and the third harmonic aliased

back into bin 6. Here we use Dan's rules to prove that the fundamental aliased down

to bin 2, and here the third harmonic aliased back down to bin 6. This is just

exactly the way it would be if M were 2. The third harmonic would then be in bin

6. Now we push M up to 31. Take a look at the time domain waveform. It's exactly

one cycle, but it's in reverse order. The reason it's one cycle is because M

is one below N. The alias falls back and bin 1, so the waveform looks like M

was 1, except in backwards order. The third harmonic has aliased back into bin

3. When M is N-1, you get an M of 1, but in reverse order.

Here I show how Dan's Rules predicts that the alias of the fundamental will

fall back in bin 1, and here I show how the alias of the third harmonic will

fall back in bin 3. And it's not just the fundamental of the third harmonic that

behave that way. The fundamental falls in bin 1 the second harmonic aliases back

into bin 2, the third harmonic aliases back in the bin 3, the fourth harmonic

aliases back in bin 4, the seventh harmonic aliases back into bin 7

and so on. So using an M that is N-1 is just like using an M of 1 except

that the time domain version of the waveform is

reversed, the phase is not correct but who cares? An M of 32 is obviously going

to be a disaster, but let's find out why. Dan's Aliasing rule #1: Is 32

greater than 32? The answer is No. Dan's Aliasing rule #2: Is 32

greater than 16? Yes, so the result is 32 minus 32 or 0. So the fundamental falls

in bin 0. So does every other harmonic! And what's worse is that there's only

one bin for everything to go into. The fundamental and every harmonic ends up

aliasing back into bin zero. Now that you have a better idea of how aliasing

works, let's watch a high speed version of what we just went through.

I hope you now know more about sampling, aliasing, and Nyquist. Don't forget Dan's

Rules and be sure to visit me at www.danbullard.com

Thanks for watching.

The Description of Sampling, Aliasing and Nyquist