We begin with
-->k=1:100; vecsin = sin (2 * %pi * 0.02 * k); plot(vecsin);We get a plot of a `sin' function (which can be seen at the top left frame of the figure 1.1). It is a sin function from 0 to 100. It has been sampled at `1', which is determined by `k=1:100' and consequently it could be seen as having a sampling frequency of `1'. The frequency of the curve is 0.02 (Hz if we see 1 as one second) and the period is 50 (1/0.02, frequency is the inverse of the period). We can check the period of the plotted sinusoid. (see first frame of figure 1.1) Now we write
-->k = 1:100; vecsin = sin (2 * %pi * 0.05 * k); plot(vecsin);With the same sampling period we have built a sinusoid of frequency 0.05 and, of course, its period is 20 (1/0.05). So we have five repetitions in a space of 100 as we can see in the middle frame of the left column of the figure. The frequency of the sinusoid can be increased
-->k = 1:100; vecsin = sin (2 * %pi * 0.2 * k); plot(vecsin);Everything seems to function well: we have a sinusoid of a frequency of 0.2, a period of 5 and 20 repetitions on the bottom left frame of the figure. We are going to increase the frequency even more (the curve has not been plotted).
-->k=1:100; vecsin = sin (2 * %pi * 0.4 * k); plot(vecsin)Now we try with
-->k=1:100; vecsin = sin (2 * %pi * 0.5 * k); plot(vecsin)Something really strange happens (top frame of the right). The plot is not a sinusoid but something that varies in frequency. If we check y-axis we see that the plot doesn't go from -1 to 1 but from -4e-14 to 4e-14, so the plot is more or less `0'. What will it happen if we increase the frequency even more?
-->k=1:100; vecsin = sin (2 * %pi * 0.8 * k); plot(vecsin)We recover the y-scale from -1 to 1 (middle right frame) but instead of a frequency of 0.8, a period of 1.25 (1/8) and 80 repetitions, we got only 20 repetitions. Even more:
-->k = 1:100; vecsin = sin (2 * %pi * 0.95 * k); plot(vecsin)We would hope a frequency of 0.95 and a period of 1.0526 (1/0.95) and we get five repetitions which implies a period of 20 and a frequency of 0.05 (1/20) at the right bottom frame. So, by increasing the frequency of the function above some level, we get a decrease of the frequency of the plot. What is happening?
What we are seeing is `aliasing', a phenomenon with important practical consequences. If t is a real variable, sin (6.28 * f * t) is a continuous function. On the other side, vecsin = sin (2 * %pi * frequency * k), being k a discrete variable, can be seen as a sampled function. The sampling theorem affirms that if a signal whose maximum frequency is fmax is sampled at a frequency greater than 2 fmax, then the original signal can be completely reconstructed. Unfortunately the sampling theorem also establishes that if there are frequencies above half of the sampling frequency, there will appear aliased frequencies (frequencies not present in the original signal which can deeply alter its form). By sampling with a frequency of 1 we can recover signals whose maximum frequency is 1 / (2*1) = 0.5. If we apply this expression to different sampling rates we get:
| Samp. rate (ms) | Samp. rate (s) | Freq. samp. (Hz) | Max. freq. (Hz) |
| 1000 | 1.0 | 1.0 | 0.5 |
| 500 | 0.5 | 2.0 | 1.0 |
| 100 | 0.1 | 10.0 | 5.0 |
| 50 | 0.05 | 20.0 | 10.0 |
| 10 | 0.01 | 100.0 | 50.0 |
| 5 | 0.005 | 200.0 | 100.0 |
| 1 | 0.001 | 1000.0 | 500.0 |
| 0.5 | 0.0005 | 2000.0 | 1000.0 |
| 0.1 | 0.0001 | 10000.0 | 5000.0 |
| 0.05 | 0.00005 | 20000.0 | 10000.0 |
| 0.01 | 0.00001 | 100000.0 | 50000.0 |
The maximum frequency present in the original signal must be at most half of the sampling frequency. This frequency is often called `Nyquist frequency'.
We need to be certain that there are not frequencies above Nyquist frequency potentially disturbing our analysis. The most commonly utilized method consists in making an analog filtering of the signal at a frequency half of the sampling frequency. Imagine that we sample an EMG signal at a frequency of 20000. If we previously filter the signal at 10000 with an analog filter (which works in real domain and does not suffer from aliasing) we are sure that all the frequencies present in the signal are adequately sampled.
Could we make a digital filtering of the signal to obtain the same results?. Unfortunately no. Once aliasing has taken place in our digital curve, we have an aliased frequency in the interval from 0 to half of the sampling frequency potentially disturbing our analysis.
Until now we have seen vectors as sampled segments of curves. We can access the components of these `curves' too.