Friday, October 26, 2018

Is a leaky integrator the same thing as a low pass filter?


The equation governing a leaky integrator (according to Wikipedia at least) is


$\frac{d\mathcal{O}}{dt} + A\mathcal{O}(t) = \mathcal{I}(t)$.


Is a continuous-time leaky integrator thus the same thing as a low pass filter with time-constant $A$, up to some scaling of the input?



Answer



A so-called leaky integrator is a first-order filter with feedback. Let's find its transfer function, assuming that the input is $x(t)$ and the output $y(t)$:


$$ \frac{dy(t)}{dt} + Ay(t) = x(t) $$


$$ \mathcal{L}\left\{\frac{dy(t)}{dt} + Ay(t)\right\} = \mathcal{L}\left\{x(t)\right\} $$


where $\mathcal{L}$ denotes application of the Laplace transform. Moving forward:


$$ sY(s) + AY(s) = X(s) $$



$$ H(s) = \frac{Y(s)}{X(s)} = \frac{1}{s + A} $$


(taking advantage of the Laplace transform's property that $\frac{dy(t)}{dt} \Leftrightarrow sY(s)$, assuming that $y(0) = 0$).


This system, with transfer function $H(s)$, has a single pole at $s = -A$. Remember that its frequency response at frequency $\omega$ can be found by letting $s=j\omega$:


$$ H(j\omega) = \frac{1}{j\omega + A} $$


To get a rough view of this response, first let $\omega \to 0$:


$$ \lim_{\omega \to 0} H(\omega) = \frac{1}{A} $$


So the system's DC gain is inversely proportional to the feedback factor $A$. Next, let $w \to \infty$:


$$ \lim_{\omega \to \infty} H(\omega) = 0 $$


The system's frequency response therefore goes to zero for high frequencies. This follows the rough prototype of a lowpass filter. To answer your other question with respect to its time constant, it's worth checking out the system's time-domain response. Its impulse response can be found by inverse-transforming the transfer function:


$$ H(s) = \frac{1}{s+A} \Leftrightarrow e^{-At}u(t) = h(t) $$



where $u(t)$ is the Heaviside step function. This is a very common transform that can often be found in tables of Laplace transforms. This impulse response is an exponential decay function, which is usually written in the following format:


$$ h(t) = e^{-\frac{t}{\tau}}u(t) $$


where $\tau$ is defined to be the function's time constant. So, in your example, the system's time constant is $\tau = \frac{1}{A}$.


matlab - Frequency vector and fft


I have got a question concerning the definition of the frequency vector for an fft operation.


Generally, I work with a frequency vector, f, with power of 2 elements (2048, 4096, 8192, ...).



Given a certain simulation analysis time, time (e.g. 600s), I should define f as follows:


% Frequency defition
t = 0:dt:(time-dt);
df = 1/(time);
fn = Nfft/time;

$$ f = -f_{n}/2:df:f_{n}/2-1; $$


where $ f_{n} $ represent the Nyquist cut-off frequency.


Actually, for:




  • computational reasons

  • symmetry of the power spectra along f axis

  • not throwing away real or imag part of the fft


I aim to define only half of the frequency range, as for example


$$ f = 0:df:f_{n}/2-1; $$


After calling the fft of my input signal, I would get the desired time series as


ouput = [real(fft) imag(fft)];

But, this way, I count the 0 frequency term twice and the -fn/2 is completely discarded.



How would it be possible to emcompasses the whole standard frequency range starting from only half of it?



Answer



The proper way to define your frequency vector after a DFT is as follows. Let $N$ be your DFT length, and $f_s$ be your sampling rate in Hz. Furthermore, define an $N$-length frequency vector $\bf{f}$, where each element $f_i = i$, for $i = 0, 1, 2, ... N-1$.


Now your frequency vector in hertz is simply going to be $\bf{f}$$\frac{f_s}{N}$


Now, assuming you are DFT'ing a real sequence, simply pick all elements with frequency values less than $\frac{f_s}{2}$, and you are in business!


You can also see my answer here for actual code.


halacha - Reading a newspaper


Are there any works that discuss the permissibility of reading secular newspapers on a weekday? The Ketzos HaShulchan (Badei HaShulchan 107:43) holds that it's forbidden:



Other [i.e. not Torah] newspapers in our generation are pretty much all against G-d and His anointed and are full of dirty jokes, heresy, and atheism, unfortunately, and even on a weekday it is forbidden to read them. Even if someone only wants to read the news part brought in the newspapers, it's still forbidden, lest he continue to read the other bad parts ... [Someone who reads them] transgresses "Don't turn to the idols" and strengthens his yetzer hara against himself ... Many people stumble in this area because they don't impart to themselves the enormity of the prohibition; someone who cares about his soul should distance himself from them, because these newspapers have made many dead fall.



Shmiras Shabbas KeHilchasah (second edition, ch. 21 note 117) quotes this source and doesn't bring a dissenting view.


The practice seems to be to read newspapers. I was wondering if there was a discussion of this in the modern poskim. (It's said that the Netziv would read the newspaper on Shabbas, but his position isn't clear — we don't know his exact reasoning. I'm looking for modern poskim who specifically speak about the issue and aren't just quoted as having read it or say it as a side point so I can see their reasons, etc.)


It was also asked about Reading a newspaper on Shabbat, but this is dealing with weekdays.




halacha - What is the point of a hechsher on Cholov Stam?


I assume that the widespread custom of eating/drinking Cholov Stam products (products using milk in which the milking was not observed by a Jew) is relying on the leniency of R' Moshe Feinstein that the government supervision and FDA oversight is enough to assume the kosher status of the milk. If so, why are there some brands of milk that have a hechsher, which is not a Cholov Yisroel hechsher? If you aren't being stringent for Cholov Yisroel and the hechsher is not accomplishing that, what is the purpose of the hechsher?



If the answer is that there is no purpose, is it dishonest of Kashrus agencies to take money for a useless hechsher?



Answer



Yoni is correct, companies ask for kosher certifications for all sorts of reasons. (I know a rabbi who had his phone ringing off the hook from two American sugar companies begging for certification. Neither needed it from the laws of kosher per se, but both were hoping to sell to a confection company that had made a simple blanket rule, "all our suppliers must have kosher certification.") But there are actually other issues (at least in the USA) besides the milk per se. Vitamin D can be synthesized from mineral ingredients, or can be "all natural" from marine creatures. (After-the-fact it would be batel as it's not a flavor or enzyme.) The line could also produce chocolate milk or the like. Most of these problems would likely be batel after the fact, but many prefer to follow the Rashba's opinion that bitul is only relied upon in cases of mistakes.


Thursday, October 25, 2018

filters - Create a third octave spectrum from a time signal



I have to create a third-octave spectrum from a time signal on Octave GNU.
I found some code on the net to help me but I don't have all the parts of the algorithm.


I have a .csv file which contains a simple sinus temporal signal. The specifications are:



  • Duration: 0 to 180s

  • Frequency: 32768


I calculate the octave bands from 10Hz to 10kHz :


    fMin=10;
fMax=10000;

octs=log2(fMax/fMin);
bmax=ceil(octs/bw);

%Octave bands.
fc=fMin*2.^((0:bmax)*bw); %Center frequencies.
fl=fc*2^(-bw/2); %Lower frequencies.
fu=fc*2^(+bw/2); %Upper frequencies

After I can display all the third octave filters using Butterworth filters :


    bw = 1/3;

numBands = length(fc);

b = cell(numBands,1);
a = cell(numBands,1);

figure
for nn=1:length(fc)
[b{nn}, a{nn}] = butter(2,[fl(nn) fu(nn)]/(fs/2));
[h,f] = freqz(b{nn}, a{nn}, 1024, fs);


hold on;
plot(f, 20*log10(abs(h)));
end
set(gca, 'XScale', 'log')
ylim([-50 0])

Which gives to me :


enter image description here


The last filters are great but the first ones have missing points.
I don't know how to fix that and, mainly, how can I use this to make my third octave spectrum.

Does someone knows how to do this ?



Answer



Hate to answer this question, but it is a plotting issue, not the actual design problem. Basically, you don't have enough points at low frequencies cause they are spaced linearly and you are plotting on logarithmic scale. You could do:


[h,f] = freqz(b{nn}, a{nn}, logspace(log10(fMin), log10(fMax), 1000), fs);

Explicitly specifying the logarithmically spaced bins. Or you can use a very large N (something like $2^{16}$).


enter image description here


product recommendation - Good sources for Mishkan and Beis Hamikdash study


Anyone aware of any website, book, or video that you consider a really good resource for Mishkan and Beis Hamikdash study? It would optimally include diagrams, video animations, and other interactive stuff. And why do you recommend it?



Answer



I enjoy my copy of Carta’s Illustrated Encyclopedia of the Holy Temple in Jerusalem. It does a great job of helping the reader picture the architecture of the Mishkan and Beit Hamikdash and the service in them. I frequently refer to it for illustration when discussing these topics.


I also have enjoyed the novels I've read from the "Naftali in the Mikdash" series by Yaakov Meir Strauss. They try to give you a sense of what it was like to live in Israel when the Beit Hamikdash stood. Sometimes, the Halachic exposition is a bit forced, but if you don't mind the fact that you're learning the Halachot as you go a long, it's an enjoyable educational experience.


electrons - Hypervalency in elements in the second period


In my experience, most texts that address hypervalency say that it only occurs from elements in the 3rd period and onwards. This explains the occurrence of $\ce{Cl2O7}$ or chlorine heptoxide. However, some 2nd period nonmetals like $\ce{C}$ and $\ce{O}$ show hypervalency.


Examples:



  • $\ce{CH5}$ - This is unlikely to occur but it does sometimes happen that carbon bonds to 5 atoms instead of 4.

  • $\ce{H3O+}$ - Here oxygen is hypervalent.



How is it possible for carbon and oxygen to each have 9 electrons if each orbital only holds 2 electrons? Do they switch between electrons or something?



Answer



Normally when we talk about a single covalent bond, we are referring to a 2-centre 2-electron bond, which means that there are two electrons holding two atoms together.


Carbon never forms 5 bonds. The only exception that I know of is the $\ce{CH5+}$ methanium cation, the bonding in which can be explained by a 3-centre-2-electron bond. The same kind of bond appears in diborane ($\ce{B2H6}$). In both cases, the octet rule (or duplet rule in the case of the bridging hydrogens in diborane) is not violated. It is just that those 2 electrons are shared amongst 3 different atoms, so each "bond" is effectively half a bond (in MO theory parlance we say that the bond order is 0.5). You could think of it as three of the C-H bonds being normal 2-electron bonds, and two of the C-H bonds being half-bonds (having one electron each). The total number of electrons around carbon is therefore $3 \times 2 + 1 + 1 = 8$.


The neutral species $\ce{CH5}$ does not exist, because it has one more electron than the $\ce{CH5+}$ cation. That would mean that you either have to put 9 electrons around carbon, or put 3 electrons around hydrogen, both of which are of course not allowed.


The hydronium ion $\ce{H3O+}$ is not actually hypervalent. It is similar to the ammonium ion $\ce{NH4+}$ in that a dative bond is formed from the lone pair on O to a $\ce{H+}$ ion.


periodic trends - Comparing radii in lithium, beryllium, magnesium, aluminium and sodium ions

Apparently the of last four, $\ce{Mg^2+}$ is closest in radius to $\ce{Li+}$. Is this true, and if so, why would a whole larger shell ($\ce{...