Thursday, February 6, 2020

digital communications - Understanding the Matched Filter


I have a question about matched filtering. Does the matched filter maximise the SNR at the moment of decision only? As far as I understand, if you put, say, NRZ through a matched filter, the SNR will be maximised at the decision point only and that is the advantage of the matched filter. Does it maximise the SNR anywhere else in the output function, or just at the point of decision?


According to Wikipedia




The matched filter is the optimal linear filter for maximizing the signal to noise ratio (SNR) in the presence of additive stochastic noise



This to me implies that it maximises it everywhere, but I don't see how that is possible. I've looked at the maths in my communications engineering textbooks, and from what I can tell, it's just at the decision point.


Another question I have is, why not make a filter that makes a really tall skinny spike at the point of decision. Wouldn't that make the SNR even better?


Thanks.


Edit: I guess what I'm also thinking is, say you have a some NRZ data and you use a matched filter, the matched filter could be implemented with an I&D (integrate and dump). The I&D will basically ramp up until it gets to the sampling time and the idea is that one samples at the peak of the I&D because at that point, the SNR is a maximum. What I don't get is, why not create a filter that double integrates it or something like that, that way, you'd have a squared increase (rather than a ramp) and the point at which you sample would be even higher up and from what I can tell, more likely to be interpreted correctly by the decision circuit (and give a lower Pe (probability of error))?



Answer



Since this question has multiple sub-questions in edits, comments on answers, etc., and these have not been addressed, here goes.



Matched filters




Consider a finite-energy signal $s(t)$ that is the input to a (linear time-invariant BIBO-stable) filter with impulse response $h(t)$, transfer function $H(f)$, and produces the output signal $$y(\tau) = \int_{-\infty}^\infty s(\tau-t)h(t)\,\mathrm dt.\tag{1}$$ What choice of $h(t)$ will produce a maximum response at a given time $t_0$? That is, we are looking for a filter such that the global maximum of $y(\tau)$ occurs at $t_0$. This really is a very loosely phrased (and really unanswerable) question because clearly the filter with impulse response $2h(t)$ will have larger response than the filter with impulse response $h(t)$, and so there is no such thing as the filter that maximizes the response. So, rather than compare apples and oranges, let us include the constraint that we seek the filter that maximizes $y(t_0)$ subject to the impulse response having a fixed energy, for example, subject to $$\int_{-\infty}^\infty |h(t)|^2\,\mathrm dt = \mathbb E = \int_{-\infty}^\infty |s(t)|^2 \,\mathrm dt.\tag{2}$$





Here onwards, "filter" shall mean a linear time-invariant filter whose impulse response satisfies (2).





The Cauchy-Schwarz inequality provides an answer to this question. We have $$y(t_0) = \int_{-\infty}^\infty s(t_0-t)h(t)\,\mathrm dt \leq \sqrt{\int_{-\infty}^\infty |s(t_0-t)|^2 \,\mathrm dt} \sqrt{\int_{-\infty}^\infty |h(t)|^2\,\mathrm dt} = \mathbb E$$ with equality occurring if $h(t) = \lambda s(t_0-t)$ with $\lambda > 0$ where from (2) we get that $\lambda = 1$, that is, the filter with impulse response $h(t) = s(t_0-t)$ produces the maximal response $y(t_0) = \mathbb E$ at the specified time $t_0$. In the (non-stochastic) sense described above, this filter is said to be



the filter matched to $s(t)$ at time $t_0$ or the matched filter for $s(t)$ at time $t_0.$




There are several points worth noting about this result.




  1. The output of the matched filter has a unique global maximum value of $\mathbb E$ at $t_0$; for any other $t$, we have $y(t) < y(t_0) = \mathbb E$.




  2. The impulse response $s(t_0-t) = s(-(t-t_0))$ of the matched filter for time $t_0$ is just $s(t)$ "reversed in time" and moved to the right by $t_0$.


    a. If $s(t)$ has finite support, say, $[0,T]$, then the matched filter is noncausal if $t_0 < T$.


    b. The filter matched to $s(t)$ at time $t_1 > t_0$ is just the filter matched at time $t_0$ with an additional delay of $t_1-t_0$. For this reason, some people call the filter with impulse response $s(-t)$, (that is, the filter matched to $s(t)$ at $t=0$) the matched filter for $s(t)$ with the understanding that the exact time of match can be incorporated into the discussion as and when needed. If $s(t) = 0$ for $t < 0$, then the matched filter is noncausal. With this, we can rephrase 1. as





  3. The matched filter for $s(t)$ produces a unique global maximum value $y(0) = \mathbb E$ at time $t=0$. Furthermore, $$y(t) = \int_{-\infty}^\infty s(t-\tau)s(-\tau)\,\mathrm d\tau = \int_{-\infty}^\infty s(\tau-t)s(\tau)\,\mathrm d\tau = R_s(t)$$ is the autocorrelation function of the signal $s(t)$. It is well-known, of course, that $R_s(t)$ is an even function of $t$ with a unique peak at the origin. Note that the output of the filter matched at time $t_0$ is just $R_s(t-t_0)$, the autocorrelation function delayed to peak at time $t_0$.




  4. No filter other than the matched filter for time $t_0$ can produce an output as large as $\mathbb E$ at $t_0$. However, for any $t_0$, it is possible to find filters that have outputs that exceed $R_s(t_0)$ at $t_0$. Note that $R_s(t_0) < \mathbb E$.




  5. The transfer function of the matched filter is $H(f)=S^*(f)$, the complex conjugate of the spectrum of $S(f)$. Thus, $Y(f) = \mathfrak F[y(t)]= |S(f)|^2$. Think of this result as follows. Since $x^2 > x$ for $x > 1$ and $x^2< x$ for $0 < x < 1$, the matched filter has low gain at those frequencies where $S(f)$ is small, and high gain at those frequencies where $S(f)$ is large. Thus, the matched filter is reducing the weak spectral components and enhancing the strong spectral components in $S(f)$. (It is also doing phase compensation to adjust all the "sinusoids" so that they all peak at $t=0$).





-------


But what about noise and SNR and stuff like that which is what the OP was asking about?


If the signal $s(t)$ plus additive white Gaussian noise with two-sided power spectral density $\frac{N_0}{2}$ is processed through a filter with impulse response $h(t)$, then the output noise process is a zero-mean stationary Gaussian process with autocorrelation function $\frac{N_0}{2}R_s(t)$. Thus, the variance is $$\sigma^2 = \frac{N_0}{2} R_s(0) = \frac{N_0}{2}\int_{-\infty}^{\infty} |h(t)|^2\,\mathrm dt.$$ It is important to note that the variance is the same regardless of when we sample the filter output. So, what choice of $h(t)$ will maximize the SNR $y(t_0)/\sigma$ at time $t_0$? Well, from the Cauchy-Schwarz inequality, we have $$\text{SNR} = \frac{y(t_0)}{\sigma} = \frac{\int_{-\infty}^\infty s(t_0-t)h(t)\,\mathrm dt}{\sqrt{\frac{N_0}{2}\int_{-\infty}^\infty |h(t)|^2\,\mathrm dt}} \leq \frac{\sqrt{\int_{-\infty}^\infty |s(t_0-t)|^2 \,\mathrm dt} \sqrt{\int_{-\infty}^\infty |h(t)|^2\,\mathrm dt}}{\sqrt{\frac{N_0}{2}\int_{-\infty}^\infty |h(t)|^2\,\mathrm dt}} = \sqrt{\frac{2\mathbb E}{N_0}}$$ with equality exactly when $h(t) = s(t_0-t)$, the filter that is matched to $s(t)$ at time $t_0$!! Note that $\sigma^2 = \mathbb EN_0/2$. If we use this matched filter for our desired sample time, then at other times $t_1$, the SNR will be $y(t_1)/\sigma < y(t_0)/\sigma = \sqrt{\frac{2\mathbb E}{N_0}}$. Could another filter give a larger SNR at time $t_1$? Sure, because $\sigma$ is the same for all filters under consideration, and we have noted above that it is possible to have a signal output larger than $y(t_1)$ at time $t_1$ by use of a different non-matched filter.


In short,




  • "does the matched filter maximize the SNR only at the sampling instant, or everywhere?" has the answer that the SNR is maximized only at the sampling instant $t_0$. At other times, other filters could give a larger SNR than what the matched filter is providing at time $t_1$, but this still smaller than the SNR $\sqrt{\frac{2\mathbb E}{N_0}}$ that the matched filter is giving you at $t_0$, and if desired, the matched filter could be redesigned to produce its peak at time $t_1$ instead of $t_0$.





  • "why not make a filter that makes a really tall skinny spike at the point of decision. Wouldn't that make the SNR even better?"
    The matched filter does produce a spike of sorts at the sampling time but it is constrained by the shape of the autocorrelation function. Any other filter that you can devise to produce a tall skinny (time-domain) spike is not a matched filter and so will not give you the largest possible SNR. Note that increasing the amplitude of the filter impulse response (or using a time-varying filter that boosts the gain at the time of sampling) does not change the SNR since both the signal and the noise standard deviation increase proportionately.




  • "The I&D will basically ramp up until it gets to the sampling time and the idea is that one samples at the peak of the I&D because at that point, the SNR is a maximum."
    For NRZ data and rectangular pulses, the matched filter impulse response is also a rectangular pulse. The integrate-and-dump circuit is a correlator whose output equals the matched filter output only at the sampling instants, and not in-between. See the figure below.




enter image description here


If you sample the correlator output at other times, you get noise with smaller variance but you can't simply add up the samples of I&D output taken at different times because the noise variables are highly correlated, and the net variance works out to be much larger. Nor should you expect to be able to take multiple samples from the matched filter output and combine them in any way to get a better SNR. It doesn't work. What you have in effect is a different filter, and you cannot do better than the (linear) matched filter in Gaussian noise; no nonlinear processing will give a smaller error probability than the matched fiter.



agada stories legends - Is the leviathan kosher?


The leviathan seems to be a unique sea creature, which I've always pictured as some sort of sea serpent. This is consistent with Yeshayahu 27:1's description of it as a snake (nachash). An answer to this question suggests that it's a fish (and doesn't address Yeshayahu). We know from the midrash that at the end of days the righteous will feed on it, whatever it is.


One could argue that because the righteous will feed on it, it must be a kosher fish. Or if the leviathan is a serpent, one could argue that when God holds this end-of-days banquet He can declare anything He wants to be permitted, culinarily speaking -- the laws of kashrut as we know them don't apply. (I've no idea if such an argument would be, err, kosher.)


Do any sources say if the leviathan is kosher by the laws of the torah?



Answer




The medrash tanchuma on parshas Shmini #7 takes the opinion that at that great feast of Beheimos and Leviason, the mitzvos which until now were only to purify/smelt the people with will no longer apply. The proof is that the Beheimos will not have a proper slaughtering, but will rather be killed by the Liviason. The medrash goes on to prove that Liviason is an abnormal strong creature, capable of killing Beheimos.


But throughout the entire discussion of proving that slaughtering will become obsolete, the medrash does not entertain the idea that Beheimos or Liviason are not kosher.


The Vayikra Rabba in chapter 22 states explicitly that it is kosher.


The Bavli in Chulin 67b says it is a kosher fish. The Maharsha asks would Hashem ever feed his Tzadikim nonkosher fish? He answers that the gemara is clarifying that Liviason is in fact a fish and not some other creature like a bird. The Iyun Yaakov answers this question by pointing to Yalkut on Shmini 535 and on Tehilim siman 146, that in fact in the future Hashem will allow what was not allowed beforehand and a New Torah will be given from Tzion. The Aruch ערך גא says the gemara needed to tell us it was kosher because it is mentioned along with a snake, so as to preclude the assumption that it is not kosher like a snake, we have the drasha in the gemara.


zero padding - What happens when N increases in N-point DFT




I am curious about DFT, and I wrote a simple MATLAB code to test what happens when $N$ increases. I took a rectangular signal with length $L=15$, an then found th DFT of 16, 32 and 64 points. I looked at the plots of the DFTs, however I could not understand why there is difference between them and how zero padding affects the DFT. Could someone explain it?



Answer



The length N of the DFT is the number of frequency points that will result in the DFT output. Zero padding will result in more frequency samples, however this does not increase frequency resolution, it just interpolates samples in the DTFT. The frequency resolution is given by $1/T$ where T is the time length of your data (regardless of sampling rate). So if you want to increase the actual frequency resolution, you need to increase the number of samples at a given sampling rate, or decrease the sampling rate which would increase the time length for the number of samples you have.


For further explanation on the difference between the DTFT and DFT, see my post response here:


For 2D signals can it be said that the frequency response is the same as the Fourier transform?


Here is a demonstration showing frequency resolution and zero padding. The two red squares on the frequency axis at the top of the picture denote the "true" frequency location for two test tones, at f1 = 0.26 and f2 = 0.28. Given the seperation of 0.02 in normalized frequency (cylces/sample) we would need to have greater than 1/0.02 = 50 samples to resolve the two frequencies. The top plot shows the result of having only 10 samples of the data and zero padding out the time domain data for final datasets of 10 (no padding), 20, 50 and 100. We clearly see in this plot that as we add more samples, we interpolate more frequency points, but it does not offer any further information about the individual frequency content of our two tones.


Below that is another plot where instead of just adding zeros, we increase the number of samples in our dataset with the same two frequency tones present and again take the DFT with 10, 20, 50 and 100 samples. At 50 samples we have enough frequency resolution for our separation in frequency (but still difficult to see on the plot), while at 100 samples the separation is clearly visible.


enter image description here


enter image description here



Why is this? Padding with zeros is the same as multiplying the longer sequence with a rectangular window. Multiplying the time domain sequences is the same as convolution in the frequency domain (circular convolution for the DFT). The time domain rectangular window that we effectively used for the example above, and the resulting DFT of the window itself is shown in the plot below. The DFT of the window is what would convolve with our original frequencies. As the time length of the window increases, the width of the main lobe of its transform in frequency gets more narrow (the nulls are located at 1/T) and therefore the frequency resolution increases.


enter image description here


repentance teshuvah - Why don't Jews sacrifice animals anymore?


Correct me if I'm wrong, but Jews do not currently sacrifice animals like ancestors long ago. Why do Jews not currently sacrifice animals? Will there be a time when sacrificing returns once again? How are sins forgiven if an animal is not sacrificed to cover for those sins?




words - The definitions of Judaism and Jew


An infinite loop:


Judaism according to Google is "the monotheistic religion of the Jews".


And Jew is "a member of the people and cultural community whose traditional religion is Judaism and who trace their origins through the ancient Hebrew people of Israel to Abraham."





What are the best, the most precise definitions of both terms?




halacha theory - Different counts of the 248 organs - bones or soft tissues?


First read the related questions here (mitzvot-and-their-body-parts and here (613-organs).


The Mishnah in Ohalot (1:8) states that there are 248 organs and lists all of them:



"מָאתַיִם וְאַרְבָּעִים וּשְׁמֹנָה אֵבָרִים בָּאָדָם, שְׁלשִׁים בְּפִסַּת הָרֶגֶל, שִׁשָּׁה בְכָל אֶצְבַּע, עֲשָׂרָה בַקֻּרְסָל, שְׁנַיִם בַּשּׁוֹק, חֲמִשָּׁה בָאַרְכֻּבָּה, אֶחָד בַּיָּרֵךְ, שְׁלשָׁה בַקַּטְלִית, אַחַת עֶשְׂרֵה צְלָעוֹת, שְׁלשִׁים בְּפִסַּת הַיָּד, שִׁשָּׁה בְכָל אֶצְבַּע, שְׁנַיִם בַּקָּנֶה, וּשְׁנַיִם בַּמַּרְפֵּק, אֶחָד בַּזְּרוֹעַ, וְאַרְבָּעָה בַכָּתֵף. מֵאָה וְאֶחָד מִזֶּה וּמֵאָה וְאֶחָד מִזֶּה. וּשְׁמֹנֶה עֶשְׂרֵה חֻלְיוֹת בַּשִּׁדְרָה, תִּשְׁעָה בָרֹאשׁ, שְׁמֹנָה בַצַּוָּאר, שִׁשָּׁה בַמַּפְתֵּחַ שֶׁל לֵב, וַחֲמִשָּׁה בִנְקָבָיו. :


There are two hundred and forty-eight limbs in the body. Thirty in the foot - six in each toe, ten in the ankle, two in the shin, five in the knee, one in the thigh, three in the hip, eleven ribs, thirty in the palm - six in each finger, two in the forearm, two in the elbow, one in the upper arm, and four in the shoulder. One hundred and one of this [side of the body], and one hundred and one of that. And eighteen vertebrates in the spinal chord: nine in the head, eight in the neck, six in the openings of the heart, and five around its cavities.



However it elaborates the purpose of this counting as:



כָּל אֶחָד וְאֶחָד מְטַמֵּא בְמַגָּע וּבְמַשָּׂא וּבְאֹהֶל. אֵימָתַי, בִּזְמַן שֶׁיֵּשׁ עֲלֵיהֶן בָּשָׂר כָּרָאוּי. אֲבָל אִם אֵין עֲלֵיהֶן בָּשָׂר כָּרָאוּי, מְטַמְּאִין בְּמַגָּע וּבְמַשָּׂא, וְאֵין מְטַמְּאִין בְּאֹהֶל



Each of these impurifies through touching, carrying, or sharing quarters. When is this true? When the limbs still have an appropriate amount of flesh on them. But if they do not have an appropriate amount of flesh on them, they will impurify through touching and through carrying, but not through sharing quarters.



It is clear that only the bones are counted, hence the original "אברים" is translated as "limbs" and not organs. We don't see the soft tissues, like skin, muscles, eyes, tongue, brain, lungs etc.


Rambam in Hilchot Tumat Met 2,3 adds that the soft tissues are considered אברים also:



מה אדם בשר וגידים ועצמות אף אבר מן החי עד שיהיה כברייתו בשר וגידים ועצמות אבל הכוליא והלשון וכיוצא בהן אף על פי שהן אבר בפני עצמן הואיל ואין בהן עצם הרי הן כשאר הבשר


Implied is that the bone must be like a man, i.e., a human corpse. Just as a human corpse has flesh, sinews, and bones, so too, a limb from a living person must be intact as it was when it came into being and have flesh, sinews, and bones. In contrast, a kidney and a tongue, and the like, even though they are considered as complete ORGANS, since they do not contain bones, they are considered as the remainder of a person's flesh.



Combining the Mishna with Rambam we can count more than 248 organs, as it includes 248 bones plus the soft organs. Another slightly contradicting source is the Mishna in Negayim 6:




"עֶשְׂרִים וְאַרְבָּעָה רָאשֵׁי אֵבָרִין בָּאָדָם שֶׁאֵינָן מִטַּמְּאִין מִשּׁוּם מִחְיָה, רָאשֵׁי אֶצְבְּעוֹת יָדַיִם וְרַגְלַיִם, וְרָאשֵׁי אָזְנַיִם, וְרֹאשׁ הַחֹטֶם, וְרֹאשׁ הַגְּוִיָּה, וְרָאשֵׁי הַדַּדִּים שֶׁבָּאִשָּׁה."


There are twenty-four tips of limbs on man that do not become impure due to a healthy patch [seen in a Nega]: The tips of the fingers of the hands and feet [i.e. toes], the tips of the ears, the tip of the nose, the tip of the male organ, the tips of the breasts on a woman.



As we see it lists organs not listed in the Mishna in Ohalot.


I am confused - Is this a different counting of the 248 body organs, or is this the only one:



  • If it is different - where are the others?

  • If that's the only one, where are the soft organs counted?




ions - Deuterium removal from water


What percentage of deuterium might be removed from water after a typical electrolysis procedure? From a post on this site I read that, "In the first stage, $\ce{NaOH}$ solution (initially $0.5\rm{M}$) is subject to electrolysis, until only $\frac{1}{32}$ of the original volume remains. This increased the original concentration of deuterium by a factor of $12$."



This seems to be, for the electrolyzed hydrogen, an approximate $38\%$ decrease from the original concentration. If we assume the original concentration was $150\rm{ppm}$ then after the first pass, we might expect to have $93\rm{ppm}$ in the deuterium reduced hydrogen. If my estimate is valid, may I expect that each successive pass would reduce the deuterium content by a similar percentage?




digital communications - Understanding the Matched Filter

I have a question about matched filtering. Does the matched filter maximise the SNR at the moment of decision only? As far as I understand, ...