# A question about sampling rate of cosine signal

Given $$c(t) = \cos(2\pi\cdot 30 \cdot t)$$

If we sample this signal at the Nyquist rate 60 Hz and at a higher rate of 80 Hz, we get the following: There is no aliasing as $$f$$ = 30 Hz is less than or equal to the folding frequency, 30 Hz and 40 Hz, respectively.

Why does sampling at a rate of 80 Hz result in this "distorted" cosine signal, although it is higher than the Nyquist rate? (I know if we go way higher than 80 Hz the signal will look better.)

• why not just change "$\cos(⋅)$" to "$\sin(⋅)$" and see what happens? – robert bristow-johnson Jan 18 '20 at 8:02
• You can't Shannon-sample a signal with infinite energy, but you can Nyquist sample it. Nyquists sampling theorem deals with periodic signals and how to sample them to get representations via a trigonometric polynomials. – Lutz Lehmann Jan 18 '20 at 19:44
• @LutzLehmann i must confess that there is almost nothing that i understand in your comment. – robert bristow-johnson Jan 22 '20 at 17:32

It is actually not distorted, it is sampled at high enough rate. What fools you is the straight lines drawn between sample points, it gives you a false impression of the waveform. It shows you a linear interpolation of the signal. It does not represent how the signal would actually look like. A sampled signal exists only at the sample points, and to convert that into continuous analog representation that also exists between the sample points, you should use sinc interpolation which limits the bandwidth to half of the sampling rate.

The actual requirement is to sample at GREATER then twice the bandwidth, not at a rate equal to it...

So only your 80Hz same set actually meets the requirement, because the 60Hz case is ambiguous in general, consider if you were sampling sin (2PiFt) instead then you would get a flat line at zero amplitude.... And changing the angle between sin and cos would just produce a waveform having variable amplitude, which is not what the original wave does.

You are filling in the gaps by joining the dots, not by low passing the impulse stream, and that does not work, all those sharp spikes represent energy way outside the bandwidth limit.

The reconstruction filter is where the magic happens.

• If you want to capture a signal with frequency B, how much more than 2B would you mathematically require? I reckon it would depend on the magnitude of the frequency, but is there a rule of thumb? 1Hz? 1%? – mhh Jan 19 '20 at 16:43
• @mhh How good are your reconstruction filters? The greater the sample rate compared to the signal of interest, the easier the filter design becomes. CD digital audio went for ~10%, which turned out to be a pain (Mostly because flat group delay was hard) when using just analogue reconstruction filters, but just fine if you do the digital filter thing and then run the analogue filters at a higher output rate. – Dan Mills Jan 19 '20 at 17:17

There is no aliasing as 𝑓 = 30 Hz is less than or equal to the folding frequency, 30 Hz and 40 Hz, respectively.

Yes and no. There isn't significant aliasing when you're sampling at 80Hz, because the resulting signal has frequency components at 30Hz and 50Hz. The result is thus unambiguous as long as you take that 50Hz signal into account.

There is aliasing when you're sampling at 60Hz, because a 30Hz signal sampled at 60Hz translates into two signals at 30Hz, and you cannot know which is which. This is why the Shannon/Nyquist sampling theorem says that you need to sample at more than twice the bandwidth of the signal.

Why does sampling at a rate of 80 Hz result in this "distorted" cosine signal, although it is higher than the Nyquist rate? (I know if we go way higher than 80 Hz the signal will look better.)

Because you are not reconstructing the signal correctly. The Shannon/Nyquist theorem doesn't say that the results of sampling won't look funny, it says that when you're done sampling, you'll have enough information to reconstruct the signal.

You need to run that sampled signal through a reconstruction filter that passes 30Hz and blocks 50Hz -- the output of that filter will be a pure 30Hz tone, to the extent that the filter blocks 50Hz.

• This paper may help. There's a lot of creative ways to misunderstand the Shannon/Nyquist theorem; I tried to cover the most common ones in that paper. – TimWescott Jan 18 '20 at 18:00
• The statement on the Shannon sampling theorem is wrong. A truly bandlimited signal with finite energy can be sampled at twice the bandwidth with perfect reconstruction. But only if you include the infinitely many samples in the infinite reconstruction sum. The basis functions fall like $1/t$, so that the influence of a sample falls very slowly with the distance in time. – Lutz Lehmann Jan 18 '20 at 20:34
• @LutzLehmann I don't see how that would work with a pure sine wave. Sampling it at exactly twice the bandwidth hits the nulls at all samples, infinite or not. – pipe Jan 18 '20 at 22:19
• @pipe : A pure sine wave does not have finite energy, thus is not covered by the sampling theorem. Any kind of windowing to make the energy finite will in general destroy the limitation to a bounded frequency band or, at best, increase the limit frequency by some amount inversely proportional to the feature size of the window function. – Lutz Lehmann Jan 18 '20 at 22:30
• @LutzLehmann The universe has only been with us for a finite time, and has a finite predicted lifespan. Therefore, I'll stick to the inequality. To be complete, you need to take into account that the reconstruction time is inversely proportional to how close you push up to the Nyquist rate: you can by no means get arbitrarily close to the Nyquist rate unless you're willing to allow reconstruction to get arbitrarily long. – TimWescott Jan 19 '20 at 0:22

Remembering from my 1970 Signal Processing lectures we have ...

The crucial thing is the filter used to reconstruct the signal. Let's do the theory first for ideal sampling a perfect sine wave at 2x its frequency and filtering with an ideal low pass filter.

1. The samples are infinitely thin - they are delta functions separated by time t.

2. The filter is an ideal low pass filter with infinite slope at the pass frequency - the response drops vertically.

3. If you put a single delta function pulse through such an ideal filter you get a sin(x)/x response which has values above and below the x axis. The response is zero at the axis crossing points t, 2t, 3t, 4t etc. The response begins at -infinity, peaks at 0 and goes on to +infinity. It is delayed by a time set by the cut off frequency of the filter which is equal to the time between the pulses.

4. If you put a stream of delta functions separated by time t through such a low pass filter you get a sin(x)/x response for each pulse. For pulse n at time = nt every other pulse has a zero response. Hence there is no aliasing -- the peak (or sampled value) output for each pulse is completely separated from the outputs for all the other pulses.

5. The output for each pulse is a sin(x)/x curve. Adding all the sin(x)/x curves for all the pulses reconstructs the signal exactly.

6. The output for a single pulse stretches from -infinity to +infinity

Now to the real world ...

Such a pulse is impossible to create.

Such a filter is impossible to create not least because it has a response which goes back to minus infinity. The filter must have some slope (so many dB/octave) and it does not have a perfect sin(x)/x output response. The less steep the slope, the further from sin(x)/x and the more aliasing.

So, in the real world, any sampling will distort the signal because of the imperfect pulse used and the imperfect filter used to recreate the signal. The best results are obtained with the narrowest pulse you can create and the steepest drop off you can create.

Sampling at frequencies greater than 2x improves the quality because the gaps between the pulses are smaller and the errors introduced by not having a sin(x)/x output response from the filter become smaller.

See Nyquist–Shannon sampling theorem at https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem which shows the sin(x)/x curve and its zero crossings.

Also, try using a smooth curve to join your points in your graph - you will get a much better representation.

And finally, obviously if the sampling frequency is exactly 2x the sine wave frequency every sample will be at the same point in the sine wave and all will be equal. It's a bit of an exception and I cannot remember how it is resolved - I think it is the sin(x)/x which re-creates the original sine wave even though all the sampled points are the same value. A quick check with 100 sample points in a spreadsheet would resolve it ...

Since this is a pure sinusoid, it has a bandwidth of 0 Hz. You can multiply it by a carrier signal of the same frequency, pass it through a low pass filter then take only a few samples. What matters is NOT the frequency of the signal, rather the bandwidth. Consider for example a voice signal modulating a 1 GHz carrier. It will be very costly, to sample this at more than 2 GHz. Instead, we apply the method above and we will need only to sample at twice the voice bandwidth.
{"ft_lang_label":"__label__en","ft_lang_prob":0.9433624,"math_prob":0.97021526,"size":2938,"snap":"2021-04-2021-17","text_gpt3_token_len":645,"char_repetition_ratio":0.13394684,"word_repetition_ratio":0.01923077,"special_character_ratio":0.22089857,"punctuation_ratio":0.077186964,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9899465,"pos_list":[0,1,2],"im_url_duplicate_count":[null,8,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-01-27T14:15:11Z\",\"WARC-Record-ID\":\"<urn:uuid:3ec63c68-6c6c-4c69-93a2-159b607e6627>\",\"Content-Length\":\"201684\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:cbcb9a31-24e9-465c-8799-7a7c45d3c14c>\",\"WARC-Concurrent-To\":\"<urn:uuid:7dd793f1-ae2e-4bd6-bb2f-65b448e10ad3>\",\"WARC-IP-Address\":\"151.101.65.69\",\"WARC-Target-URI\":\"https://dsp.stackexchange.com/questions/63321/a-question-about-sampling-rate-of-cosine-signal/63327\",\"WARC-Payload-Digest\":\"sha1:CTSDGX36RQ3KCDNGHMSREOFNZ2DQZJ4S\",\"WARC-Block-Digest\":\"sha1:DYKC3KITSL7NP6JVVUY7QEFT24LW3S3Y\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-04/CC-MAIN-2021-04_segments_1610704824728.92_warc_CC-MAIN-20210127121330-20210127151330-00362.warc.gz\"}"}