Lessons › Lesson 3
How often we listen: the sample rate
A recorder does not hear the sea all the time. It measures the pressure at regular moments and keeps one number each time. How far apart those moments are decides what a record can hold, what it can get wrong, and how every time in it is counted. This lesson is about that one number.
1What a sample is
A hydrophone turns pressure into a voltage that changes all the time. A recording system cannot store a curve - it stores numbers. At regular moments it measures the voltage and writes down one number: a sample. Whatever happens between two samples is not stored at all.
One thing has two names, and both are used:
- The sample interval, written Δt: the time from one sample to the next, in milliseconds. In the field people say "we record at 2 ms" - that is the interval.
- The sample rate: how many samples a second, in hertz. It is one divided by the interval: 1 ÷ 0.002 s = 500 samples a second.
| Sample interval | 4 ms | 2 ms | 1 ms | 0.5 ms | 0.1 ms |
|---|---|---|---|---|---|
| Samples a second | 250 | 500 | 1,000 | 2,000 | 10,000 |
The idea to keepA record is a list of numbers, one every sample interval. The interval is what turns "sample number 500" into a time. Read it wrongly and every time - and every frequency - in the record is read wrongly with it.
2Two samples a cycle: Nyquist
How often is often enough? A wave goes up and down once in each cycle. To be told apart from a slower wave it has to be caught more than twice in every cycle - on the way up and on the way down. So the highest frequency a record can hold is half its sample rate. That frequency is the Nyquist frequency, fN:
fN = 1 ÷ (2 × Δt) · at 2 ms: 1 ÷ 0.004 s = 250 Hz
The sampling theorem asks for strictly more than two samples a cycle. At exactly two, the samples can fall on the wave's zero crossings and see nothing at all.
Aliasing: a wave in disguise
A frequency above the Nyquist frequency does not simply go missing. Its samples are exactly the samples of a slower wave, and nothing in the record can tell the two apart. This is aliasing: the fast wave turns up in disguise, at a frequency it never had. Film does the same thing to wheels - a fast wheel can seem to turn slowly, stand still, or even turn backwards.
Try it: sample a wave
A pure tone - one frequency - and the samples a recorder keeps of it. Drawn the SEG way, a rise in pressure down. Raise the frequency past the Nyquist frequency, or make the interval longer, and watch what the samples say. Then switch the anti-alias filter on.
- Nyquist frequency
- -
- Samples a cycle
- -
- The samples show
- -
- Samples a second
- -
The sampling demo needs JavaScript; the drawing above shows what it shows.
For the curious: where an alias lands
Frequencies fold back around the Nyquist frequency like a paper fan. To find where one lands, subtract the nearest whole multiple of the sample rate fs and drop the sign:
falias = | f − k × fs | (k: the whole number that makes it smallest)
At 2 ms, fs = 500 Hz and fN = 250 Hz. A 300 Hz wave lands at |300 − 500| = 200 Hz; 600 Hz at |600 − 500| = 100 Hz; 1,000 Hz at |1000 − 2 × 500| = 0 Hz - its samples are all the same number, and it looks like no wave at all.
The idea to keepAbove the Nyquist frequency nothing is lost quietly: it comes back as something false, and once recorded it cannot be taken out.
3The anti-alias filter
An alias cannot be removed after it is recorded, so recording systems remove its cause first. Before the signal is sampled, while it is still continuous, an anti-alias filter - a high-cut filter - takes out what lies above the Nyquist frequency.
No filter cuts like a knife: it needs room to go from passing everything to passing nothing. So it starts below the Nyquist frequency. Sercel's specification for its Seal 428 marine system, for example, gives the high-cut filter as 0.8 FN - 0.8 of the Nyquist frequency - with more than 120 dB of attenuation above Nyquist. On a 2 ms record that is full strength up to 200 Hz, and next to nothing past 250 Hz.
SEG‑D writes the filter down with the data: every channel set descriptor carries an alias filter frequency (0 to 9999 Hz) and its slope in dB per octave.
Making the interval longer: resampling
Data is often resampled to a longer interval - a 0.1 ms signature compared with a model drawn at 2 ms, for one. Keeping every 20th sample is not enough. Everything between the new Nyquist frequency (250 Hz) and the old one (5,000 Hz) would fold down into the band and sit there as false signal. Filter first, below the new Nyquist frequency; then keep every 20th sample.
The idea to keepFilter before you sample, and filter again before you resample.
4What the interval decides
| Sample interval | 4 ms | 2 ms | 1 ms | 0.5 ms | 0.1 ms |
|---|---|---|---|---|---|
| Nyquist frequency | 125 Hz | 250 Hz | 500 Hz | 1,000 Hz | 5,000 Hz |
| A time read to the nearest sample | ± 2 ms | ± 1 ms | ± 0.5 ms | ± 0.25 ms | ± 0.05 ms |
| One channel, one minute, 4-byte samples | 60 kB | 120 kB | 240 kB | 480 kB | 2.4 MB |
- The highest frequency in the record - the Nyquist frequency, less the room the anti-alias filter needs.
- How precisely a time is known. Read straight off the samples, a time is known to the nearest sample - half an interval either way. That is why gun controllers sample finely: Seamap's GunLink 4000 samples its near-field hydrophones every 0.1 ms.
- Whether the ghost notch can be seen. Lesson 1 put the ghost notch of a gun at 6 m at c ÷ (2 × z) = 1500 ÷ 12 = 125 Hz. A 4 ms record's Nyquist frequency is exactly 125 Hz - the notch is at the very edge of what it can hold, and its anti-alias filter has already taken the band away.
- Not how finely a spectrum is resolved. That is the record's length: a spectrum's lines are 1 ÷ T apart, so a 0.5 s record gives a line every 2 Hz whether it was sampled at 2 ms or at 0.1 ms. A shorter interval reaches higher frequencies; a longer record separates close ones.
- The size of the data. Halve the interval and the data doubles.
The idea to keepChoose the interval for the highest frequency you need, with room for the filter - and pay for it in data.
5How SEG‑D writes the interval
In SEG‑D revision 1 - the revision of Lesson 2 - the interval is written in two steps:
- General Header Block #1, byte 23: the base scan interval. In the standard's words, it is "coded as a binary number with the LSB equal to 1/16 msec", and "the allowable base scan intervals are 1/16, 1/8, 1/4, 1/2, 1, 2, 4, and 8 msec".
- Each channel set descriptor, byte 12: the subscans. A number S/C, an exponent of 2: the set is sampled 2S/C times in each base scan - 1, 2, 4 … up to 512 times. The set's interval is the base scan interval divided by that.
| Interval | 1/16 ms | 1/8 ms | 1/4 ms | 1/2 ms | 1 ms | 2 ms | 4 ms | 8 ms | 0.1 ms |
|---|---|---|---|---|---|---|---|---|---|
| Byte 23, counting sixteenths of a ms | 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 | 1.6 ? |
| In binary | 0000 0001 | 0000 0010 | 0000 0100 | 0000 1000 | 0001 0000 | 0010 0000 | 0100 0000 | 1000 0000 | no code |
Every interval revision 1 can write is a power of two: halves, quarters, eighths, sixteenths of a millisecond - and dividing by subscans only halves it further. 0.1 ms is 1.6 sixteenths. It has no code at all.
The channel set descriptor also gives the set's start and end time, in 2 ms steps. From those and the interval a reader works out how many samples each trace has: (end − start) ÷ interval. Revision 1 can also write the count itself, in a trace header extension ("Number of Samples per Trace", bytes 8-10) - but a record whose traces carry no extension leaves the reader to work it out.
SEG‑Y does it differently. Its binary file header (bytes 3217-3218) and every trace header (bytes 117-118) hold the sample interval in microseconds. In SEG‑Y, 0.1 ms is simply 100.
The idea to keepKnow what a format can write before you trust what it says. SEG‑D revision 1 writes powers of two of a millisecond, and nothing in between.
6GunLink's 0.1 ms records
Gun controllers time guns finely. Seamap's GunLink 4000 samples its near-field hydrophones every 0.1 ms - 10,000 samples a second. Its records are SEG‑D revision 1, and revision 1, as the last part showed, has no code for 0.1 ms.
So the header has to say something else. Read with SEG‑D Monitor, GunLink's records describe a 0.1 ms channel set with the nearest interval revision 1 can write - 1/8 ms, a base scan interval and a number of subscans that come to 1/8 ms - and give the set an end time chosen so that end time ÷ 1/8 ms is the right number of samples. The count is right. The interval written beside it is not.
What a reader that believes the header shows
A general SEG‑D viewer has only the header to go on. SegDSee, a free viewer for SEG‑D revisions 0 to 3.1, decodes the base scan interval from byte 23 like any reader - its manual shows one decoded as "Base scan interval I : 32 [20] [2 ms]". Given a GunLink 0.1 ms set, such a reader puts each sample 1/8 ms after the one before: a quarter too far.
- Every time comes out 1.25 times too late. 1,000 samples - 100 ms of record - are shown as 125 ms; a bubble pulse 100 ms after the primary is shown at 125 ms.
- Every frequency comes out at 0.8 of the truth. The Nyquist frequency is shown as 4,000 Hz instead of 5,000. A ghost notch at 125 Hz is shown at 100 Hz, and a depth worked out from it, 1500 ÷ (2 × 100), comes to 7.5 m - for a gun at 6 m.
- Type the true 0.1 ms in, keep the header's end time, and the count goes wrong. The reader now expects 1.25 times as many samples as each trace has, and reads on past the end of the trace - through the next trace's header and into its samples.
Try it: read a 0.1 ms record three ways
A synthetic signature, made up for this page: a gun at 6 m fires, its ghost follows 8 ms later, its bubble 100 ms later. It was recorded every 0.1 ms - 2,000 samples - and its header says 1/8 ms, as described above. Pick how it is read.
- Record length · samples
- -
- Bubble period
- -
- Ghost notch
- -
- Depth from the notch
- -
The demo needs JavaScript; the list above says what it shows.
What to do
- Take every channel set's interval from the recording system's own setup - here, GunLink's - never from the header alone. SEG‑D Monitor asks for it for this reason: Settings → Channel Sets has a dt (ms) for every set.
- Check the header against itself. A recorder does not set its anti-alias filter above its own Nyquist frequency. An alias filter frequency in the channel set descriptor that is higher than the Nyquist frequency of the interval the header claims cannot both be right.
- Check a time you know. If the shot is aimed at a known time, the primary must arrive there. A primary that arrives a quarter late says the interval is wrong.
The idea to keepThe number of samples and the interval between them must come from the same truth. For GunLink records, that truth is GunLink's setup.
7Sample 0 or sample 1?
Time zero is the moment of the shot. In SEG‑D a channel set's start time "identifies the timing word of the first scan of data in this channel set" - and in a single record it is "typically recorded as a zero". So the first sample is at 0 ms, the next one interval later, and so on.
But what number does the first sample have? Two habits exist:
- Counting from 0. The first sample is sample 0, and sample k is at k × Δt. A sample's number is then the number of intervals since time zero - which is why seismic work usually counts this way. C and Python count from 0 too: in Python's own words, "the first character having index 0".
- Counting from 1. The first sample is sample 1, and sample n is at (n − 1) × Δt. Fortran counts this way, and so does MATLAB ("MATLAB uses 1-based indexing") - and so do many programs' sample counters, because people count from one.
Neither habit is wrong. Mixing them is: the same number then means two times, one interval apart.
counted from 0: t = k × Δt · counted from 1: t = (n − 1) × Δt
At 0.5 ms, a gun aimed at 50 ms fires on sample 100 counted from 0 - and on sample 101 counted from 1. Read a program's "sample 100" the wrong way, and a gun that fired on time looks 0.5 ms early. SEG‑D Monitor, for one, flags a gun that fires more than half a sample interval from its aim point: an error of one whole sample, made by counting, fails a good gun.
SEG‑Y adds one more thing to check: the delay recording time (trace header bytes 109-110), the "time in ms between initiation time of energy source and time when recording of data samples begins". When it is not zero, the first sample is not at time zero.
Try it: one number, two times
A program shows a sample number. Tell it the interval and how it counts, and see the time that number means - and the time it would mean read the other way.
- Its time
- -
- Read the other way
- -
- The difference
- -
- Intervals since time zero
- -
The counting demo needs JavaScript; the two formulas above are all it does.
For the curious: why programmers count from zero
In 1982 the computer scientist Edsger Dijkstra wrote a short note, "Why numbering should start at zero". Counting from 0, he argued, a subscript equals the number of elements before it. For samples that is exactly the time: sample k has k samples before it, so it is k intervals after the first.
The idea to keepBefore you read a time off a sample number, ask two questions: does it count from 0 or from 1 - and when is the first sample?
8Interesting facts
Kotelnikov's theorem
In Russian literature the sampling theorem bears another name: Vladimir Kotelnikov found it independently in 1933.
Wikipedia: Nyquist-Shannon sampling theoremMany fathers
Whittaker wrote about it in 1915 and Nyquist in 1928. Shannon's papers of 1948 and 1949 made it widely known - though he never claimed to have originated it.
Wikipedia: Nyquist-Shannon sampling theoremThe wheel that turns backwards
In films a spoked wheel can seem to turn slowly, stand still or go backwards. In recorded media that is aliasing in time - the camera samples the wheel.
Wikipedia: Wagon-wheel effectWhy a CD runs at 44.1 kHz
To reproduce the audible range of 20 to 20,000 Hz. Half of 44,100 is 22,050 Hz, which leaves a 2.05 kHz band for the anti-alias filter to do its work.
Wikipedia: 44,100 HzEight intervals
SEG‑D revision 1's base scan interval can be only 1/16, 1/8, 1/4, 1/2, 1, 2, 4 or 8 ms - powers of two, nothing in between.
SEG‑D revision 1Zero, the most natural number
Dijkstra's 1982 note ends by arguing that zero deserves to be treated as the most natural number to start counting from.
E. W. Dijkstra, EWD8319Quiz: what stayed?
Ten questions. Pick an answer and it is marked at once, with a line on why. Nothing you answer leaves this page.
-
Answer
500. 1 ÷ 0.002 s = 500. The interval (2 ms) and the rate (500 a second) are two ways of saying one thing.
-
Answer
1,000 Hz. 1 ÷ (2 × 0.0005 s) = 1,000 Hz - half of the 2,000 samples a second.
-
Answer
A 200 Hz wave. The sample rate is 500 Hz and the Nyquist frequency 250 Hz; 300 Hz folds back to |300 − 500| = 200 Hz - a false frequency that nothing in the record can tell from a real one.
-
Answer
To stop aliasing. An alias cannot be taken out once it is recorded, so the anti-alias filter removes what is above the Nyquist frequency while the signal is still continuous.
-
Answer
A filter below the new Nyquist frequency. Without it, everything between 250 Hz and 5,000 Hz would fold down into the band. Filter first, then keep every 20th sample.
-
Answer
The record's length. A 0.5 s record gives a line every 2 Hz, whatever its interval. The interval decides how high the spectrum reaches, not how finely it is resolved.
-
Answer
0.1 ms. Byte 23 counts sixteenths of a millisecond in binary steps - 1/16, 1/8, 1/4 … 8 ms. 0.1 ms would be 1.6 sixteenths, and there is no such code.
-
Answer
At 125 ms. Each sample is placed 1/8 ms after the last instead of 0.1 ms: every time comes out 1.25 times too late, and every frequency at 0.8 of the truth.
-
Answer
The recording system's setup. The header can only write the nearest interval revision 1 allows; the file size fixes how many samples there are, not how far apart they are.
-
Answer
49.5 ms. (100 − 1) × 0.5 = 49.5 ms - one interval earlier. The same number, two times.
10Sources and further reading
Every fact in this lesson comes from one of these - except what GunLink's records carry in their headers, which is what SEG‑D Monitor finds when it reads them; the arithmetic is the standard's. The drawings and the demos' data are the site's own.
- SEG Field Tape Standards Subcommittee (1994). Digital field tape standards - SEG‑D, revision 1 (special report). Geophysics 59, 668-684 - the base scan interval (General Header Block #1, byte 23), the subscans (channel set descriptor, byte 12), the channel set start and end times, the alias filter fields and the number of samples per trace.
- Pavlukhin, S. (2019). SegDSee manual - a free viewer for SEG‑D revisions 0 to 3.1 and SEG‑B.
- MIND Technology: Seamap GunLink 4000 data sheet - near-field hydrophones sampled every 0.1 ms.
- Sercel: Seal 428 specifications - sample rates, the high-cut filter at 0.8 FN and the stop-band attenuation above Nyquist.
- U.S. Geological Survey, Data Series 95: SEG‑Y format - the sample interval in microseconds, the number of samples and the delay recording time.
- Wikipedia: Nyquist-Shannon sampling theorem - the theorem, the strict inequality and its history.
- Wikipedia: Wagon-wheel effect.
- Wikipedia: 44,100 Hz.
- Dijkstra, E. W. (1982). Why numbering should start at zero (EWD831).
- Wikipedia: Zero-based numbering - C counting from 0, Fortran from 1.
- Python Software Foundation: An informal introduction to Python - indexing from 0.
- MathWorks: Matrix indexing in MATLAB - indexing from 1.