Starting with the formula for sample variance
$$ s^{2}=\frac{ \sum_{i=1}^{N}\left ( X_{i}-\bar{X} \right )^2}{N-1} $$
you multiply out to get
$$ s^{2}= \frac{\sum_{i=1}^{N}\left({X_i}^2-2X_i
\bar{X}+\bar{X}^2\right )}{N-1} $$
Distribute the sums. Using the fact that \$ \bar{X}\$ is a constant, then $$ \sum 2X_i \bar{X} = 2\bar{X}\sum{X_i}, $$ and $$\sum{X_i}=N\bar{X},$$
So, $$ 2\bar{X}\sum{X_i}=2N\bar{X}^2.$$
Then, using $$ \sum_{i=1}^{N}\bar{X}^2=N\bar{X}^2, $$ and
$$ N\bar{X}^2 = \frac{ N\left( \sum{X} \right )^2}{N^2} $$
the overall equation for varance reduces to a convenient computational formula for variance:
$$ \frac{ \sum_{i-1}^{N}\left ( X_{i}^2 \right )-\frac{\left (\sum_{i=1}^{N}X_i \right )^2}{N}}{N-1} $$
XSQR=X.*X; \ simply element by element squares the column array, X
Without entirely explaining convolution, convolution with a string of ones of length N (i.e., convsig) is simply a sum of the previous N points at each time step.
The last line in the code just gets rid of the trash at either end of the array associated with the beginning and end of convolution.
Lastly, you need to understand that most operations on arrays in Matlab operate on the whole array at the same time -- most of the operations in the program you show would absolutely need to loop over every element in the array in a language like C, which likely very confusing for folks not used to working in Matlab.
Bottom line, its not much different than actually just implementing the sum, but convolution is something directly written into matlab, and there are generally libraries that directly handle convolution on DSP's, so its a convenient way to implement a moving variance filter without needing to do the grunt work.
Obviously, they expect you to answer based on the lab or lecture, not based on actual use.
There is no reason you have to interrupt on the Rising Edge instead of the Falling Edge, or the other way round, or both. Or edge interrupt instead of level interrupt.
Your design determines which type of interrupt you need. A signal that is active low will need a falling edge or level low interrupt, while a active high signal will need a rising edge or level high interrupt.
Sometimes you want to interrupt on both sides of the signal, like from a sensor or button. Someone pressed a button, and you want to do x when it's pressed, and y when it's released. Or you're timing how long the signal goes from one state to the other. Etc.
Best Answer
cyclic
ˈsʌɪklɪk,ˈsɪklɪk/
adjective
1. occurring in cycles; regularly repeated.
You haven't given a reference for the 'cyclic code' terminology but there is certainly a cyclic patter. This is most obvious in an encoder disc.
Figure 1. The cyclic pattern of each bit is clearly visible on this optical absolute encoder disc.
Each bit has a repeating on-off pattern with a 50% mark-space ratio. The bits are arranged so that only one bit changes at a time. This prevents errors on transitions from one code to the adjacent one due to misalignment of sensors, etc.
There's a generic definition about the cyclic nature of the Gray code further down the Wikipedia Gray code article mentioned in altai's answer: "The last entry in Gn differs by only one bit from the first entry. (The code is cyclic.)". That is it can wrap while still maintaining only one-bit change.
It would be possible to generate a Gray-ish code that didn't have this property if, for example, the number of steps was not even or a power of 2. This might be acceptable in a linear encoder which wouldn't need to wrap.