text
stringlengths
81
47k
source
stringlengths
59
147
Question: <p>I'm using two microcontrollers to implement an adaptive LMS filter to filter out the noise from the signal. One is recording the noise and streaming the data to the other microcontroller which is recording the (noised) signal and using the noise reference, filtering it out.</p> <p>How does the delay between those signal affect the filtering quality? Say the noise reference input is delayed for 100us/1ms/10ms/100ms/1s, how does that affect the filtering process?</p> Answer: <p>The adaptive filter tries to emulate the assumed filtering process between the noise reference signal and the actual noise in the noisy signal. </p> <p>If $n(t)$ is the actual noise in the noisy signal, and $n_r(t)$ is the noise reference, it is assumed that there's a linear filtering relationship between the two:</p> <p>$$n(t)=(n_r*h)(t)$$</p> <p>where $*$ denotes convolution (filtering), and $h(t)$ is some unknown impulse response, which should be approximated by the adaptive filter.</p> <p>The practical effect of a delay of the noise reference depends on the impulse response $h(t)$. A delay of $\tau$ in the noise reference means that the adaptive filter needs to model $h(t+\tau)$ instead of $h(t)$. This can be a good thing if $h(t)$ is almost zero in the interval $0&lt;t&lt;\tau$, because then optimal use is made of the length of the adaptive filter. However, if there is significant energy in $h(t)$ in that interval, then, after delaying the noise reference, the adaptive filter must approximate a non-causal filter, which it will have a very hard time to do.</p> <p>So in general, a delay of the reference signal results in a shifting of the impulse response that needs to be approximated by the adaptive filter. If this shifting is helpful or not depends on the amount of shift and the properties of the impulse response.</p>
https://dsp.stackexchange.com/questions/26664/lms-adaptive-filter-relatively-delayed-signal-and-reference-inputs
Question: <p>The MATLAB code below is for equalizer using lms algorithm adaptive filter and then plotting MSE (Mean Square Error) Vs Iteration numbers</p> <hr /> <pre><code>%% Channel Equalization using Least Mean Square (LMS) algorithm % Author: SHUJAAT KHAN clc;clear all;close all; %% Channel and noise level h = [0.9 0.3 0.5 -0.1]; % Channel SNRr = 10; % Noise Level %% Input/Output data N = 1000; % Number of samples Bits = 2; % Number of bits for modulation (2-bit for Binary modulation) data = randi([0 1],1,N); % Random signal d = real(qammod(data,Bits)); % BPSK Modulated signal (desired/output) r = filter(h,1,d); % Signal after passing through channel x = awgn(r, SNRr); % Noisy Signal after channel (given/input) %% LMS parameters epoch = 50; % Number of epochs (training repmiotion) mio = 1e-3; % Learning rate / step size order=12; % Order of the equalizer U = zeros(1,order); % Input frame W = zeros(1,order); % Initial Weigths %% LMS Algorithm for k = 1 : epoch for n = 1 : N U(1,2:end) = U(1,1:end-1); % Sliding window U(1,1) = x(n); % Present Input y = (W)*U'; % Calculating output of LMS e(n) = d(n) - y; % Instantaneous error W = W + mio * e(n) * U ; % Weight update rule of LMS J(k,n) = e(n) * e(n)'; % Instantaneous square error end end %% Calculation of performance parameters MJ = mean(J,2); % Mean square error %% Plots figure % MSE plot(10*log10(MJ),'linewidth',lw) hg=legend('MSE','Location','Best'); grid minor xlabel('Epochs iterations'); ylabel('Mean squared error (dB)'); title('Cost function'); </code></pre> <hr /> <p>But the curve plotted is unexpected, as the MSE should have fluctuations across iterations and to be very smooth like that as it LMS algorithm is used</p> <p>That's because it doesn't take the Expectation in the adaptive equation.</p> <p>The curve plotted is as the following:</p> <p>[<img src="https://i.sstatic.net/QXMoq.png" alt="The output of MATLAB code1" /></p> <p>Where the expected plot is as the following:</p> <p><a href="https://i.sstatic.net/fl2ai.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/fl2ai.png" alt="The expected output" /></a></p> Answer:
https://dsp.stackexchange.com/questions/72047/matlab-model-for-equalizer-using-lms-algorithm-adaptive-filter-and-unexpected-ou
Question: <p>How would the LMS equalizer dimensions change for the MISO case?</p> <p>LMS adaptive filters are typically described for equalizing a single input signal, <span class="math-container">$x(t)$</span>. Can the LMS algorithm be modified in the MISO case to perform diversity combining when the transmitter has <span class="math-container">$N=1$</span> antennas, the receiver has <span class="math-container">$M&gt;1$</span> antennas?</p> <p>For the LMS algorithm, assume <span class="math-container">$n$</span> is the number of the current input sample and <span class="math-container">$p$</span> is the number of filter taps.</p> <p><span class="math-container">$$ \begin{aligned} \mathbf x(n) &amp;= \begin{bmatrix}x(n)&amp; x(n-1)&amp; \cdots &amp; x(n-p+1)\end{bmatrix}^T \\ e(n) &amp;= d(n) - \hat h(n)^Hx(n) \\ \hat h(n+1) &amp;= \hat h(n) + \mu e^*(n)x(n) \end{aligned} $$</span> where dimensions are:</p> <p><span class="math-container">$\mathbf x(n) $</span> = <span class="math-container">$p\times 1$</span> vector<br /> <span class="math-container">$\hat h(n)^Hx(n) $</span> = <span class="math-container">$[1 \times p]$</span> * <span class="math-container">$[p \times 1]$</span> = <span class="math-container">$1\times1$</span><br /> <span class="math-container">$e(n)$</span> = scalar<br /> <span class="math-container">$\hat h(n)$</span> = <span class="math-container">$p\times 1$</span> vector</p> <p>Now define the <span class="math-container">$M$</span> received vectors, <span class="math-container">$r(n)$</span>, corresponding to the collected samples from each receiver, <span class="math-container">$r(n) = [r_1(n), r_2(n),...,r_M(n)]$</span></p> <p>There are two ways I can think of to incorporate the additional received vectors.</p> <p>The first way is to change the dimensions of <span class="math-container">$x(n)$</span> such that it is <span class="math-container">$p\times M$</span></p> <p><span class="math-container">$x(n) = [r_1(n), r_2(n),...,r_M(n)]^T$</span></p> <p>This would result in the dimensions changing as follows:</p> <p><span class="math-container">$\mathbf x(n) $</span> = <span class="math-container">$p\times M$</span> matrix<br /> <span class="math-container">$\hat h(n)^Hx(n) $</span> = <span class="math-container">$[M \times p]$</span> * <span class="math-container">$[p \times M]$</span> = <span class="math-container">$M \times M$</span> &lt;-- should this be dot product or summed?<br /> <span class="math-container">$e(n)$</span> = scalar<br /> <span class="math-container">$\hat h(n)$</span> = <span class="math-container">$p\times M$</span> matrix</p> <p>The second way is how one of the answers proposed, is to concatenate individual inputs into <span class="math-container">$x(n)$</span>. This would result in a dimension of <span class="math-container">$Mp$</span>.</p> <p><span class="math-container">$x(n) = [r_1(n) r_2(n),...,r_m(n),...r_m(n-p+1]^T$</span></p> <p>In practice we almost always use a fractionally spaced equalizer so the technique would require to scale for that use case. The first way could be extended for the fractionally spaced equalizer case, but the second way doesn't seem like it could. Are either of these right, or is there another way, or is it not possible ?</p> <p>Note: more details on LMS <a href="https://en.wikipedia.org/wiki/Least_mean_squares_filter" rel="nofollow noreferrer">here</a>.</p> Answer: <p>I'm surprised I couldn't find a decent reference for this on the web.</p> <p>Terminology gets difficult. Let <span class="math-container">$s(n)$</span> (a scalar) be the transmitted information. Let there be <span class="math-container">$M$</span> inputs. Let <span class="math-container">$\mathbf r(n)$</span> be the received vector at each instant, <span class="math-container">$$ \mathbf r(n) = \begin{bmatrix} r_1(n) \\ r_2(n) \\ \vdots \\ r_M(n) \end{bmatrix}, \tag 1$$</span> where each <span class="math-container">$r_m(n)$</span> is some linear combination of <span class="math-container">$\begin{matrix} s(n), &amp; s(n-1), \cdots \end{matrix}$</span>.</p> <p>Then it <em>ought</em> to work if you let the <span class="math-container">$\mathbf x (n)$</span> above equal a concatenation of the individual inputs, i.e. <span class="math-container">$$\mathbf x (n) = \begin{bmatrix}r_1(n) &amp; r_2(n) &amp; \cdots &amp; r_m(n) &amp; r_1(n - 1) &amp; \cdots &amp; r_m(n-p+1)\end{bmatrix}^T. \tag 2$$</span></p> <p>Then just do the rest &quot;naturally&quot;, using the equations you cite above.</p> <p>The length would become <span class="math-container">$Mp$</span>, where <span class="math-container">$M$</span> is the number of inputs and <span class="math-container">$p$</span> is the number of points you take into the past.</p>
https://dsp.stackexchange.com/questions/84076/can-a-lms-adaptive-filter-be-adapted-for-miso
Question: <p>The algorithms given for <a href="https://en.wikipedia.org/wiki/Recursive_least_squares_filter#Lattice_recursive_least_squares_filter_(LRLS)" rel="nofollow noreferrer">un-normalized LRLS</a> and <a href="https://en.wikipedia.org/wiki/Recursive_least_squares_filter#Normalized_lattice_recursive_least_squares_filter_(NLRLS)" rel="nofollow noreferrer">normalized LRLS</a> filters on Wikipedia are transcribed from Adaptive Filtering Algorithms and Practical Implementation by Paulo S. R. Diniz. In reading the book, I noticed the author has this to say of the forgetting factor λ.</p> <blockquote> <p>Another interesting feature of the normalized lattice algorithm is that the forgetting factor λ does not appear in the internal updating equations; it appears only in the calculation of the energy of the input and reference signals. This property may be advantageous from the computational point of view in situations where there is a need to vary the value of λ.</p> </blockquote> <p>I do not understand whether the author is saying that updating the factor is impossible with the un-normalized form, or computationally expensive. Nor do I understand what prevents one from updating the factor over time when using the un-normalized form. To me, it looks simple to parameterize the forgetting factor in terms of k for either algorithm. Could someone help me shed light on precisely what is meant here and why it is true?</p> Answer:
https://dsp.stackexchange.com/questions/61544/updating-forgetting-factor-in-un-normalized-lattice-recursive-least-squares-adap
Question: <p>One way of separating downgoing and upgoing wavefields in offshore seimic processing is to add signals from hydrophone and vertical component of the geophone (they are co-located). Hydrophone only registers a change in the pressure whereas geohphone as well as registering a change in seismic field also reacts to the direction of arriving wave, ie. if it is coming from above or below (sensors are deployed on sea floor). But the scale of the two are different as they record two different physical quantities. In addition, there is a phase difference between the two. To do the summation, I first need to re-scale one to the other and phase shift. The phase shift is slightly frequency dependent. I would like to make a filter that does the above on a period of data and then use the filter on all incoming data. The figure below shows an example of an upcoming signal (hydrophone signal has been downscaled for the exmple. In reality it is of much higher amplitude). If the two were of same scale and in phase then summing them will double the signal's amplitude while reducing the noise coming from above. I have some solution in time domain (assuming constant phase shift and scaling factor) and frequency domain by multiplying one's spectra with the transfer function between the two (found from spectral division). I have also used 'nlms' adaptive filtering. But some noise still remains, enough to make trouble later on. Wonder if anyone has a suggestion on how to make the filter or some Matlab code. Thanks <a href="https://i.sstatic.net/4sHvI.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4sHvI.png" alt="enter image description here"></a></p> Answer: <p>It seems that you want to equalize one time series to the other or vice versa or some combination. The general problem is then (in shorthand) $$ h_1{\Large *}y_1 \approx h_2{\Large *}y_2 $$ where $\Large *$ denotes convolution, $h_i$ are filters, and $y_i$ are your time series. If you simply equalize one time series to the other, this is $$ y_1 \approx h_2{\Large *} y_2 $$</p> <p>In matrix form, this becomes $$ \left[\begin{array}{c} y_1[p]\\y_1[p+1]\\\vdots\\y_1[p+N-1]\end{array}\right] \approx \left[\begin{array}{cccc}y_2[2p] &amp; y_2[2p-1] &amp; \cdots &amp; y_2[0]\\ y_2[2p+1] &amp; y_2[2p] &amp; \cdots &amp; y_2[1]\\ \vdots &amp; \ddots &amp; \ddots &amp; \vdots \\ y_2[2p+N-1] &amp; y_2[2p+N-2] &amp; \cdots &amp; y_2[N-1] \end{array}\right] \left[\begin{array}{c}h_2[0]\\h_2[1]\\\vdots\\h_2[2p] \end{array}\right] $$ or more concisely $$ \underline{y}_1 \approx {\bf Y_2}\underline{h}_2 $$ The least squares solution for the equalizing filter coefficient vector is $$ \underline{h}_{2,LS} = \left({\bf Y_2^HY_2}\right)^{-1}{\bf Y_2^H}\underline{y}_1 $$</p> <p>You can alternatively use LMS or RLS to do recursive updates to find/track $\underline{h}_2$.</p> <p>One additional comment on equalizing one time series to the other: by choosing to equalize $\underline{y}_2$ to $\underline{y}_1$, we choose one spectral weighting - implicitly. If we instead equalized $\underline{y}_1$ to $\underline{y}_2$, we would have a slightly different spectral weight for the overall least squares fit. If the filters are relatively minor in magnitude variation over the signal band, the spectral weight difference is similarly minor, but if the equalizer filter response is quite different for the two cases (can just as well solve and analyze both), you will need to assess which is preferred/better and why.</p>
https://dsp.stackexchange.com/questions/49221/adaptive-filter-to-scale-and-phase-shift-two-sensors-output
Question: <p>This wikipedia page <a href="https://en.wikipedia.org/wiki/Recursive_least_squares_filter" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Recursive_least_squares_filter</a> (and in fact other sources) do not explain the apparent paradox of the cost function that computes the MSE of the output and the &quot;desired&quot; (or &quot;ideal&quot;) signal.</p> <p>For someone who tries, like me, to understand this RLS algorithm, it seems a priori absurd to compute a cost function w.r.t. a signal that we do not know, and that we are looking for : this &quot;desired&quot; signal !</p> <p>I have trained neural nets in a supervised learning manner, i.e. with a &quot;ground truth&quot; so this is the only scenario that I can imagine where we have access to a &quot;desired&quot; signal... but for the adaptive filter, there is no &quot;training&quot; mentioned and as I understand it should continuously adapt its parameters in real time as the input signal (to be filtered) arrives (so training would not really make any sense anyway ?)... So can anyone please explain clearly what this desired signal means ? Especially in the context of filtering a signal corrupted by e.g. noise or other perturbations, for example the wiki example of the ECG corrupted by AC noise. They never explain what this &quot;ideal signal&quot; is... it seems absurd because we DO NOT KNOW the clean ECG signal, this IS what we try to obtain with the filter ... how could we compute any cost function then?</p> <p>Also, this wiki page should clearly be modified to explain this apparent absurdity. I really don't see how someone who tries to learn about these filters could understand anything about this without this basic explanation.</p> Answer: <p>A good example of an adaptive filter is an Acoustic Echo Canceller as shown in this <a href="https://www.researchgate.net/profile/Mirco-Ravanelli-2/publication/275637439/figure/fig2/AS:614318697619469@1523476399262/Principle-of-acoustic-echo-cancellation-x-is-the-known-signal-emitted-by-a-loudspeaker.png" rel="nofollow noreferrer">picture</a> (<a href="https://www.researchgate.net/figure/Principle-of-acoustic-echo-cancellation-x-is-the-known-signal-emitted-by-a-loudspeaker_fig2_275637439" rel="nofollow noreferrer">source</a>)</p> <p>The problem here is that the sound emitted by the loudspeaker will be picked up from the microphone and needs to be removed to get the &quot;clean&quot; speech signal. Ignoring the noise (<span class="math-container">$w$</span> in the picture) the signal at the microphone, <span class="math-container">$m(t)$</span> is</p> <p><span class="math-container">$$m(t) = v(t) + x(t)*h(t) \tag{1}$$</span></p> <p>where <span class="math-container">$v(t)$</span> is the speech signal, <span class="math-container">$x(t)$</span> is the input signal to the loudspeaker, <span class="math-container">$h(t)$</span> is the room impulse response (RIR), and <span class="math-container">$*$</span> the convolution operator. We DO know the input to the loudspeaker but we don't know the RIR and often it's time variant as speaker and/or microphone move around.</p> <p>We want the adaptive filter to estimate the RIR: we give it <span class="math-container">$x(t)$</span> as the input and <span class="math-container">$m(t)$</span> as the desired signal. An adaptive filter minimizes the error, <span class="math-container">$E$</span>, between the input and the desired signal which we can write as:</p> <p><span class="math-container">$$E = &lt;(x(t)*\hat{h}(t) - m(t))^2&gt; \tag{2}$$</span></p> <p>The error is clearly minimized if the response, <span class="math-container">$\hat{h}(t)$</span>, of the adaptive filter is identical to the RIR, i.e. <span class="math-container">$\hat{h}(t) = h(t)$</span> and that's what the adaptive filter will try to converge to.</p> <p>In other words: we use the adaptive filter to estimate the RIR so we can remove as much of the filtered loudspeaker signal as possible. The best estimate of the speech signal is simply the residual error:</p> <p><span class="math-container">$$v(t) \approx m(t) - x(t)*\hat{h}(t) \tag{3}$$</span></p> <blockquote> <p>signal that we do not know, and that we are looking for : this &quot;desired&quot; signal !</p> </blockquote> <p>You misunderstand &quot;desired&quot; here. It doesn't mean <strong>&quot;it's the thing we want to calculate&quot;</strong>. It just means <strong>&quot;it's the target for the adaptive filter&quot;</strong>. In most cases we use adaptive filters to identify impulse responses we don't know using signals we do know, which includes the &quot;desired&quot; signal. You can argue the naming convention, but it's the established name for it.</p> <blockquote> <p>Also, this wiki page should clearly be modified to explain this apparent absurdity</p> </blockquote> <p>There is no need for this type of language. I understand you are frustrated, but the page works just fine for many other people. The page has been created and maintained at considerable effort by many contributors that share their knowledge freely and without compensation. Personally, I am very grateful that such a resource exists.</p>
https://dsp.stackexchange.com/questions/94203/rls-adaptive-filter-intuitive-explanation-of-the-so-called-desired-signal
Question: <p>I am working with adaptive filters and similar adaptive models (mainly with gradient adaptation) for a few years. I and my colleagues always struggle to find out the correct size of regression vector.</p> <p>So far, as I find out by the hard way (experience):</p> <ol> <li><p>for filtration mostly works well (low MSE) with something about 10-50 last samples, this number changes according to data and used step-size / algorithm.</p></li> <li><p>for prediction the optimal size also depends on data and learning rate. Longer windows (regression vectors) commonly works well and it can be beneficial to skip samples, example:</p></li> </ol> <p><strong>Example ad 2.</strong></p> <p>For data where is one really dominant frequency (but changing over time) works for me the vector</p> <p>$[u(k), u(k-15), u(k-30), u(k-45), u(k-60)]$ (size of 4 samples)</p> <p>with the same MSE as </p> <p>$[u(k), u(k-1), ..., u(k-60)]$ (size of 60 samples)</p> <p>it seems that only what matters is to cover the size of data about 2 last waves of with the most dominant frequency, no matter how much samples was used.</p> <p><strong>My question</strong></p> <p>What is applicable theory for this problem (at least possibly)? I am pretty sure there must be some data attributes what can tell how big regression vector is important to get the most from the data. But I do not really now what should I study, or how to search for it.</p> <p>Any hint or research direction recomendation is welcome. Thanks in advance.</p> Answer: <p>Suppose that you are adapting <span class="math-container">$w$</span> to minimize <span class="math-container">$\text{E}(y[n]-w[n]*u[n])^2$</span> where <span class="math-container">$$y[n]=h[n]*u[n]+\nu[n]$$</span> <span class="math-container">$y[n]$</span> and <span class="math-container">$u[n]$</span> are known and <span class="math-container">$\nu[n]$</span> is an additive noise component. With a long enough FIR filter you can model any linear system <span class="math-container">$h$</span> with any accuracy. You can opt for a shorter filter length in expense of limited modelling accuracy. A key parameter is the sampling rate of the signals. If the signals are over sampled unnecessarily then the required length for <span class="math-container">$w$</span> increases.</p> <p>Suppose that we settle for a certain modelling accuracy and we want to find <span class="math-container">$w$</span>. If all the samples of <span class="math-container">$u[n]$</span> are available and <span class="math-container">$h$</span> remains constant you can find an estimate of <span class="math-container">$h$</span> namely <span class="math-container">$w$</span> using a least square estimation. This estimation will have a limited accuracy. But it is the best you can do. This error is referred to as the Least square error which here I (a bit wrongly) consider the same as Mean Square Error (MSE error).</p> <p>Since <span class="math-container">$h$</span> may change, we need to continuously estimate <span class="math-container">$h$</span>, and that is why we are using the adaptive filters. Let's say that we use the LMS adaptation to find <span class="math-container">$w$</span>. Now on top of the MSE error we have extra error owing to the way that the LMS adaptation is performed. This error is called misadjustmentis and it is caused by the limited window where <span class="math-container">$u[n]$</span> is used in the adaptation. If the LMS step size <span class="math-container">$\mu$</span> approaches zero we are including all sample of <span class="math-container">$u[n]$</span> in estimation, but then there is no adaptation. It can be proved (Take a look at any adaptive filters book) that misadjustment is proportional to</p> <ol> <li>The filter length</li> <li>The step size</li> </ol> <p>The other issue is the tracking behavior of the filter. Since <span class="math-container">$h$</span> is changing we like to adapt the filter as fast as possible. To increase the adaption speed we can increase <span class="math-container">$\mu$</span>. To keep the filter stable we should have <span class="math-container">$\mu&lt;\frac{1}{\lambda_{\text{max}}}$</span> where <span class="math-container">$\lambda_i$</span> are the eigenvalues of the covariance matrix of <span class="math-container">$u[n]$</span>. The situation is worse if the sample of <span class="math-container">$u[n]$</span> are correlated (apparantly your scenario). In this case the covariance matrix has different eigen values and the adaptive filter converges with different modes where the time constant <span class="math-container">$\tau_i$</span> for each mode will be <span class="math-container">$$\tau_i=\frac{1}{2 \mu \lambda_i}&gt;\frac{\lambda_{\text{max}}}{2 \lambda_i}$$</span> The ratio of largest to smallest eigenvalue <span class="math-container">$\frac{\lambda_{\text{max}}}{\lambda_{\text{min}}}$</span> increases as the samples of <span class="math-container">$u[n]$</span> become more correlated and the LMS filter becomes slower. Unfortunately the speed cannot be increased idefinitely by increasing <span class="math-container">$\mu$</span>. Since <span class="math-container">$\mu$</span> is limited from above by <span class="math-container">$\frac{1}{\lambda_{\text{max}}}$</span>.</p> <p>Back to your case: It seems that your data is highly correlated which is why removing 14/15 of the samples does not change the performance that much. Throwing away samples of <span class="math-container">$u[n]$</span> can help in your case for the following reasons:</p> <ol> <li>You are decreasing the length of the part that you are adapting. This can decrease misadjustment.</li> <li>You are whitening your data by down-sampling it. This decreases the eigenvalue ratio and improves the tracking behavior of the filter.</li> <li>Another issue with highly correlated <span class="math-container">$u[n]$</span> is the potential divergence of filter at frequencies where <span class="math-container">$u[n]$</span> has almost no component. If <span class="math-container">$u(e^{j\omega_i})=0$</span> then <span class="math-container">$h(e^{j\omega_i})$</span> can go to infinity if the filter length is infinite. The shorter the filter the least likely that this occurs. This problem however can be solved by introducing leakage.</li> </ol> <p>The negative impact of throwing away samples of <span class="math-container">$u[n]$</span> is that you are imposing a certain assumption on <span class="math-container">$w$</span>. By using only <span class="math-container">$[u(k), u(k-15), u(k-30), u(k-45), u(k-60)]$</span> you are assuming that <span class="math-container">$w$</span> takes a form like: <span class="math-container">$$w=[w_0~...~0~w_{15}~0~...0~w_{30}~...~w_{60}]$$</span> This limits the ability of <span class="math-container">$w$</span> to model an arbitrary <span class="math-container">$h$</span>.</p>
https://dsp.stackexchange.com/questions/37855/regression-vector-size-for-prediction-reconstruction-and-filtration-with-adapti
Question: <p>I am currently reading a chapter about adaptive filters from the <a href="https://link.springer.com/book/10.1007/978-3-540-49127-9" rel="nofollow noreferrer">Springer Handbook of Speech Processing</a>. </p> <p>In a formulation of the variable stepsize normalized least mean squares (VSS-NLMS)-algorithm, i found an expression that I do not know yet, and searching the internet did so far not yield results i can make sense of.</p> <p>The algorithm is expressed as </p> <p><span class="math-container">$$\mathbf{\hat{h}}(k) = \mathbf{\hat{h}}(k-1) + \mu_\text{NPVSS}(k)\mathbf{s}(k)e(k),$$</span></p> <p>where <span class="math-container">$\mathbf{\hat{h}}(k)$</span> is the current estimate of the desired filter impulse response, <span class="math-container">$\mathbf{s}(k)$</span> the source signal and <span class="math-container">$e(k)=x(k)-\hat{x}(k)$</span> the error difference between filter output and actual output (using the real <span class="math-container">$\mathbf{h}(k)$</span>). The stepsize for this algorithm is defined as <span class="math-container">$$\mu_\text{NPVSS}(k) = \frac{1}{\mathbf{s}^\text{T}(k)\mathbf{s}(k)} \left[ 1-\frac{\sigma_b}{\sigma_e(k)} \right],$$</span></p> <p>with <span class="math-container">$\sigma_b$</span> and <span class="math-container">$\sigma_e$</span> denoting the square root of the variance/power of a noise process <span class="math-container">$b(k)$</span> uncorrelated to the source signal and of the error difference, respectively. </p> <p>For a practical implementation it is suggested to compute the fraction <span class="math-container">$[\mathbf{s}^\text{T}(k)\mathbf{s}(k)]^{-1}$</span> as <span class="math-container">$[\delta + \mathbf{s}^\text{T}(k)\mathbf{s}(k)]^{-1}$</span> instead.</p> <p>In this context, the regularization parameter is defined as <span class="math-container">$$\delta = \text{cst} \cdot \sigma_s^2.$$</span></p> <p>I am not too familiar with the concept of regularization, so I have no clue what the term <span class="math-container">$\text{cst}$</span> means in this algorithmic formulation.</p> <p>What does it mean? Any pointers or literature recommendations would be very much appreciated.</p> Answer: <p>The standard normalized step-size LMS algorithm computes the current step-size according to</p> <p><span class="math-container">$$ \mu = \frac{c}{s_k^T \cdot s_k} $$</span></p> <p>where <span class="math-container">$c$</span> is a suitable scale factor and <span class="math-container">$s_k^T \cdot s_k$</span> is the total energy of the current tap inputs. The algorithm aims to adjust step size according to input signal power; when input has large power then decrease the step-size so that filter coefficient update will not deivate much. But if the signal goes to zero or very small levels (silence durations, or small variance sections), then the division will possibly be very large and algorithm may produce unbounded (very large) outputs or even diverge...</p> <p>To prevent this from happening, a small nonzero factor; the regularisation factor, is added to the denominator </p> <p><span class="math-container">$$ \mu = \frac{c}{s_k^T \cdot s_k + \delta} $$</span></p> <p>to limit the maximum of the fraction to <span class="math-container">$c/\delta$</span> when input power goes to zero.</p>
https://dsp.stackexchange.com/questions/59715/unknown-symbol-expression-in-text-about-adaptive-filters-cst
Question: <p>I need to identify the coefficients of a linear, causal, time-invariant physical system that can be described by a classical state-space formulation.</p> <p>For the sake of the example, suppose that the system has two states, only one of which is observed, and one input. Suppose that this state-space is described by the following matrices:</p> <pre><code> a = x1 x2 x1 -1.25e-05 1.25e-05 x2 1.389e-05 -2.083e-05 b = u1 x1 0 x2 6.944e-06 c = x1 x2 y1 1 0 d = u1 y1 0 </code></pre> <p>The discrete, equivalent, zeroth-order-hold transfer function is given by:</p> <pre><code> 3.481e-05 z + 3.446e-05 ----------------------- z^2 - 1.97 z + 0.9704 </code></pre> <p>In filter terminology, this is clearly an IIR filter because of the higher-order coefficients in the denominator.</p> <p>I'm looking for a suitable adaptive filter algorithm that will:</p> <ul> <li>be numerically stable</li> <li>allow for online updates, i.e. be recursive</li> </ul> <p>From my research so far, I've read that if you treat the recorded signal values as inputs to this filter, then it's possible to treat this filter as a FIR filter. This is called the equation error approach. One can then apply, for example, the QR-RLS adaptive FIR filter to find the coefficients.</p> <p>But in my trials on the real system I often find filter coefficients that are not physically possible, and I just don't know if my hand-crafted adaptive filter is correct or not. I would like to try with an "official" implementation of such an adaptive filter.</p> <p>Therefore, my question is whether there exists (for MATLAB or in C) a freely available implementation of an adaptive IIR filter that has the same advantages of a QR-RLS FIR adaptive filter.</p> Answer: <p>While I may not be the final authority, I have looked into this. In short, no. </p> <p>From my own research, the problem is stability. When the filter is extended to have a wider bandwidth, which of course means that the y[n] values and lags 'move quickly', and then is quenched to a lower bandwidth, where the y[n] values and lags 'move slowly', the y[n] buffer may be loaded with fast oscillated entries that appear as initial conditions to the low bandwidth filter. The filter can easily go unstable. If the bandwidth is altered in an adiabatic manner this instability may be avoided (I'm supposing) but then there's an additional constraint on your adaptivity. </p> <p>Now, you don't have to take my word for it. In "Adaptive Filters: Theory and Applications" (2nd) page 5 (<a href="http://rads.stackoverflow.com/amzn/click/1119979544" rel="nofollow">Amazon</a>), Boroujeny writes, "However, as we shall see in the later chapters, because of the many difficulties involved in adaptation of IIR filters, their application in the area of adaptive filters is rather limited." The author states that the adaptation process can place (digital) poles outside of the unit circle, even if they started within the unit circle. The rest of his book is mostly dedicated to FIR filters.</p> <p>I hope this information helps.</p>
https://dsp.stackexchange.com/questions/19125/is-there-a-widely-available-implementation-of-an-adaptive-recursive-numericall
Question: <p>The context is as follows: I want to measure (as in, digitize) some input signal <span class="math-container">$x$</span> (I have no detailed knowledge about <span class="math-container">$x$</span> or its statistical description).</p> <p>A noise signal <span class="math-container">$x_N$</span> contaminates <span class="math-container">$x$</span> before I digitize it. That is, the signal I read is: <span class="math-container">$x' = x + H_1(x_N)$</span>, where <span class="math-container">$H_1$</span> is some <em>unknown</em> filter (let's assume linear, but possibly time-varying).</p> <p>I have access to <span class="math-container">$x_N$</span> (for example, <span class="math-container">$x_N$</span> could be the "mains" voltage, or the ripple voltage in my power supply). I want to cancel the noise component in <span class="math-container">$x'$</span> to obtain the best estimate of <span class="math-container">$x$</span>. This estimate <span class="math-container">$\hat{x}$</span> is obtained by subtracting a filtered version of the noise: <span class="math-container">$$\hat{x} ~=~ x' - \;H(x_N)$$</span></p> <p>where <span class="math-container">$H$</span> is my adaptive filter. The <em>best</em> estimate is that with minimum power (as a function of the filter coefficients), since the noise and the true signal are uncorrelated.</p> <p>My algorithm aims to minimize <span class="math-container">$\left(\hat{x}\right)^2$</span>. At time step <span class="math-container">$n$</span>, I have: <span class="math-container">$$\left(\hat{x}(n)\right)^2 = {\left( x' - \sum_{k=0}^L h_k \, x_N(n-k) \right)}^2$$</span> To obtain the gradient, I take: <span class="math-container">$$\frac{\partial \left(\hat{x}(n)^2\right)}{\partial h_k} = -2 \, \hat{x}(n)\; x_N(n-k)$$</span> And presumably voilà: each <span class="math-container">$h_k$</span> at step <span class="math-container">$n$</span> is updated by adding <span class="math-container">$\mu$</span> times the above expression to the estimate of <span class="math-container">$h_k$</span> at step <span class="math-container">$n-1$</span>.</p> <p>Question 1: Does the above make sense?</p> <p>Question 2: Rather, a concern when I look at the math above --- intuitively, I expect the gradient's magnitude to approach zero as the system gets close to the solution (the optimal filter), but that doesn't seem the case from the equation above: the gradient is a copy of the last <span class="math-container">$L$</span> samples of <span class="math-container">$x_N$</span> (which in principle has non-zero mean), scaled by the present value of the output (which also, in principle has non-zero mean).</p> <p>Am I doing something wrong?</p> Answer: <p>I'm a little skeptical of your derivation and notation as it abstains from telling whether a Mean-Square or a Least-Squares metric of error is minimized, but rather just works on an instantaneous error at sample <span class="math-container">$n$</span>. But I believe you eventually would devise an LMS or RLS filter, hence either of the two would happen.</p> <p>So, based on your notation the adaptive system error is <span class="math-container">$\hat{x}(n)$</span>, which is an estimate of the true signal <span class="math-container">$x(n)$</span>, and you have two correlated noises <span class="math-container">$x_N$</span> and <span class="math-container">$H(x_N)$</span> which are <strong>uncorrelated</strong> with the true signal. The standard noise cancelling setup.</p> <p>Had you used the steepest descend based quadratic MSE surface minimization procedure, your instantaneous gradient on the error surface would be something like:</p> <p><span class="math-container">$$ \nabla J(w) = - E\{ e(n) \bar{x}[n] \} $$</span></p> <p>where the expectation is due to stochastic MSE framework. In your notation this would become: </p> <p><span class="math-container">$$ \nabla J(w) = - E\{ \hat{x}(n) \bar{x}_N[n] \} $$</span></p> <p>Now, if the optimum condition is reached, then the error is minimized, and we can assume that <span class="math-container">$\hat{x}(n)$</span> <strong>converged</strong> to the true signal <span class="math-container">$x(n)$</span> and you may replace it. Remember this is an approximate conditions actually...</p> <p><span class="math-container">$$ \nabla J(w) = - E\{ x(n) \bar{x}_N[n] \} $$</span></p> <p>and since your noise source is uncrorrelated with the true signal, this expectation is zero, yielding the zero gradient at the minimum point.</p> <p>In your case, you don't specifically use expectations, so might be harder to show why the gradient would go to zero. Furthermore, as always, be aware that gradient would only theoretically go to zero. Any practical implementation will deviate from this depending on how unrealistic your assumptions were.</p>
https://dsp.stackexchange.com/questions/54660/adaptive-filter-for-noise-cancellation-when-measuring-some-input
Question: <p>I have the following diagram for the adaptive seperation of a narrowband and wideband signal using LMS algorithim,</p> <p><a href="https://i.sstatic.net/IZCIN.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/IZCIN.png" alt="enter image description here"></a></p> <p>The way it was explained to us was that "The narrowband signal is correlatied over significant time whereas the broadband signal is not correlated over significant time" and in the delayed line, the ADF can only predict the narrowband.</p> <p>That doesn't make much sense to me. Why is the narrowband correlated over significant time and the broadband isn't and also what's the point of the delay in this?</p> Answer: <p>A narrowband signal seems like (almost) periodic as indicated by</p> <p><span class="math-container">$$ x[n] = m[n] \sin( w_0 n) $$</span> where the message <span class="math-container">$m[n]$</span> has such a low bandwidth that the peak amplitude (the <strong>envelope</strong>) of the carrier sine wave changes very slowly compared to how fast the sine wave oscillates between those +/- envelope limits. This makes its autocorrelation sequence also to be long tailed and almost periodic. And it means that the narrowband signal is highly correlated for long <strong>lags</strong> (long delays).</p> <p>The opposite is true for the wideband signal, its correlation sequence ceases very rapidly even for a small amount of lag.</p> <p>The Wiener filter works by <strong>estimating</strong> the supplied <strong>desired</strong> response signal from its filter input signal, whose success depends on the amount of correlation between the desired signal and the filter input. </p> <p>If there is large correlation between the desired signal and the filter input, then the filter will successfully estimate the desired signal and the error (which is desired signal minus the filter ouyput) signal will be small. On the other hand if there is not enough correlation between the two, then the estimation will be poor.</p> <p>Based on this operational principle of the Wiener filter, and based on the fact that the narowband and the wideband signals have different correlation characteristics, from the given adaptive filter scheme, you can explain its operation as follows.</p> <p>First, you see that the filter input signal and the desired response signals are the same (except the delay) and are a mixture of an auto-correlated narrowband component plus an uncorrelated wideband component. </p> <p>The <strong>delay</strong> is essentially used to <strong>decorrelate</strong> the desired response and the filter input. However, by carefuly chosing the amount of delay (the lag), you can insure that the wideband component is fully decorraleted whilst the narrowband component is still corelated enough. If you chose the delay to too long, both components will lose their cross-correlation to the desired response. If you chose the delay too short, you would not be able to suppress the wideband component enough. Some intermediate delay will be sufficiently decorrelating the wideband component while still maintaining the cross-correlation between the narrowband components at the desired signal and the filter input.</p> <p>When this is the case, the filter will successfully predict the correlated narrowband component in the desired response from the delayed version of it at its input, and it will therefore be subtracted from the supplied desired response signal which yields as the narrowband component as the error signal.</p>
https://dsp.stackexchange.com/questions/54079/seperation-of-wideband-and-narrowband-adaptive-filter
Question: <p>I am writing LMS filter to suppress noise in wav file (I know there are many modules to do this but I need to write LMS manually now as I will translate it into C later).</p> <p>According to this answer[1], the inputs will be the noisy voice and a shifted version of it here is my python code:</p> <pre><code>import numpy as np from scipy.io import wavfile #Reading wav fs, data = wavfile.read('te.wav') #d= vector of first channel samples d = np.transpose(data)[0] print(data.shape) #delay= 2 seconds xd= np.roll(d,2*fs) M=5 L=d.size w=np.zeros(M) y=np.zeros(L-M) e=np.zeros(L-M) meu=0.1 for i in range(0,L-M): xPart=xd[i:i+M] #print(xPart.shape) y[i]=xPart.dot(w) e[i]=d[i]-y[i] w = w+ meu*e[i]*xPart print(w) </code></pre> <p>now, the final value if filter is [nan,nan,...,nan] and a lot of overflows happens.</p> <p>I don't know what is wrong.</p> <ul> <li>is this implementation right?</li> </ul> <p>[1] <a href="https://dsp.stackexchange.com/questions/48681/noise-removal-using-adaptive-noise-cancellation-algorithms-in-real-time-systems">Noise removal using adaptive noise cancellation algorithms in real time systems</a></p> Answer:
https://dsp.stackexchange.com/questions/55723/lms-adaptive-filter-noise-suppression-question-about-my-implementation
Question: <p>Suppose I have a IIR filter represented by <span class="math-container">$$G_0\left(z\right)=\frac{1}{1-0.2z^{-1}-0.1z^{-2}}$$</span></p> <p>I would like to use the LMS algorithm to model an FIR filter <span class="math-container">$G\left(z\right)$</span> of order <span class="math-container">$N = 15$</span> such that it would adaptively reach <span class="math-container">$ G_0\left(z\right)$</span> coefficients values</p> <p>So we know that <span class="math-container">$G_0$</span> can be represented by:</p> <pre><code>num = 1; den = [1; -0.2; -0.1]; </code></pre> <p>my issue is that I don't know how to initiate <span class="math-container">$G(z)$</span> given its order is <span class="math-container">$N=15$</span>.</p> <p>Is it valid to say:</p> <pre><code>G(z) = zeros(N,1)?? </code></pre> <p>because my confusion is that if <span class="math-container">$G_0(z)$</span> has only 3 coefficients, how would <span class="math-container">$G(z)$</span> converge to 3 coefficients given that it is 15 taps long?</p> <p>Please give me some clear insights into this. Thank you in advance.</p> Answer: <p>An adaptive FIR filter is a FIR filter, that uses some kind of an adaptive algorithm to change the filter weights and reach a desired state. In case of using an LMS algorithm the general update equation is the following:</p> <p><span class="math-container">$$ \mathbf{w}(n+1) = \mathbf{w}(n) + \mu\cdot e(n) \cdot \mathbf{x}(n), $$</span></p> <p>where <span class="math-container">$\mathbf{w}(n)$</span>, <span class="math-container">$e(n)$</span> and <span class="math-container">$\mathbf{x}(n)$</span> are respectively filter weights, an error and tap values at <span class="math-container">$n^{th}$</span> sample and <span class="math-container">$\mu$</span> is an adaptation step size.</p> <p>That means, that the result of adaptation of a <span class="math-container">$N$</span>-tap filter will be <span class="math-container">$N$</span> new values of its weights.</p> <p>In your case, you can make a FIR filter <span class="math-container">$G(z)$</span> with <span class="math-container">$N=15$</span> try to adapt, such that its impulse response will be close to the impulse response of the IIR filter <span class="math-container">$G_0(z)$</span>. And it should be able to do so starting from zero weights. However, after the convergence it will certainly still have an error.</p> <p>Useful references on the LMS algorithms are Chapter 9 &quot;Adaptive Filtering&quot; in <em>Statistical Digital Signal Processing and Modeling</em> by M.H. Hayes and a <a href="https://en.wikipedia.org/wiki/Least_mean_squares_filter" rel="nofollow noreferrer">Least_mean_squares_filter</a> entry on Wikipedia.</p>
https://dsp.stackexchange.com/questions/71770/iir-adaptive-filter-in-matlab
Question: <p>I am attempting to make ANC headphones, so far I have constructed the headphones and validated that every component works. I have also constructed an FIR adaptive filter using leaky NLMS for its algorithm. I have validated that this filter works by using the signal from the headphones reference microphone as its input and setting its desired output to a song. I did this by calculating the error signal e(n) to be fed into the LMS algorithm as:</p> <p>e(n) = c(n)-y(n)</p> <p>Where c(n) is the signal of the desired song and y(n) is the output of the filter.</p> <p>This worked well and operated in real time. So then I tried to have it perform noise cancellation. To do this I used the signal directly from the error microphone on the inside of the headphones as the error to be used in the LMS algorithm (e(n)). I thought this is what should be done based on the papers I have read but all that ended up happening was the filter ended up producing the signal from the error microphone itself. I have no idea why this is happening so I would really appreciate if someone could explain to me if I am misunderstanding something.</p> <p>Useful things to note are:</p> <ul> <li>I thought that FXLMS might help so I tried that and the feedback persisted.</li> <li>When creating my ANC system I originally intended to use just LMS but then it turned out that the signal from my reference microphone was so weak that it could not reconstruct the filter output so I had to use NLMS to normalise the signal. I am using the same type of microphone for the error mic so I thought that maybe I need to normalise that too but I'm not sure how to.</li> </ul> <p>I am really lost so any help or suggestions would be greatly appreciated, I hope you ave a good day :).</p> <p>Edit:</p> <p>I was asked to give more details about my hardware and software setup. In terms of hardware I'm using a Teeny 4.1 as the processor, the adafruit mono amplifier, the adafruit i2s mems microphone for all the inputs and a generic 3W 4 Ohm speaker. This is configured as in the pic below:</p> <p><a href="https://i.sstatic.net/WzxJpKwX.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/WzxJpKwX.png" alt="enter image description here" /></a></p> <p>For the actual headphones I am using a pair of ear defenders as the base and the reference microphone is kept on the outside of one ear cup and the error is embedded into the inside of the same ear cup.</p> <p>In terms of software I am using the Arduino IDE with objects from the teensy audio library. My code is as follows:</p> <pre><code>#include &lt;Audio.h&gt; #include &lt;Wire.h&gt; #include &lt;SPI.h&gt; #include &lt;SD.h&gt; #include &lt;SerialFlash.h&gt; // GUItool: begin automatically generated code AudioPlaySdWav playSdWav1; //xy=169,332 AudioInputI2SQuad i2s_quad1; //xy=180,196 AudioAmplifier amp3; //xy=313,329 AudioAmplifier amp1; //xy=345,178 AudioAmplifier amp2; //xy=347,226 AudioRecordQueue queue3; //xy=446,329 AudioRecordQueue queue2; //xy=490,228 AudioRecordQueue queue1; //xy=491,178 AudioPlayQueue queue4; //xy=706,321 AudioPlayQueue queue5; //xy=725,386 AudioAmplifier amp4; //xy=874,238 AudioOutputUSB usb1; //xy=911,367 AudioOutputI2S2 i2s2_1; //xy=1022,241 AudioConnection patchCord1(playSdWav1, 0, amp3, 0); AudioConnection patchCord2(i2s_quad1, 0, amp1, 0); AudioConnection patchCord3(i2s_quad1, 2, amp2, 0); AudioConnection patchCord4(amp3, queue3); AudioConnection patchCord5(amp1, queue1); AudioConnection patchCord6(amp2, queue2); AudioConnection patchCord7(queue4, 0, usb1, 0); AudioConnection patchCord8(queue4, amp4); AudioConnection patchCord9(queue5, 0, usb1, 1); AudioConnection patchCord10(amp4, 0, i2s2_1, 0); AudioConnection patchCord11(amp4, 0, i2s2_1, 1); // GUItool: end automatically generated code #include &lt;iostream&gt; #include &lt;deque&gt; #include &lt;cstdlib&gt; File yFile; const int SDCard = BUILTIN_SDCARD; const float XmicGan = 4.5; const float RmicGan = 4.5; const float songVol = 1.0; const float outVol = 0.02; const int L = 128; const float mu = 0.816; const float eps = 2.2204460492503131E-16; const float LeakFac = 0.079; const int BufLen = 128; //Number of samples in each buffer round std::deque&lt;float&gt; x(L*2, 0); //L*2 bcs read in buffer sizes of L samples so need to go back -L when processing forst sample in buf. int16_t yBuf[BufLen] = {}; float NormYBuf[BufLen] = {}; float NormDBuf[BufLen] = {}; float NormRBuf[BufLen] = {}; float w[L] = {}; //Initalise filter coefficents to be 0 float xPow = 0; float e = 0; void writeFunc(File fileNam, float data){ if(fileNam) { fileNam.println(data, 10); }else { Serial.println(&quot;Error opening write file.&quot;); } } void setup(){ AudioMemory(500); // Open serial communications and wait for port to open: Serial.begin(38400); while (!Serial) { ; // wait for serial port to connect. } Serial.println(&quot;Serial connection established.&quot;); if (CrashReport) { Serial.print(CrashReport); } Serial.print(&quot;Initializing SD card...&quot;); if (!SD.begin(SDCard)) { Serial.println(&quot;initialization failed!&quot;); return; } Serial.println(&quot;initialization done.&quot;); if (SD.exists(&quot;yTest.csv&quot;)) { // The SD library writes new data to the end of the // file, so to start a new recording, the old file // must be deleted before new data is written. SD.remove(&quot;yTest.csv&quot;); } amp1.gain(XmicGan); amp2.gain(RmicGan); amp3.gain(songVol); amp3.gain(outVol); // Play the desired signal (song) WAV file. if (!playSdWav1.play(&quot;SongTest.wav&quot;)) { Serial.println(&quot;Failed to play WAV file!&quot;); return; } Serial.println(&quot;Playing WAV file...&quot;); delay(100); //Delay to stop the next if statemnt from running before playing starts queue1.begin(); queue2.begin(); queue3.begin(); } void loop() { //yFile = SD.open(&quot;yTest.csv&quot;, FILE_WRITE); if (queue1.available() &gt; 0){ int16_t* xBuf = queue1.readBuffer(); int16_t* RBuf = queue2.readBuffer(); int16_t* dBuf = queue3.readBuffer(); memset(NormYBuf, 0, sizeof(NormYBuf)); for(int n=0; n&lt;BufLen; n++){ x.push_back(xBuf[n]/32768.0); //Adding x sample to buf and normalising. xBuf[n]/32768.0 x.pop_front(); //0.6*(rand() % 101)/100.0 NormRBuf[n] = RBuf[n]/32768.0; NormDBuf[n] = dBuf[n]/32768.0; xPow = 0.0; NormYBuf[n] = 0;//Doubley making sure output sample starts at 0. for(int i=0; i&lt;L; i++){ NormYBuf[n] += w[i]*x[L+L-1-i]; // x[n-i]=x[n+x.length()-L-i] xPow += sq(x[L+L-1-i]); } e = NormDBuf[n]-NormRBuf[n]; //NormDBuf[n]-NormRBuf[n]; for(int i=0; i&lt;L; i++){ w[i] = (w[i]*LeakFac)+((mu/(xPow+eps))*e*x[L+L-1-i]); //n = (L+L-1) because n is always the last element in the x deque. } yBuf[n] = NormYBuf[n]*32768; //Convert back into 16 bit. /*Serial.print(x[L+L-1], 10); Serial.print(&quot; &quot;); Serial.print(NormDBuf[n], 10); Serial.print(&quot; &quot;); Serial.print(NormYBuf[n], 10); Serial.print(&quot; &quot;); Serial.println(e, 10);*/ //writeFunc(yFile, NormYBuf[n]); if(NormYBuf[n] != NormYBuf[n]){ //Resetting to initial conditions if output becomes NaN. memset(w, 0, sizeof(w)); e = 0; } } queue4.play(yBuf, BufLen); queue5.play(dBuf, BufLen); queue1.freeBuffer(); queue2.freeBuffer(); queue3.freeBuffer(); } // Check if the file is still playing if (!playSdWav1.isPlaying()) { Serial.println(&quot;All done.&quot;); //yFile.close(); // Play the desired signal (song) WAV file. if (!playSdWav1.play(&quot;SongTest.wav&quot;)) { Serial.println(&quot;Failed to play WAV file!&quot;); return; } Serial.println(&quot;Playing WAV file again...&quot;); delay(100); //Delay to stop the next if statemnt from running before playing starts } } </code></pre> Answer:
https://dsp.stackexchange.com/questions/96618/problem-with-feedback-in-lms-adaptive-filter-for-anc
Question: <p>I will try to explain the issue I am having as clearly as possible without going into my coding or maths. I have my own and a MATLAB Central implementation pf standard LMS in MATLAB. Fixed step size. No normalization or other stuff.</p> <p>I am trying to use it in a system identification setup. I generate a vector of gaussian numbers using "randn" and give the same vector as input and desired response to the LMS filter. Now the estimated weight vector at the end should be a "delta" channel and this is what I get. Then i tried upsampling and interpolating the input vector by an integer number and repeating the same thing. This time around the estimated channel is of the shape of an "Sinc". I gave the interpolated signal as the input and the desired response as before. No changes.</p> <p>Then i also tried low pass filtering the input vector and repeating the same thing. Again a "Sinc". Has anyone observed this before or know something about this? Please point out my mistake. Any suggestions or a discussion is also welcome. </p> Answer: <p>Prior to upsampling, you have a white signal meaning every single frequency in the Nyquist bandwidth from $-\pi$ to $\pi$ is represented. This is a requirement to obtain an impulse (because the Fourier transform of an impulse is a white spectrum). The reason that white signals are often used as inputs for purposes of system identification is that they excite all frequencies of the system. This is important when trying to determine the system's response.</p> <p>After upsampling and interpolating by $N$, you obtain a sequence with a spectrum that is more or less white in the bandwidth from $-\frac{\pi}{2N}$ to $\frac{\pi}{2N}$. The rest of the band (if your interpolation filter is working correctly) will be nearly zero or null. That means that these frequencies are no longer contributing to your coefficient calculation. In turn, this means that you cannot obtain a delta function since it requires every frequency present to be represented properly. The closest approximation to a delta function that you can obtain is a sinc pulse. This is why you are observing this result.</p> <p>Summary: You cannot estimate the response at frequencies that are not contained in your input signal. Your input signal and desired signal are no longer white (because they are bandlimited by the interpolation filter). Therefore, the adaptive filter does not estimate those frequencies. This leads to the sinc response you are observing which is the closest band-limited response to the true system response (a delta function).</p>
https://dsp.stackexchange.com/questions/37074/upsampled-input-to-an-adaptive-filter
Question: <p>My understanding of interpolation specific to resampling applications is limited to the concept of inserting zeros, then designing a filter to minimize distortion in the passband and reject the images the zero-insert creates (to desired performance levels), such as what is depicted in a simple interpolate by 4 zero-insert shown below (showing the resulting spectrum before filtering).</p> <p><a href="https://i.sstatic.net/40Yoo.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/40Yoo.png" alt="enter image description here"></a></p> <p>I am noting that in creating the filter, we are creating the high order polynomial used for interpolating the input samples. I then understand that with a Spline interpolation method (as a user, and perhaps naively as I haven't really dug deeply into the underlying mathematics) we are doing piecewise interpolations using limited polynomials (therefore low order filters) over a smaller span of the sequence, and in many cases due to decreased ripple this will provide better performance.</p> <p>My question then is if such "adaptive" resampling filters have been designed either using Spline approaches directly, or otherwise piecewise similar in process to a spline, but in a fashion that is best suited for high rate FPGA processing with a FIR based interpolation filter (I say that to avoid the response "just do a spline", but perhaps that would actually result in the solution even in an FPGA FIR based interpolator...). Before digging into that further has anyone seen such an approach, is it common, or are there known pitfalls why this would be a BAD idea? Thanks for the thoughts and input!</p> Answer: <p>Look up "Farrow filter". It's essential a set of piecewise polynomial interpolators for the coefficients of an even longer (better) FIR interpolation filter (and without the need for a huge polyphase table). IIRC, it can be implemented in a straightforward arithmetic hardware pipeline (thus is likely quite suitable for an FPGA).</p>
https://dsp.stackexchange.com/questions/38568/spline-based-adaptive-interpolation-filters
Question: <p>General questions:</p> <ul> <li>Is the Kalman filter (they have used Unscented Kalman Filter) adaptive or not? Is the Unscented Kalman Filter used in the paper an adaptive algorithm? </li> <li>Adaptive algorithms such as Constant Modulus and Least Squares are adaptive. Why? What is being adapted ? Based on my understanding, the step size is adapted and the weights as well. But I am not sure for the case of Kalman filters -- is the Kalman Gain getting adapted? Adapted to what?</li> </ul> Answer: <p>Adaptive Filters are called "Adaptive" when they can adapt to changes in data.<br> In the filters you mentioned above, which are part of the Linear Filters family the property means their coefficients are changing over time.</p> <p>Linear Filters are basically weighing and summing the data.<br> For instance, given no prior information on data you may want to have exact weight for any data given. </p> <p>Yet in most Signal Processing use cases we'd like to (Or might want to) give higher weight for each data sample according to its properties such as SNR, How good it fit the model, etc...</p> <p>In the classic Kalman Filter the coefficients are set according to a model matrix - $ P $.<br> For Kalman filter this matrix stands for the Covariance of the estimation.<br> It changes according to 2 other matrices which are properties of our model and data - $ Q $ - The model confidence level matrix, $ R $ the data confidence model (For Gaussian data it is basically the SNR). </p> <p>Since the algorithm support the cases those are changing over time it is called adaptive. </p> <p>For instance, in the case of tracking a target using RADAR the algorithm can change the matrix $ R $ according to the SNR of the measurement.</p> <p>The Recursive Least Squares have similar properties (Though it depends only on one factor, something similar to the matrix $ R $ of the Kalman Filter).<br> One could even see the RLS as a private case of the Kalman Filter (Or the Kalman Filter as a generalization).</p> <p>There are many extension for the Kalman Filter for many cases.<br> The UKF (Unscented Kalman Filter) you mentioned is built to handle Non Linear cases of the Model.<br> But adaptive concept stays the same, the weights are changing according to properties of the Data and the Model.</p>
https://dsp.stackexchange.com/questions/42710/explain-the-adaptive-part-of-adaptive-algorithms-kalman-filter-and-least-mean
Question: <p>I want to find the resonant frequency of specific <a href="https://en.wikipedia.org/wiki/End-blown_flute" rel="nofollow noreferrer">end-blown flute</a> called <a href="http://persianney.com/technique.html" rel="nofollow noreferrer">Persian ney</a>, Using LMS in arrangement of system identification. Two signal is needed for algorithm:</p> <ol> <li>system excitation (<code>x</code>)</li> <li>desired signal (<code>d</code>).</li> </ol> <p><a href="https://i.sstatic.net/JJ2ee.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/JJ2ee.png" alt="General adaptive system identifier" /></a></p> <p>The plant here is flute. The adaptive is coefficients describing flute behavior in time and frequency. Almost mostly <code>x</code> is white noise. The microphone outside the flute will capture the sound as <code>d</code>. All done. But mechanical-acoustic arrangement is like:</p> <pre><code> ----------- Tubes, conducting acoustic: | | Including big tube, tube reducer and small tube (flute size) |Noise(x) / --------------\ |generator| | -----*-------------- - - ----- --- --- |speaker | | -----*------ ------------------------- |box \ --------------/ Flute entrance | | O ----------- | Microphone(d) * Marks flute entrance </code></pre> <p>Exciting approach seems to be wrong since to make flute work in playing time, we enclose all over flute entrance with lips, only small piece of it's circle remains open to let air move out and make friction with flute edge. If do not enclose, the instrument will not sound!</p> <p>Small area marked with red is an open area(between teeth and tongue): <a href="https://i.sstatic.net/XExJl.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/XExJl.png" alt="Flute excitation small exhaust gap" /></a></p> <p>The question is how to model this type of flute excitation correctly? Since the white noise must enter the flute, but also it's entrance must be closed.</p> <p>I'm not sure if maybe human lung also contribute to it's resonance.</p> Answer: <p>I'm partially going on my own knowledge of electronic circuits, my own experience singing and playing (and playing with) wind instruments, and <a href="https://newt.phys.unsw.edu.au/jw/fluteacoustics.html" rel="nofollow noreferrer">this page</a>.</p> <p>Your model is wrong (sorry).</p> <p>A better model for a flute is a resonator (mouth, throat, lungs, etc.), a negative acoustic impedance (the working edge, and the jet of air being blown against it), and then another resonator.</p> <p>The magic (as with any wind instrument) happens at that &quot;negative acoustic impedance&quot;. A <em>positive</em> acoustic impedance is any element that tends to make vibrations in the air turn into heat and dissipate away. A <em>negative</em> acoustic impedance is an element that tends to make vibrations in the air <strong>get stronger</strong>.</p> <p>When you have a bunch of resonators (or just one, really) working against a negative acoustic impedance, then if all the elements work together correctly, you get an oscillation. This oscillation is what causes a wind instrument to make a steady tone.</p> <p>So -- the random noise generator needs to come <strong>out</strong>, and you need to insert a negative acoustic impedance. To model this accurately you're going to have to learn a lot about acoustics -- but it'll be good for you.</p> <p>What you should end up with is a model that generates a sine wave or nearly so, and that sounds like a flute when you generate a sound file and play it.</p>
https://dsp.stackexchange.com/questions/88123/modeling-end-blown-flute-instrument-using-adaptive-filter
Question: <p>i am currently attempting system identification using the LMS algorithm. The input and the output data are available and are very noisy and consists of multiple frequencies. The input and the output data are shown below. <a href="https://i.sstatic.net/rNeKT.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/rNeKT.png" alt="input and output signals" /></a></p> <p>The LMS algorithm fails to converge, i.e., adapt to the desired output signal. See images below. <a href="https://i.sstatic.net/PX0M5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/PX0M5.png" alt="enter image description here" /></a></p> <p>However, passing the signals through a low-pass filter first and then implementing the LMS for low frequency converges the filter output to the reference and minimizes the filter error. See image below. <a href="https://i.sstatic.net/KJGF4.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/KJGF4.png" alt="enter image description here" /></a></p> <p>Could anyone explain me how and why LMS performs better for low frequecy data. Also, how should I move forward? Is it ok to pass the data through LPF first and apply the LMS filter. Would it cause loss of information and produce wrong system identification? How can I implement LMS algorithm for high frequency signal.</p> <p>I thank all the experts on any assistance on this.</p> <p>Best regards,</p> Answer: <p>In general for a standard LMS you can only ensure convergence if the stepsize <span class="math-container">$µ &lt; 1 / (2p\sigma^2)$</span> . With p being the filter order and <span class="math-container">$\sigma^2$</span> the variance of the input signal x. Therefore if you first low-pass filter your signal, the variance is reduced and the possible save range for µ increases.</p> <p>One option would be to reduce the stepsize or use the normalized LMS where the stepsize is timevaring to ensure convergence.</p>
https://dsp.stackexchange.com/questions/85113/lms-adaptive-filter-for-system-identification
Question: <p>For the adaptive filter to work properly, a desired signal d(n) needs to be provided. The output from the equalizer y(n) is subtracted from d(n) to produce an error signal, which is used to adjust the filter weights.</p> <ol> <li><p>The adaptive filter is located on the receiver side, so how to obtain the desired signal, and use it at the receiver? When using a training sequence, the desired sequence can easily be located at the receiver. What will be the situation with other unknown sequences?</p></li> <li><p>What is the difference between least mean square and recursive least squares adaptive linear filters?</p></li> </ol> Answer: <p>To answer (1) the adaptive equalizer without a training sequence (blind equalization) can be used based on the decisions of the received sequence. This specifically is called a "decision directed equalizer". Of course it can not work in very low SNR conditions, where a training sequence would be required. A typical approach is to have the training sequence first to remove channel ISI and establish a higher SNR signal. From this point a decision directed approach can continue to track and maintain the equalized signal as the channel varies with time. (If I recall correctly, a decision directed approach can typically converge if the bit error rate is better than 1E-3 -- but this exact figure I am not confident in). </p> <p>I have heard (but have no experience with) that the most commonly used adaptive algorithm for blind channel equalization is the Constant Modulus Algorithm. Perhaps someone more knowledgeable about this approach can add an additional response with more comments and details about CMA (or better if I cannot Google a satisfactory explanation I can post it as a question myself).</p> <p>To answer (2), the LMS (Least Mean Square, also referred to as the Gradient Algorithm) and the RLS (Recursive Least Squares algorithm) are the two most common algorithms for recursively minimizing mean square error in adaptive linear equalizers (in contrast to non-linear Decision Feedback Equalizers, which are not to be confused with "Decision-Directed" mentioned above, would be preferred in the case of frequency selective fading). </p> <p>The LMS algorithm is well known, easy to implement and computationally cheap (requires $2M+1$ multiply operations, where M is the number of equalizer coefficients). It uses a Stochastic Gradient Descent Rule, so may converge slowly.</p> <p>The RLS algorithm in comparison is computationally more expensive (requires $2.5M^2+4.5M$ multiply operations), but has faster convergence and good tracking. </p> <p>For details on the LMS and RLS algorithms (and likely where I got the metrics quoted above), see Wireless Communications by Rappaport which I have notated in the plots below. Notice the computational difference between the two algorithms:</p> <p><a href="https://i.sstatic.net/utCiJ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/utCiJ.png" alt="LMS equalizer"></a></p> <p><a href="https://i.sstatic.net/CpQru.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CpQru.png" alt="RLS equalizer"></a></p> <p>Also see this post here where I give the code and detailed intuitive explanation for the determination of the LMS equalizer coefficients using the Wiener-Hopf equation: <a href="https://dsp.stackexchange.com/questions/31318/compensating-loudspeaker-frequency-response-in-an-audio-signal/31326#31326">Compensating Loudspeaker frequency response in an audio signal</a>. In this post I used a known copy of the signal to determine the channel impulse response in the static case (not a recursive solution). However as noted above this could also be done blind with the decisions of what we think was transmitted if the SNR was high enough to make a sufficient number of correct decisions. </p> <p>you can find additional detailed explanations on Wikipedia: <a href="https://en.wikipedia.org/wiki/Recursive_least_squares_filter" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Recursive_least_squares_filter</a></p>
https://dsp.stackexchange.com/questions/51200/recursive-least-square-adaptive-linear-equalizer
Question: <p>I'm trying to filter out line noise(60Hz and 120Hz) from a EEG signals received over a bluetooth link. I'm proposing to use a IIR notch filter to filter out the line-noise which varies w.r.t to distance between the bluetooth transmitter and receiver. I'm not able to establish a clear relationship between the Notch filter parameters and the magnitude of line noise so as to avoid over-attenuation or under-attenuation to avoid dips and peaks at these frequencies in the spectrum. The problem is Q-factor and stop-band Bandwidth which define the notch filter don't directly relate to the stop band attenuation. If this is not possible is there any other equally efficient adaptive stop-band filtering method to achieve the same ? How can this be implemented w.r.t line noise measurement and corresponding filter parameter adjustments ? </p> Answer:
https://dsp.stackexchange.com/questions/19612/adaptive-line-noise-removal-using-iir-notch-filters
Question: <p>I am trying to understand the entire signal chain and all the algorithms associated with adaptive filtering as mentioned in the case above. From my understanding:</p> <ul> <li><p><strong>Adaptive noise filtering (ANF)</strong>- can be performed with the help of Weiner filters, wavelet packet based auditory masking or subspace projections -- all these help in removing correlated noise. For uncorrelated noise, we can use a low pass filer? Gaussian filter bank in some way (need some guidance on this)?</p></li> <li><p><strong>Adaptive Echo cancellation (AEC)</strong> - draws some speech from the far end speaker and modulates it so it sounds like the "feedback" from the near user so it can be successfully cancelled out from the near-end input (uses NLMS and RMS)?</p></li> <li><p><strong>Automatic Gain control (AGC)</strong>- Look-ahead limiter?</p></li> </ul> <p>From my understanding, the chain goes as follows:</p> <p>Near end $\rightarrow$ Uncorrelated noise removal $\rightarrow$ Correlated noise removal + AEC $\rightarrow$ AGC.</p> <p>Also how do Voice Activity Detection (VAD) and Discountinuous Transmission (DTX) work in this chain?</p> <p>Is this correct? Can someone explain in detail about this?</p> Answer:
https://dsp.stackexchange.com/questions/43222/signal-chain-for-voice-calls-including-adaptive-noise-cancellation-adaptive-ech
Question: <ol> <li><p>Considering non-linear filtering technique like Extended Kalman filtering with Expectation Maximization (EM). EM is an iterative technique but what is Kalman filtering? Is Kalman Filtering called iterative approach? </p></li> <li><p>Adaptive signal processing algorithms like Least Mean Square and Recursive Least square (RLS) estimate weights at each time instant and then update them. Since, RLS has a recursive nature and it falls under adaptive technique, then does this mean that adaptive is another name for recursive? </p></li> <li><p>What is the difference between adaptive and iterative terminologies? Are Kalman filtering and its nonlinear versions adaptive?</p></li> </ol> <p>Q1: In short, is adaptive=recursive=iterative? </p> <p>Q2: Where is EM and Kalman Filtering approaches categorized under and why?</p> Answer: <blockquote> <p>Q1: In short, is adaptive=recursive=iterative?</p> </blockquote> <p>Filtering is applying a filter $f$ to an input signal $x$ to get an output signal $y$:</p> <p>$$ y(t) = f(x(t), t) $$</p> <p>The filter $f$ is called <a href="https://en.wikipedia.org/wiki/Iteration" rel="nofollow"><strong><em>iterative</em></strong></a> if its next value can be calculated from other time-dependent values of either $x$ or $y$ or both.</p> <p>The filter $f$ is called <a href="https://en.wikipedia.org/wiki/Recursion" rel="nofollow"><strong><em>recursive</em></strong></a> if it depends on $y$ for some time $s \le t$ (where $t$ is the current time). </p> <p>If the way $f$ uses past values of $y$ to filter $x$ changes, then the filter $f$ is also <a href="https://en.wikipedia.org/wiki/Adaptive_filter" rel="nofollow"><strong><em>adaptive</em></strong></a>.</p> <p>For example, the filter: $$ y(t) = x(t) $$ is iterative, but <strong>not</strong> recursive <strong>nor</strong> adaptive.</p> <p>For example, the filter: $$ y(t) = x(t) + \alpha y(t-1) $$ is both iterative and recursive, but <strong>not</strong> adaptive.</p> <p>For example, the filter: $$ y(t) = x(t) + \alpha(y,x) y(t-1) $$ is <strong>both</strong> recursive and adaptive (the filter coefficient $\alpha$ depends on some function of past inputs $x$ and past outputs $y$).</p> <blockquote> <p>Q2: Where is EM and Kalman Filtering approaches categorized under and why?</p> </blockquote> <p>Kalman filtering is definitely <strong>iterative</strong> and <strong>recursive</strong> as the new updates will depend on past values of the input and output (well state estimates).</p> <p>The standard implementation of the Kalman filter is <strong>not adaptive</strong>. However, there are simple extensions that make it adaptive.</p>
https://dsp.stackexchange.com/questions/26860/terminologies-adaptive-recursive-and-iterative
Question: <p>I am looking for methods to enhance noisy images, where:</p> <ul> <li>some pixels in the image are very noise,</li> <li>some other pixels do not contain so much noise. </li> </ul> <p>My first thought is to build an adaptive Gaussian filter. This means that the Gaussian kernel will depend on the (estimated) noise status of the current pixel (large radius of the Gaussian kernel for noisy pixels and a smaller in the converse case).</p> <p>Could you help me in calculating the kernel values?</p> Answer: <p>So if I understand your description correctly your data looks something like this:</p> <p><img src="https://i.sstatic.net/JMStt.png" alt="enter image description here"></p> <p>In this case you could try using a robust Gaussian smoothing. This involves an extra weight term to discard 'outliers'. There are many possible ways to define the outliers using deviation from the local mean (over the kernel) greater than $\pm 3 \sigma$ is a common way. Unfortunately I can't seem to find any decent papers or articles describing the method in more detail.</p>
https://dsp.stackexchange.com/questions/16326/adaptive-gaussian-filter-for-image-denoising
Question: <p>Adaptive IIR filters is not straightforward, and may be unstable. Many people say that adaptive IIR filters <em>use less coefficients</em> than FIR filters. What I'm curious about is how many coefficients can IIR save?</p> <p>I tried to use adaptive IIR filters to estimate transfer function of a 32-order FIR filter. Assume the IIR filter has $M+N+1$ coefficients: $a_1, a_2, ..., a_M, b_0, b_1, ...b_N$. I found the estimation result is acceptable only when $M+N+1 \ge 30$, i.e. only 2 coefficients can be saved.</p> <p>In actual projects, for example, a 50 MHz FPGA, a 32-order FIR will produce about $(32 / 50 ~{M}) / 2 = 0.32 ~{\mu s}$ delay, so </p> <ul> <li>What will happen for IIR? </li> <li>Can adaptive IIR filters really reduce number of coefficients and reduce signal processing time delay?</li> </ul> Answer: <p>These are the key differences between FIR and IIR filters, regarding the feature you wish to control are the following:</p> <p>$$ \begin{array}{c|lcr} \text{Feature} &amp; \text{IIR} &amp; \text{FIR} \\ \hline \text{Implementation} &amp; \text{Poles &amp; Zeros} &amp; \text{Zeros Only} \\ \text{States} &amp; \text{Yes} &amp; \text{No} \\ \text{Phase Delay} &amp; \text{*} &amp; \text{Half Integer} \\ \text{Stability} &amp; \text{*} &amp; \text{Always} \\ \text{Ripple} &amp; \text{Yes} &amp; \text{*} \\ \text{Cut-Off} &amp; \text{Yes} &amp; \text{*} \\ \end{array} $$</p> <p>The * indicates the feature can be controlled, by adding orders in most cases.</p> <p>The standard definitions of FIR and IIR filters are:</p> <p>FIR:</p> <p>$$H(z)=b_0z^0+...+b_nz^n$$ $$y(t)=b_0u(t)+...+b_nu(t-n)$$</p> <p>IIR: </p> <p>$$H(z)=\frac{b_0+b_1z^1+...+b_nz^n}{1+a_1z^1+...+a_nz^n}$$ $$y(t)=b_0u(t)+...+b_nu(t-n)-a_1y(t-1)-...-a_ny(t-n)$$</p> <p>$u$ is the input, $y$ is the output, $x$ is the states (below), $t$ is the time, scaled by a sampling time $dt$, $n$ is the number of orders of the filter. Each filter has $n$ size coefficient vectors, plus constant direct-output term $b_0$ (optional), and $a_0$=1. For simplicity assume $\sum{b_i}=1$ and $\sum{a_i}=1$, though this is not required anywhere.</p> <p><strong>Implementation</strong>. By definition, FIR include zeros only, leading to a <a href="https://en.wikipedia.org/wiki/Linear_filter" rel="noreferrer">linear system</a> in the history vector for $u$: $[u(t-1)...u(t-n)]$.</p> <p>IIR include both poles and zeros, also leading to a <em>linear system</em> in the history vector not only for $u$, but for $y$ too. Because of this, by one side IIR can be unstable; but by other side, they can be designed to have smooth ripple and sharp cutoffs with a minor number of orders.</p> <p><strong>States</strong>. FIR are <em>static systems</em> in the history vectors, meaning the filter is not dynamical, do not have states, is not recursive, no feedback. IIR are <em>dynamical systems</em> in the history vectors, meaning the filters have states, is recursive, has feedback, hence have "memory" from past inputs &amp; outputs.</p> <p><strong>Phase Delay</strong>. The <a href="https://en.wikipedia.org/wiki/Group_delay_and_phase_delay" rel="noreferrer">Phase Delay</a> $\tau_\phi$</p> <p>$$y(t)=y_0(t-\tau_t) sin(\omega(t-\tau_\phi)+\theta)$$</p> <p>can be easily controlled in FIR implementations. If $b_k=b_{n-k}$,$k=0...n$, the phase delay is constant, equal to $n/2$ (the center of the FIR coefficients shape, its impulse response), equal to the group delay, and thus the filter become <a href="https://en.wikipedia.org/wiki/Linear_phase" rel="noreferrer">linear phase</a>, with phase equal to $\omega\tau_phi$. </p> <p>Because IIR have infinite impulse response, they can be <a href="https://en.wikipedia.org/wiki/Minimum_phase" rel="noreferrer">minimum phase</a> instead of linear phase, though the phase achieved can be much less than the phase of a FIR for the same number of orders.</p> <p><strong>Stability</strong>. FIR are always stable, IIR can be designed to be stable, if stability is required.</p> <p><strong>Ripple</strong>. IIR can be designed to be flat-ripple both in pass-band|stop-band|both (butterworth|chebyshev|elliptic), FIR requires a major (tending to "infinite") number of orders for equate this property. </p> <p><strong>Cut-Off</strong>. IIR can be designed to have a sharp cut-off or narrow transition bands, FIR requires a major (tending to "infinite") number of orders for equate this property. </p> <p>Related Articles: </p> <p><a href="https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-341-discrete-time-signal-processing-fall-2005/lecture-notes/lec08.pdf" rel="noreferrer">https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-341-discrete-time-signal-processing-fall-2005/lecture-notes/lec08.pdf</a> <a href="https://www.quora.com/Why-are-FIR-filters-preferred-over-IIR-filters" rel="noreferrer">https://www.quora.com/Why-are-FIR-filters-preferred-over-IIR-filters</a> <a href="http://iowahills.com/A8FirIirDifferences.html" rel="noreferrer">http://iowahills.com/A8FirIirDifferences.html</a> <a href="http://forums.prosoundweb.com/index.php?topic=2045.0" rel="noreferrer">http://forums.prosoundweb.com/index.php?topic=2045.0</a> <a href="http://www.vyssotski.ch/BasicsOfInstrumentation/SpikeSorting/Design_of_FIR_Filters.pdf" rel="noreferrer">http://www.vyssotski.ch/BasicsOfInstrumentation/SpikeSorting/Design_of_FIR_Filters.pdf</a></p>
https://dsp.stackexchange.com/questions/32129/whats-the-advantage-of-adaptive-iir-filter-against-fir
Question: <p>I am currently working on a project where i am to estimate a signal x_T using x_1 and x_2 with an RLS filter.</p> <p>I have a problem where i don't quite get the results i am looking for. I think there is a problem with the filter coefficients. I don't know which ones i am to use.</p> <p>This is what i have come up with that i need to do:</p> <p>Using the first 9:5 minutes of xT [n], x1[n], x2[n], train the RLS filter and estimate the coefficients ai and bi.</p> <p>xT [n] = Σ(i=0 to N) ai * x1[n - i] + Σ(i=0 to M) bi* x2[n - i]</p> <p>Freeze the estimates ^ai and ^bi at the end of 9:5 minutes.</p> <p>Using the last 30 seconds of x1[n] and x2[n], form an estimate of xT [n] for the last 30 seconds.</p> <p>In my code i have the following RLS algorithm:</p> <pre><code>% Parameters data_length = length(x_T); dim = 2; lambda = 0.9; % 0 &lt; lambda &lt; 1 alpha = 100; N = 100; M = 100; % Initialization theta = zeros(dim, 1); P = alpha * eye(dim); % RLS algorithm for n = 1:data_length % Form input vector h = [x_1(n); x_2(n)]; % Compute a priori error error = x_T(n) - h' * theta; % Compute Kalman gain vector K = P * h / (lambda^n + h' * P * h); % Update estimate theta = theta + K * error; % Uppdatera P[n] P = (eye(dim) - K * h') * P; % Store theta values at each iteration a_koeff(n) = theta(1); b_koeff(n) = theta(2); end </code></pre> <p>This means that i will have length(x_T) number of filter coefficients. First of all i am wondering if this is correct and second of all if it is correct, which ones am i supposed to use for reconstructing the missing part? I think i probably shouldn't have this many filter coefficients but only &quot;filter_length&quot; number of coefficients... I just cant think of a way to implement this.</p> <p>Also for the reconstruction part, the problem here is i don't know which filter coefficients to use. If i like i do now have length(x_T) filter coefficients which is 71250, am i to use the first 3750 coefficients or the last?</p> <p>Right now i am using the N first for ai and M first for bi as following:</p> <pre><code>% Reconstruction x_reconstructed = zeros(size(x_missing)); for n = length(x_T):length(x_1) a = 0; b = 0; for i = 1:N a = a + a_koeff(i) * x_1(n-i); end for j = 1:M b = b + b_koeff(j) * x_2(n-j); end x_reconstructed(n-length(x_T)+1) = a + b; end </code></pre> <p>This seems wrong as the coefficients should get better the more we have iterated. I tried with using the last but then the results are even stranger. I will attach an image of the plots where i have the reconstructed signal and the missing signal.</p> <p>Thank you!!</p> <p>Full code:</p> <pre><code>% This file provides code for loading data for one patient % The file assumes the DATASET folder is in the same folder with this m-file clear all close all clc patient_no = 2; s=string(patient_no); x_1= importdata('DATASET/ECG_'+s+'/ECG_'+ s +'_V.mat'); x_2= importdata('DATASET/ECG_'+s+'/ECG_'+ s +'_AVR.mat'); x_T = importdata('DATASET/ECG_'+s+'/ECG_'+ s +'_II.mat'); x_missing= importdata('DATASET/ECG_'+s+'/ECG_'+ s +'_II_missing.mat'); % Parameters data_length = length(x_T); dim = 2; lambda = 0.9; % 0 &lt; lambda &lt; 1 alpha = 100; N = 100; M = 100; % Initialization theta = zeros(dim, 1); P = alpha * eye(dim); % RLS algorithm for n = 1:data_length % Form input vector h = [x_1(n); x_2(n)]; % Compute a priori error error = x_T(n) - h' * theta; % Compute Kalman gain vector K = P * h / (lambda^n + h' * P * h); % Update estimate theta = theta + K * error; % Uppdatera P[n] P = (eye(dim) - K * h') * P; % Store theta values at each iteration a_koeff(n) = theta(1); b_koeff(n) = theta(2); end % Reconstruction x_reconstructed = zeros(size(x_missing)); for n = length(x_T):length(x_1) a = 0; b = 0; for i = 1:N a = a + a_koeff(i) * x_1(n-i); end for j = 1:M b = b + b_koeff(j) * x_2(n-j); end x_reconstructed(n-length(x_T)+1) = a + b; end % Plotting the reconstructed data subplot(2,1,1) plot(x_reconstructed) title('Reconstructed Data') xlabel('Sample Index') ylabel('Amplitude') legend('Reconstructed Signal') % Plotting the missing data subplot(2,1,2) plot(x_missing) title('Missing Data') xlabel('Sample Index') ylabel('Amplitude') legend('Missing Signal') <span class="math-container">```</span> </code></pre> Answer:
https://dsp.stackexchange.com/questions/90089/rls-adaptive-filter-for-estimating-signal
Question: <p><strong>Problem:</strong> I am looking at an adaptive filtering application where the eigenvaluespread of the autocorrelation matrix <span class="math-container">$R$</span> is important for the convergence of the algorithm. For a <strong>single</strong> channel system the autocorrelation matrix <span class="math-container">$R$</span> for iterationstep <span class="math-container">$n$</span> can be calculated by <span class="math-container">$R=E\{ x(n) x^H(n)\}$</span> where <span class="math-container">$x(n)$</span> is the input signal of the adaptive filter at iterationstep <span class="math-container">$n$</span> consisting of a number of samples <span class="math-container">$N$</span> recorded over a timespan. The calculation of the eigenvalues is straight forward.</p> <p><strong>Question:</strong> What is the &quot;multichannel equivalent&quot; for <span class="math-container">$R$</span> in the case of e.g. an adaptive filtering <strong>multichannel</strong> application? Do I need to calculate some sort of autocorrelation tensor?</p> Answer: <p>You apply the same formula, but instead of using a scalar <span class="math-container">$x(n)$</span>, you will have <span class="math-container">$x(n) \in \mathbb{C}^{M \times 1}$</span>, where <span class="math-container">$M$</span> is the number of channels, and <span class="math-container">$x^{H}(n)$</span> is the <span class="math-container">$1 \times M$</span> matrix whose entries are the complex conjugate of the entries in <span class="math-container">$x(n)$</span>. As a result <span class="math-container">$R \in \mathbb{C}^{M \times M}$</span> is an <a href="https://en.wikipedia.org/wiki/Hermitian_matrix" rel="nofollow noreferrer">Hermitian matrix</a>, and its eigenvalues are all real.</p>
https://dsp.stackexchange.com/questions/73686/autocorrelation-of-multiple-signals
Question: <p>In my design and implementation of a SIR particle Filter, I don't have the state process equation of the actual system, which would have given a very good estimation of the real signal. I was wondering, if there are any mathematical methods out there to extrapolate the next state (i.e construction of process equation) based on the given previous estimates and measurements. I would also add that I am using this filter for a real-time application, which is subject to continous random change. That makes the filter an adaptive particle filter according to my understanding of the terms.</p> <p>I have tried to extrapolate using a set of previous measurements, but the estimate was just as the meausrements, namely noisy, amplified and shifted by an offset. It does not make any sense obviously, since the filter is intended to correct the measurements uncertainties.</p> <p>Any promising suggestions would help!</p> Answer:
https://dsp.stackexchange.com/questions/81914/adaptive-particle-filter-unknown-process-equation
Question: <p>I am using gradient descent on an adaptive IIR filter for the below system <a href="https://i.sstatic.net/Q6D6S.png" rel="nofollow noreferrer">1</a>. At the moment I am just assuming the known system is not there and it works fine. However, occasionally when the known system has slower dynamics it does not perform very well. Are there any papers or methods for adapting a filter in this kind of scenario? Thank you in advance for your help.</p> <p><a href="https://i.sstatic.net/Kt2lX.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Kt2lX.png" alt="Layout" /></a>The known system is not necessarily invertible, but is always stable.</p> Answer: <p>The problem with your diagram is that the calculation of the error isn't done on the output of the adaptive filter.<br /> The adaptive filter minimizes the error based on the idea the error is a function only of the weights of the filter and the input. In your cases it is also a function of the weights of the unknown system.</p> <p>If you have the ability to change to locations of the blocks it would make sense to do as following (By <a href="https://asciiflow.com/" rel="noreferrer">ASCII Flow</a> at <a href="https://asciiflow.com/#/share/eJyrVspLzE1VssorzcnRUcpJrEwtUrJSqo5RqohRsrI0NtaJUaoEsowsDIGsktSKEiAnRkkBCTyasodsFBOTh2aUAgaAKCPSQKB677z88jyF4MriktRcCp1HtqdQPYLLW5iCeHxPpRAn105yAa3NokZYUMkMkuOdCHlSUn5oXjZK0ieg3jElsaAksyxVwS0zpyS1iJB6IrMqIXlMYwY0%2BmKUapVqAS5GXV8%3D" rel="noreferrer">Adaptive Filter</a>):</p> <pre><code> ┌──────────────────┐ │ │ ┌───────────┤ Known System ├────────────────────────────────────┐ │ │ │ │ │ └──────────────────┘ │ │ │ │ │ │ ┌──────────────────┐ ┌──────────────────┐ │ │ │ │ │ │ │ └───────────┤ Unknown System ├────────┤ Adaptive Filter ├────────┘ │ │ │ │ └──────────────────┘ └──────────────────┘ </code></pre> <p>Then what the adaptive filter will try to do is to imitate the system which is inverse of the unknown system and equivalent to the known system.</p> <p>The performance of the convergence, as always with adaptive filters, depends on the properties of the eigen values of the systems.</p>
https://dsp.stackexchange.com/questions/84700/approximate-a-known-system-with-adaptive-filter-and-an-unknown-system-in-a-serie
Question: <p>Here you can see building blocks of DFE from <strong>&quot;Adaptive Filters: Theory and Applications”</strong> a book by Behrouz Farhang-Boroujeny in chapter 17.</p> <p>Figure 17.9 shows the overall building blocks of DFE which in the input we have noisy signal x that passed through channel and feeds to equalizer to have an estimated version of transmitted symbols at the output.</p> <p>Figure 17.22 illustrates the more detailed version of the previous one.</p> <p>Figure 17.9 demonstrates how theory of multirate signal processing can be used to replace the cascade of <span class="math-container">$P_{R}(z)$</span> and the twofold decimator by the corresponding polyphase structure.</p> <p>I put the Matlab code from book which compares Symbol-Spaced, Fractionally spaced and DF equalizers.</p> <p>Now my questions are:</p> <p>In figure 17.22</p> <p>1- Why a two fold decimator have been used?</p> <p>2-Why a delayed version of <span class="math-container">$s(n)$</span> has been subtracted before <span class="math-container">$W_{FB}(z)$</span>.</p> <p>3- In the code: optimum wights had been calculated for every L sample of channel which made me confused how to calculate the overall tap wights of FF and FB. Meaning, what should I do in order to pass noisy symbols from channel and DF equalizer while optimum tap wights calculated for every L sample of channel?</p> <p>unfortunately, the code lacks a test demo to show how all these thing works. <a href="https://github.com/YangangCao/AdaptiveFilter/blob/master/AdaptiveFilters/equalizer_eval.m" rel="nofollow noreferrer">https://github.com/YangangCao/AdaptiveFilter/blob/master/AdaptiveFilters/equalizer_eval.m</a></p> <p><a href="https://i.sstatic.net/QJpro.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QJpro.jpg" alt="enter image description here" /></a></p> <p><a href="https://i.sstatic.net/HAJyT.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/HAJyT.jpg" alt="enter image description here" /></a></p> <p><a href="https://i.sstatic.net/8wTZd.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/8wTZd.jpg" alt="enter image description here" /></a></p> Answer:
https://dsp.stackexchange.com/questions/91920/decision-feedback-equalizer-building-blocks-from-adaptive-filters-theory-and-a
Question: <p><a href="https://i.sstatic.net/bZHOLDIU.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bZHOLDIU.jpg" alt="LMS algorithm" /></a></p> <p>When applying an algorithm like LMS, for example, in order to updates the weight coefficients I need the error signal at time <span class="math-container">$e[n]$</span>. Above is the summarized algorithm from Monson Hayes's book &quot;Statistical Signal Processing and Modelling&quot;.</p> <p><span class="math-container">$$e[n] = d[n] - y[n],$$</span> where <span class="math-container">$d[n]$</span> is the desired signal and <span class="math-container">$y[n]$</span> is the filter output. But in order to calculate <span class="math-container">$e[n]$</span> it seems I need to know <span class="math-container">$d[n]$</span>. But if I know <span class="math-container">$d[n]$</span>, I already know the desired signal, so the whole algorithm becomes irrelevant.</p> Answer: <p>The LMS algorithm uses <span class="math-container">$d[n]$</span> as a training signal to adapt the filter coefficients iteratively. This process is critical for training and tuning the filter to achieve the desired performance. Once trained, the filter can operate without requiring <span class="math-container">$d[n]$</span>, making the algorithm highly relevant for applications such as system modeling, noise cancellation, and signal equalization.</p>
https://dsp.stackexchange.com/questions/94512/adaptive-filtering-isnt-the-desired-signal-dn-already-known
Question: <p>It seems both names are used for the same algorithm:</p> <p><strong>least mean square</strong> - mainly literature before 1990, for example: <em>Widrow, Bernard, and Samuel D. Stearns. &quot;Adaptive signal processing prentice-hall.&quot; Englewood Cliffs, NJ (1985).</em></p> <p><strong>least mean squares</strong> - newer papers / popular posts, for example: wikipedia</p> <p>What is the correct name? Does it matter? Is there a difference I miss?</p> Answer: <p>According <a href="https://www-isl.stanford.edu/%7Ewidrow/papers/j2005thinkingabout.pdf" rel="nofollow noreferrer">this</a> 2005 Stanford reference, &quot;Thinking about Thinking, the Discovery of the LMS Algorithm&quot;, in 1960 the algorithm was baptized <em>least mean square</em>.</p> <blockquote> <p>I met Ted for the first time on a Friday afternoon in the fall of 1959. [...] We didn’t have a name for this algorithm. A year or so later, my Ph.D. students, James S. Koford, gave it the name LMS algorithm for “least mean square,” and the name stuck.</p> </blockquote>
https://dsp.stackexchange.com/questions/83988/lms-adaptive-filter-is-it-least-mean-square-or-least-mean-squares
Question: <p>I'm currently attempting to study up on adaptive digital filters. My book presents the diagram I've included below and I'm having trouble understanding conceptually what it's indicating. The problem deals with noise cancelation. The idea is that someone is driving and makes a phone call. The <em>x(k)</em> is their voice input. There's a reference mic at <em>v(k)</em> which picks up road noise. I know that the ultimate goal is to filter road noise from our transmitted voice signal.</p> <p>The desired output is obviously:</p> <p>$$ d(k)=x(k)+v(k) $$</p> <p>The error in this case is:</p> <p>$$ e(k)=x(k)+v(k)-y(k) $$</p> <p>Taking a quote from my book, it states</p> <blockquote> <p>If the speech <em>x(k)</em> and the additive road noise <em>v(k)</em> are uncorrelated with one another, then the minimum possible value for $e^2(k)$ occurs when <em>y(k) = v(k)</em>, which corresponds to the road noise being removed completely from the transmitted speech signal e(k).</p> </blockquote> <p>I don't understand how <em>e(k)</em> is our output of the system though. It seems to me that if we minimize our error, then it approaches zero. This means that $d(k)-y(k) = e(k)=0$ Consequently if our output is the error and we've minimized it, it seems like we're outputting 0 not a transmitted signal <em>e(k)</em> with the road noise removed!? I guess I'm asking why our desired output <em>d(k)</em> isn't our output....why is the error the output?</p> <p>Can somebody help me understand this conceptually? Thank you for your help! Please let me know if I need to clarify anything.</p> <p><img src="https://i.sstatic.net/Jggp9.png" alt="enter image description here"></p> Answer: <p>Judging from the figure, the situation is slightly different from your explanation in the question. The noise $v(k)$ is the actual noise in the signal, not the noise picked up by the reference microphone. So the noisy signal is $d(k)=x(k)+v(k)$. If you knew $v(k)$ you could simply subtract it from $x(k)$ without the need to use an adaptive filter. What you have is another noise signal $r(k)$, which is a filtered version of the noise $v(k)$. This unknown filter is depicted by the "black box" in the figure. It is filtered because the transfer function from the noise source (road, tires, etc.) to the reference microphone is different from the transfer function to the microphone recording the speech. What the adaptive filter is trying to do is estimate the noise in the speech signal from the reference noise, i.e. it tries to invert the unknown filter in the black box. This can be achieved by minimizing the power of the error signal $e(k)$. The reason is that if you assume that speech and noise are uncorrelated, the output of the adaptive filter can only reduce the noise component in $d(k)$, not the speech component. So the power of $e(k)$ becomes a minimum if the output of the adaptive filter $y(k)$ equals $v(k)$. You don't need to worry that the speech signal is removed because $y(k)$ cannot model the speech signal at all, because noise and speech are assumed to be uncorrelated. So ideally the error signal $e(k)$ contains only clean speech. Note that due to noise and speech being uncorrelated, the power of $e(k)$ can never become zero. Neither can the error signal itself become zero (for all $k$).</p>
https://dsp.stackexchange.com/questions/22325/adaptive-digital-filter-block-diagram-question
Question: <p>I am aware that some filter implementations such as <a href="http://www.signal.uu.se/Staff/pd/DSP/Doc/applicat/chap6.pdf" rel="nofollow noreferrer">lattice/ladder</a> and <a href="https://www.dsprelated.com/freebooks/filters/Series_Parallel_Filter_Sections.html" rel="nofollow noreferrer">SoS sections</a> are advantageous over high order transversal filter structures in terms of coefficient update convergence in adaptive environments but I don't understand why.</p> <p>My first thought was that the transient response is altered because the number of input samples required to populate the states is reduced. But this doesn't make sense because the transient response is a characteristic of the system, not implementation.</p> <p>What am I missing?</p> Answer: <p>I don't know why lattices converges faster. But I know why cascades are hard to converge. Assume you want only a delayed impulse as impulse response. you have many options to achieve this intuitively. This will impose it to slower convergense and multimodality. Im also waiting for others to provide more comprehensive answer.</p>
https://dsp.stackexchange.com/questions/85359/why-are-some-filter-implementations-preferable-for-adaptive-iirs
Question: <p>I am recording data from an accelerometer attached to the chest (1000Hz). I need to extract the respiratory waveform. I tried an adaptive bandpass filter based on a dominant frequency in my signal based on <a href="https://cutt.ly/j24zdj" rel="nofollow noreferrer">https://cutt.ly/j24zdj</a>.</p> <p>Steps in brief: Take frequency spectra, find dominant freq f0, Make a bandpass filter as [max(0.1,f0-0,4), 0.4+rm]</p> <p>The respiration rate could be between anything from 0.1 to 2 Hz. For deep and normal breathing, the filter works just fine. But for rapid and shallow breathings (low amplitude but high freq), it fails. It identifies the dominant freq incorrectly and thus the entire filter goes wrong.</p> <p>For example in the image below: The dominant freq should have been around 0.6, but is identifies as 1.7 (Slight diff in amplitude). So filter works badly.</p> <p>1) How do I design a filter for this? Any suggestions. I can't control the noise in this freq range. The person is as still as possible.</p> <p>2) The red line is spectra after filtering. Why has the amplitude of certain frequencies increased? I am using the 'spec' function in R: uses the hanning window for computing. </p> <p>It's not the issue with plotting. The amplitudes have actually increased. <a href="https://i.sstatic.net/fVa1I.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/fVa1I.png" alt="enter image description here"></a></p> <p><a href="https://i.sstatic.net/K3p3P.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/K3p3P.png" alt="enter image description here"></a></p> Answer: <p>Under the extremely controlled conditions required to measure respiratory rate using this method, you can try to use the <a href="https://en.wikipedia.org/wiki/Autocorrelation" rel="nofollow noreferrer">autocorrelation</a> (which is more robust in the presence of noise) to determine the "dominant" frequency in your signal.</p> <blockquote> <p>2) The red line is spectra after filtering. Why has the amplitude of certain frequencies increased? I am using the 'spec' function in R: uses the hanning window for computing.</p> </blockquote> <p>If that is not a mere rescaling of the waveform as it gets plotted over the same figure (?), then it would be safe to assume that the filter included some overall gain.</p> <p>Hope this helps.</p>
https://dsp.stackexchange.com/questions/59831/adaptive-band-pass-filter-for-extracting-respiratory-waveform-from-accelerometer
Question: <p>Now I am trying to design FIR based adaptive filter for rejection of Jamming in GPS device. (just self-learning purpose, Jamming is simple tone)</p> <p>I've designed NOT-BAD performance adaptive filter for low sampling frequency. (~44100 Hz)</p> <p>But when I use this adaptive filter for high sampling frequency (16 MHz), transient width of filter is greatly increased. (I think it is sure because transient width is proportional to 1/degree)</p> <p>Since it is self learning purpose, I just want to know how big sampling frequency of normal GPS signal for digital filtering is.</p> <p>If it is not so high as above, I'll quit this design and concentrate on other issues(quantization error etc).</p> <p>If sampling frequency of normal GPS signal is high as above, I'll study more about that issue.</p> <p>So, my question is :</p> <p>How high sampling frequency of normal GPS is ?</p> <p>Thank you.</p> Answer: <p>C/A code (the main civilian channel as of now) has a main lobe of around 2MHz and depending on how much processing you want to do, it is normally sampled in the low MHz range, which you are in. (you could pull it off with 2-5MHz).</p> <p>Do know that the signal must be mixed down to a lower frequency before you sample it. The original signal is at 1.57GHz. </p>
https://dsp.stackexchange.com/questions/25111/sampling-frequency-of-gps
Question: <p>This <em>might</em> be a terminology question but I am not sure. </p> <p>Basically, what is the difference between <em>conventional</em> beamformers, and <em>adaptive</em> beamformers? I thought that all beamformers were inherently adaptive to some criteria, like minimization of distortion or variance, or some other spatial filtering criteria etc. So what is the difference between them?</p> Answer: <p>A beamformer is basically a spatial filter. It can be passive, just like a temporal filter. </p> <p>Instead of samples separated by time, they are separated by space. A passive temporal filter can be a bandpass that is "aimed" or "steered" at a particular frequency. For passive spatial filters (i.e. beamformers), the filter can be steered towards a particular angle of arrival, instead of temporal frequency.</p> <p>Adaptive filters/beamformers can be incredible because they can "steer" a null towards a frequency or angle where there is an interfering signal.</p> <p>Just like a temporal adaptive filter, a spatial adaptive filter (i.e. beamformer) is constantly adjusting the filter weights/coefficients to optimize some criteria that usually involves "nulling out" or "rejecting" an interferer.</p> <p>Here's a diagram of a CBF that is called a "K-Omega" Beamformer. <img src="https://i.sstatic.net/TPwe9.png" alt="K-Omega Beamformer Diagram"></p> <p>Here's a diagram to reinforce the idea that a passive beamformer is possible.</p> <p><img src="https://i.sstatic.net/o3bfb.png" alt="Beamformer Concept"></p> <p>I realize that these are a bit random, but hopefully you can follow the logic of the above. I'll see if I can find a better diagram that more clearly shows what's happening. To be clear, the windows referred to above are Hamming/Hanning type windows, and this process is basically returning a 2-d matrix where temporal frequency is on the x-axis and a special spatial variable is on the y-axis. This special variables makes the math easier, and it's a one step process to convert the special spatial variable and temporal frequency to an angle of arrival.</p> <p>The green lines below are lines of constant angles. <img src="https://i.sstatic.net/gftA9.png" alt="Beamforming Angle Lines"></p> <p>Keep in mind that all of this is for CBF (conventional beamformers) and the above covers all spatial and temporal frequency (within the limits of Nyquist.<br> Some common ABF techniques are:</p> <pre><code>MPDR - Minimum Power Distortionless Rejection BF (Described by Van Trees) DMR - Dominant Mode Rejection BF (Abraham and Owsley) R-DMR - Robust Dominant Mode Rejection BF (Cox and Pitre) EBAE - DMR BF with Eigenvector Beam Association and Excision (Kogon) </code></pre> <p>Instead of using a spatial FFT as the spatial filtering operation, these techniques typically involve constructing an updated spatial autocorrelation matrix of the incoming signal, and then using that matrix or eigenvectors of that matrix to adaptively influence the spatial filter.</p> <p>Update for @Mohammad: Below is the list that of beamforming texts I received from my professor:</p> <ul> <li><p>Van Veen, B.D.; Buckley, K.M.; , "Beamforming: a versatile approach to spatial filtering," ASSP Magazine, IEEE , vol.5, no.2, pp.4-24, April 1988</p></li> <li><p>Efficient digital beamforming in the frequency domain Brian Maranda, J. Acoust. Soc. Am. 86, 1813 (1989)</p></li> <li><p>Array Signal Processing by Don Johnson and Dan Dudgeon, Prentice Hall, 1993</p></li> <li><p>Optimum Array Processing by Harry L. Van Trees, Wiley, 2002.</p></li> </ul> <p>Also, after searching around, this looks very interesting. It seems to be more interested in the practical/implementation side than the theory. I don't have it but I'll probably buy a copy:</p> <ul> <li>Practical Array Processing by Mark Sullivan, McGraw Hill, 2008 ( <a href="http://www.practicalarrayprocessing.com/index.html" rel="noreferrer">http://www.practicalarrayprocessing.com/index.html</a> )</li> </ul>
https://dsp.stackexchange.com/questions/7825/difference-between-conventional-and-adaptive-beamformers
Question: <p>I'm having some trouble implementing my LMS Adaptive Filter in MATLAB to separate wideband and narrowband signals from a voice signal.</p> <p>I'm using a delayed version of my input as a reference as well as the error term.</p> <pre><code>step = 0.01; w = zeros(1, N); xDelayed = [zeros(1, 100) x']'; % delaying input for n=1:length(x) e = x(n) - w(1)*xDelayed(n); w = w - step*e*xDelayed(n); end </code></pre> <p>It's essentially an implementation of this</p> <p><span class="math-container">$$w(n+1) = w(n) - \alpha e(n) x(n)$$</span></p> <p>For some reason, my entire w (N long) vector is all the same value. UPDATE:</p> <pre><code>M = 5; N = length(sound) w = zeros(M, N); STEP_SIZE = 0.01; d = sound; x = sound_delayed(1:N); for i=(M+1):N e(i) = d(i) - x((i-(M)+1):i)*w(:,i); w(:,i+1) = w(:,i) + mu * e(i) * x((i-(M)+1):i)'; end for i=(M+1):N yd(i) = x((i-(M)+1):i)*w(:,i); end </code></pre> Answer: <p>There are several problems in your code. First, it looks like you're confusing iteration and vector indices. The computation of <code>e</code> should use <em>all</em> values of the current (delayed) data vector, filtered with the current filter coefficients. In the update equation, you subtract a scalar from a vector, which is not what you want. Again you should be using all values of the current data vector (the length of which must equal the chosen filter length).</p> <p>Take a look at the Matlab code in <a href="https://stackoverflow.com/q/26593385">this question</a> (the second one in the EDIT-part). I haven't run it but it looks like it deals correctly with the vectors in the update loop.</p>
https://dsp.stackexchange.com/questions/53461/adaptive-lms-algorithm-matlab
Question: <p><a href="https://dsp.stackexchange.com/questions/146/how-can-one-improve-the-robustness-of-adaptive-beamformers-to-signal-mismatches">It has been shown</a> that 'diagonal loading' a covariance matrix derived for an adaptive beamformer can improve robustness of the beamformer when the antenna array is perturbed, albeit at the expense of background noise power. </p> <p>The question is <em>why</em> does this work? Is the diagonal loading stopping the adaptive filter from reaching a local minima? Or is there some other mechanism at work here? </p> Answer: <p>I had worked on an array processing problem where I had used diagonal loading of the measurement covariance matrix. But I had used diagonal loading as a solution to what I thought was a numerical issue with my eigen values being too small. Since I had to invert the covariance matrix with small eigen values, I had numerical issues with the result. Diagonal loading of the covariance matrix helped me get rid of the issue as the eigen values were now bounded by the diagonal loading value.</p> <p>I am not sure, but one place where diagonal loading helps is in numerical stability of inverting the covariance matrix which is most likely encountered in adaptive beamforming.</p>
https://dsp.stackexchange.com/questions/303/why-does-diagonal-loading-of-a-covariance-matrix-make-an-adaptive-beamformer-mor
Question: <p>I am quite new to the idea of equalization. I have a few queries regarding the same.</p> <ul> <li>In my application I require to equalize a channel whose impulse response is an IIR response. Is it possible to design an adaptive equalizer based on LMS algorithm to equalize it? I tried some MATLAB simulations and it worked well (the estimation error reduced with each step and converged) for FIR channels but not for IIR responses. So is there any restrictions on the channel characteristics (like FIR/IIR response) for the adaptive filter to function properly?</li> <li>Also, from my simulations for FIR channels I observed that, in absence of noise, the adaptive filter after converging had a response that is inverse of the channel response which is the same as that of a Zero-Forcing equalizer. So is it always true that, LMS adaptive filter will tend to a Zero-forcing equalizing filter in the absence of noise? If yes, can someone refer me to the proof of this?</li> </ul> <p>I have another doubt. Say I am measuring the channel output in presence of an additive zero mean noise,</p> <p>$$Y(z)=X(z)H_c(z)+N(z),$$ </p> <p>Where $H_c(z)$ is the channel response, I still would like the equalizer to estimate the inverse response of the channel. I thought this should work, as if I try to derive the Weiner-Hopf filter, in presence of noise, I end up getting </p> <p>$$R_{dx}(k) - R_xW -E\left[n(l)x^{*}(n-l]\right],$$ </p> <p>Where $R_{dx}$ is the cross correlation between the desired signal $d(n)$ and the filter output $x(n)$, and $R_x$ is the auto-correlation matrix, and $W$ is the filter weights. Since the noise is independent of $x$ and has zero mean, $E\left[n(l)x^{*}(n-l)\right]$ becomes 0 and I again get the same equation. So I thought that the same algorithm could potentially work. </p> <p>Also in the LMS algorithm, instead of using $E\left[e(n)x^{*}(n)\right]$, directly as $e(n)x^{*}(n)$, I tried to take an $L$ point average of the product, with the intention that, since the error $e(n)$ will consist components both due to ISI as well as the additive noise, averaging it will remove the additive noise and retain the ISI, and so the filter coefficients will converge to give the inverse response of the channel. </p> <p>But MATLAB simulations do not agree with my argument above. I want to know the mistake in my argument and also I would like to know if there is any means by which I could still estimate the inverse response of the channel to a good approximation even in presence of a zero mean noise.</p> Answer: <p>Note that the inverse of an FIR system is IIR, and the same is true for the inverse of an IIR system, unless it is an all-pole system, the inverse of which would be FIR. So in most cases the ideal equalizer should have an infinitely long impulse response in order to perfectly invert the channel. In practice almost all adaptive equalizers are FIR filters which can only partly compensate for the channel response. This is why I think that there should be no reason for your equalizer to perform worse for IIR channels than for FIR channels. You could post some more information about the channel responses and the convergence of your equalizer to make it easier to see what's going on.</p> <p>As for the zero forcing criterion, such criteria for designing an equalizer only make sense for noisy channels, because otherwise there is no trade-off between equalizing the channel response and noise enhancement. Zero-forcing and MSE criteria result in the same equalizer in the absence of noise. If you have no noise, the only problem is the (hopefully linear) distortion of the channel and naturally this is the only thing the equalizer would compensate for. However, with an FIR equalizer exact zero-forcing is usually impossible as discussed above.</p>
https://dsp.stackexchange.com/questions/17838/adaptive-equalizer-for-iir-channel
Question: <p>I read a paper about adaptive filtering specifying the following procedure: <span class="math-container">$$ q_{FIR}(k) \overset{\textrm{FIR}}{\longleftarrow} q(k)$$</span></p> <p>The framework processes the input signal (sampled in <span class="math-container">$f_s$</span> sampling rate) using STFT and works batch by batch. Suppose I have a filter in the frequency domain <span class="math-container">$q(k)$</span> (obtained in an adaptive manner, not from a predesigned function like Butterworth or SciPy design-FIR).</p> <ol> <li>Take the adaptive filter <span class="math-container">$q(k)$</span>.</li> <li>Transform the filter to the time domain, i.e. of the general FIR type <span class="math-container">$y[n] = \sum_{i=0}^{N_{org}} b_i x[n-i]$</span> (how <span class="math-container">$N_{org}$</span> is determined?).</li> <li>Truncate the filter, to a given number of taps <span class="math-container">$N_{trunc}$</span>. Then have <span class="math-container">$y[n] = \sum_{i=0}^{N_{trunc}} b_i x[n-i]$</span>.</li> <li>Reconvert the truncated filter (<span class="math-container">$b_0, b_1, ... , b_{N_{trunc}}$</span>) to the frequency domain <span class="math-container">$q_{FIR}(k)$</span>.</li> <li>Perform the filtering in the frequency domain: <span class="math-container">$y_{filt}(k) = q_{FIR}(k)^* u(k)$</span>.</li> </ol> <p>I have two questions about it:</p> <ol> <li>What is it good for?</li> <li>How do I implement it in Python (using NumPy and SciPy)?</li> </ol> <p>The naive way to do it is just to use <code>np.fft.irfft</code> to go from freq to time, then zero all the values after <span class="math-container">$N_{trunc}$</span> (e.g. <code>q_time[N_trunc:]=0</code>) and then go back with <code>np.fft.rfft</code>.</p> Answer:
https://dsp.stackexchange.com/questions/95783/filter-processing-frequency-to-time-truncate-taps-and-back-to-frequency-doma
Question: <p>I have the following equalization problem as shown in the figure below:</p> <p><a href="https://i.sstatic.net/O9Ws2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/O9Ws2.png" alt=""></a></p> <p>Now I can compute the coefficients for my adaptive FIR filter c (dim(c) = N) the following:<br> <span class="math-container">$\mathbf{c_{opt}} = (\mathbf{H}^T\mathbf{H})^{-1}\mathbf{H}~\mathbf{h_{ideal}}$</span><br> where <span class="math-container">$\mathbf{H}$</span> is a convolution matrix with shifted vectors of <span class="math-container">$\mathbf{h}$</span> and <span class="math-container">$\mathbf{h_{ideal}}$</span> is chosen such that <span class="math-container">$x[n]=d[n]$</span> (delay-free equalizer).</p> <p>The channel impulse response is given as<br> <span class="math-container">$\mathbf{h} = [1, 0.5]^T$</span><br> <span class="math-container">$\Rightarrow H(z) = 1+0.5 z^{-1}$</span> so the inverse of the system would be IIR: <span class="math-container">$1/H(z) = \frac{z}{z+0.5}$</span></p> <p>Now the question is the following: What is the difference between the LS-solution with an adaptive filter and direct inversion of the system? Is it just that one filter is FIR and the other one IIR? Therefore with the FIR-filter we cannot reach full equalization and a residual error stays? </p> Answer: <p>Inverting a channel can only be done when the channel is a minimum phase system (trailing echos only). A minimum phase system is characterized as having all zeros in the left half plane (for the s plane, or equivalently in a sampled system and the z plane all zeros inside the unit circle). Inverting such a channel results in poles where every zero exists, and a causal system that has any poles in the right half plane (outside the unit circle) is not stable. So a minimum phase system has a stable causal inverse, while a mixed phase or maximum phase system does not. </p> <p><a href="https://i.sstatic.net/6etDx.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/6etDx.png" alt="leading and trailing echos"></a></p> <p><a href="https://i.sstatic.net/t7PAx.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/t7PAx.png" alt="recursive vs feedforward"></a></p>
https://dsp.stackexchange.com/questions/63914/adaptive-equalization-vs-inverse-of-transfer-function
Question: <p>I'm just a bit confused about the least mean squares algorithm to separate wideband and narrowband in an adaptive filter for voice conversation. I'm interested in the narrowband part and I'm confused about the LMS equation as follows:</p> <p><a href="https://i.sstatic.net/ghBem.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ghBem.png" alt="enter image description here"></a> Is h being iterated twice here with j and n? Wouldn't that mean I have two different sets of h values?</p> <p>I'm having trouble putting this into MATLAB. </p> Answer: <p>I recommend you read up on the <a href="https://en.wikipedia.org/wiki/Least_mean_squares_filter" rel="nofollow noreferrer">LMS algorithm</a> and try to understand it before you start implementing it, otherwise you won't be able to find any errors in your code. In that formula, the index <span class="math-container">$n$</span> is the iteration number, and the index <span class="math-container">$j$</span> is the vector index of the filter coefficients. So at any iteration <span class="math-container">$n$</span> you have <span class="math-container">$N+1$</span> filter coefficients (indexed by <span class="math-container">$j$</span>) that need to be updated according to that equation.</p>
https://dsp.stackexchange.com/questions/53444/least-mean-squares-algorithm-confusion-with-adaptive-line-enhancement
Question: <p>I want to extrapolate a signal <strong>X</strong> of length 11, using the weiner filter coefficients <strong><em>W</em></strong> of length 7. The procedure I am using is as follows:</p> <ol> <li>Compute the autocorrelation matrix upto lag 8 .</li> <li>Using Levinson recursion, invert the autocorrelation matrix <strong><em>A</em></strong>.</li> <li>Multiply the matrix of cross-correlations with the <strong><em>inv(A)</em></strong> to get <strong><em>W</em></strong></li> <li>Obtain <strong>Extrapolated Sample=Sum(W.*Signal)</strong></li> </ol> <p>My questions is that, if now I have a new signal <strong>Y</strong> of length <strong>15</strong> as: <strong>Y</strong>=[<strong>X</strong> (4 new samples)]</p> <p>So the Signal <strong>Y</strong> has first 11 samples of <strong>X</strong> and 4 new samples.</p> <p>Now I want to compute weiner coefficients of this signal, given that I have already computed those for the signal <strong>X</strong>, can you recommend any possible approach to 'update' the filter co-efficients <strong><em>W</em></strong> given the 4 new samples, without having to do the whole weiner filter computation again thus saving some computational time?</p> <p><strong>Edit 1:</strong></p> <p>I have written the code for LMS Algorithm to iteratively 'adapt', when a new sample arrives, the filter co-efficients which were initially derived by Weiner Prediction.</p> <p>The result is not same as the Weiner coefficients derived on the whole input.</p> <p>The code is:</p> <p><code> `FilterOrder=7;</p> <pre><code>Window=7; Filter=zeros(1,FilterOrder); x = -20*%pi:0.1:20*%pi; m=length(x); StepSize=2.3e-4/1000000; data=[cos(2*x(1:floor(m/2))) cos(3.3*x(floor(m/2)+1:m))]; Filter=WeinerCtrace(data(1:Window+1),FilterOrder); // Initial Co-efficients for i=1:50 Input=data(1+i:Window+i); // Sliding Window of Filter Input DesiredOutput=data(Window+1+i); // New sample value ActualOutput=Input(Window:-1:1)*Filter'; Error=DesiredOutput-ActualOutput; while(1) NewFilter=Filter+StepSize*Error*Input; // Gradient Descent if(sum((NewFilter-Filter).^2)&lt;1e-20) break; end Filter=NewFilter; end Filter=NewFilter; end WCoefficients=WeinerCtrace(data(1:Window+i+1),FilterOrder) </code></pre> <p>Now, according to my opinion the values of <strong>WCoefficients</strong> and <strong>Filter</strong> should match as the <strong>WCoefficients</strong> are computed by applying Weiner Prediction on all the arrived data, while <strong>Filter</strong> is computed iteratively on introduction of every new sample.</p> <p><strong>Edit 2:</strong> I have also implemented the RLS algorithm code given below, but the output of RLS still does not match the output of Weiner Prediction Coefficients for the same window: <code></p> <pre>FilterOrder=11; Window=11; t=0:1:1000; f=linspace(.5,5,length(t)); fs=100; data=cos((%pi/fs)*(f.*t)); [Filter,P]=WeinerCtrace(data(1:Window+1),FilterOrder); w=1; plot(data,'-r'); for i=1:500 Input=data(Window+i:-1:1+i)'; // Sliding Window of Filter Input DesiredOutput=data(Window+1+i); // New sample value ActualOutput=Input'*Filter; Error=DesiredOutput-ActualOutput; K=(P*Input)/(w+(Input'*P*Input)); P=(P-(K*Input'*P))/w; Filter=Filter+(K*Error); end inp=data(i+1:Window+i+1); WC=WeinerCtrace(inp,FilterOrder) inp=data(i+1:Window+i); for j=1:100 NextValue=inp(11+j-1:-1:j)*WC; inp=[inp NextValue]; plot(Window+1+i+j,NextValue,'r+') end inp=data(Window+i:-1:1+i); for j=1:100 NextValue=inp(1:Window)*Filter; inp=[NextValue inp]; plot(Window+1+i+j,NextValue,'b*') end </code></pre> <p></code></p> <p>Can someone point out what am I doing wrong in the code or in anything else ? Any suggestions/idea is welcome. Thanks!</p> Answer: <p>The Wiener filter is, by definition </p> <p>a) not adaptive and </p> <p>b) not FIR / AR. </p> <p>You seem to want an adaptive FIR filter. </p> <p>There are many variants of this: <a href="http://en.wikipedia.org/wiki/Least_mean_squares_filter" rel="nofollow">LMS</a>, <a href="http://en.wikipedia.org/wiki/Least_mean_squares_filter#Normalised_least_mean_squares_filter_.28NLMS.29" rel="nofollow">NLMS</a>, <a href="http://en.wikipedia.org/wiki/Recursive_least_squares" rel="nofollow">RLS</a> (as you say), or the <a href="http://en.wikipedia.org/wiki/Kalman_filter" rel="nofollow">Kalman filter</a>. Choose your poison! :-) </p> <p>ALL of them are (generally) less computationally intensive that the Wiener filter.</p>
https://dsp.stackexchange.com/questions/11422/adaptive-wiener-filter-coefficients-calculation
Question: <p>AEC algorithms mostly rely on LMS adaptive filtering, i.e. you update FIR filter coefficients then perform the filtering. Theoretically, the FIR must be as long as the maximum echo length you want to cancel. For instance to cancel delays up to 500ms on a 48kHz signal, you'll need a 24000 point FIR. When your memory and processing power limitations make it so you can neither afford to perform 24000 MACs per processed sample, nor to use FFT-based fast convolution algorithms, is there a way around for cancelling such potentially high length echoes in a more affordable way, given delay is unknown and potentially variable?</p> <p>I was wondering maybe about some other algorithm running in parallel that could assess the approximate delay, then use an adaptive length delay line + a shorter adaptive FIR filter (up to a few hundreds taps is OK)</p> <p>Does this make sense? Any other neat approach to suggest?</p> Answer: <p>I believe you logic is reasonable. The fact that there are companies offering algorithms for long echo tail (even above 1 second) with reasonable performance indicates that an algorithm similar to your suggested logic can work.</p>
https://dsp.stackexchange.com/questions/26689/echo-cancellation-supporting-long-delays-and-without-frequency-domain-processing
Question: <p>What is the best filter for removing Gaussian noise without destroying the edges? I am using the standard Lena images with additive Gaussian noise and I want to denoise before applying anisotropic diffusion. I don't want to median filter because edges become blurred. I tried adaptive filtering but results were not satisfactory.</p> Answer: <p>You might need to consider more advanced techniques. Here are two recent papers on edge-preserving denoising:</p> <ul> <li><p><a href="http://dx.doi.org/10.1109/TIP.2006.877409">Edge-Preserving Image Denoising via Optimal Color Space Projection</a> <a href="http://web.mysites.ntu.edu.sg/zvitali/publications/.../colordenoisefinal.pdf">[in color]</a> This paper preserves edges by decomposing the image into an "optimal" color space and performing wavelet shrinkage. The optimal color space belongs to the luminance/color-difference family (think L*a*b*, or YCrCb).</p></li> <li><p><a href="http://dx.doi.org/10.1016/j.sigpro.2010.04.009">Edge Structure Preserving Image Denoising</a> From the paper:</p></li> </ul> <blockquote> <p>Our method is based on [jump regression analysis], and consists of three major steps, outlined below. First, edge pixels are detected in the whole design-space by an edge detector. Second, in a neighborhood of a given pixel, a piecewise-linear curve is estimated from the detected edge pixels by a simple but efficient algorithm, to approximate the underlying edge segment in that neighborhood. Finally, observed image intensities on the same side of the estimated edge segment, as the given pixel, are averaged by the local linear kernel smoothing procedure (cf., [35]), for estimating the true image intensity at the given pixel.</p> </blockquote> <p>(<em>Jump regression models</em> incorporate discontinuities using step functions. The primary author <a href="http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471420999,subjectCd-EEC0.html">has a book on this subject</a>.)</p>
https://dsp.stackexchange.com/questions/1365/how-to-remove-gaussian-noise-from-an-image-without-destroying-the-edges
Question: <p>I have to apply some kind of adaptive filter to my function $f(x).$ I present each point of my signal as a Gaussian, whose bandwidth depends on its location <strong>(not the point of observation $\textbf{x}$)</strong> as $h(t),$ which is a known pre-calculated function. The final output function $s(x)$ is a superposition of the influence of all Gaussians (of all points).</p> <p>$$s(x)=\int\limits_{-\infty}^{+\infty}f(t)g(h(t),x-t)dt$$</p> <p>$g(h(t),x)$ is a $NormPDF(\sigma, x_0, x)$ with $\sigma=h(t)$, $x_0=0$</p> <p>NB: the diameter of each Gaussian depends on the location of each Gaussian $t$, not on the location of observation point $x$.</p> <p>It gives a good look of $s(x)$, but is calculates a bit too slow.</p> <p>If I had a fixed-bandwidth filter, I could perform the well-known fast convolution algorithm via FFT. Or I could drop the faraway points and have the convolution as: $$s(x)=\int\limits_{x-\Delta x}^{x+\Delta x}f(t)g(h(t),x-t)dt$$</p> <p>But for the adaptive filter I should take my $\Delta x$ at least twice as large, as the maximum bandwidth is (in my case it is nearly 30% of all x area), so it cannot give a big profit.</p> <p>Also, I don't know any algorithms of fast convolutions for such types of filters.</p> Answer:
https://dsp.stackexchange.com/questions/10561/need-a-fast-algorithm-of-adaptive-convolution
Question: <p>I see mention that normalized LMS &quot;usually converges faster than LMS&quot;, in Diniz &quot;Adaptive Filtering&quot; p.152, can this be made more precise? IE, for which signal distributions does it hold?</p> <p>I'm in particular interested in overparameterized regime where misadjustment is zero for LMS and NLMS.</p> <hr /> <p><a href="https://i.sstatic.net/VJU0V.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/VJU0V.png" alt="enter image description here" /></a></p> Answer:
https://dsp.stackexchange.com/questions/83564/when-is-normalized-lms-better-than-lms
Question: <p>In adaptive filters, the development of LMS algorithm typically starts from the Weiner-Hopf equation, while the development of RLS algorithm starts from the normal equation. As I understand, these two equations are the same, and both their solutions is the optimal coefficients that the adaptive filter has to find. Is this true or am I missing something?</p> Answer: <p>Weiner-Hopf equation leads to Wiener filter that is optimal filter. For the case of stationarity in some time span it's the only filter minimizing MSE at its output. LMS and RLS algorithms are the adaptive approaches and they converge to Wiener optimal solution (as you can see from their convegence curves). While LMS is the simple steepest descent method of finding such an optimum, RLS solves Least Squares estimation problem at every step recursively.</p> <p>LS estimation problem can be treated as a practical approach of Wiener filter. Look:</p> <ul> <li>$w = \hat{R}^{-1} \cdot \hat{r}$</li> </ul> <p>is the normal equation in matrix form for the LS problem, $\hat{R}$ and $\hat{r}$ are estimations of autocorrelation matrix and cross-correlation vector respectively. So if these estimations is properly done this solution leads us to the Wiener-Hopf eq., i.e. to Wiener filter. But it's only true if estimations are valid. So in general LS solution is <strong>not</strong> a Wiener solution, it's an approximation. </p> <p>RLS approach is derived from LS (as it can be viewed from abbreviation):</p> <ul> <li>$w(k) = S(k) \cdot \hat{r}(k)$,</li> </ul> <p>where $S(k)$ is recursive estimation of $R^{-1}$ and $\hat{r}(k)$ is a recursive estimation of $r$. From the equation above one can see RLS try to solve LS problem at every step. </p> <p>So the conclusion might be both LMS and RLS try to converge to Wiener solution and Wiener filter theory is in the core of these algorithms. But ways they do this are different. </p> <p>This is my own understanding, maybe some discrepancies are possible. There is very good reference about adaptive filters: <a href="http://books.google.ru/books/about/Adaptive_Filter_Theory.html?id=MdDi_PF7gMsC&amp;redir_esc=y" rel="nofollow">http://books.google.ru/books/about/Adaptive_Filter_Theory.html?id=MdDi_PF7gMsC&amp;redir_esc=y</a> </p>
https://dsp.stackexchange.com/questions/17632/what-is-the-difference-between-the-weiner-hopf-equation-and-the-normal-equation
Question: <p>Is it when the cost function such as the error signal or Mean Square Error (MSE) signal is minimised?</p> Answer: <p>The adaptive filter is converged when the error is what they call Wide Sense Stationary, meaning the mean and variance of the error are unchanging over long time intervals.</p>
https://dsp.stackexchange.com/questions/28366/how-is-it-determined-that-an-adaptive-filter-has-converged
Question: <p><a href="https://i.sstatic.net/huadl.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/huadl.jpg" alt="enter image description here"></a><a href="https://i.sstatic.net/p7Tm1.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/p7Tm1.jpg" alt="Image shows the matlab code of lms algorithm."></a><a href="https://i.sstatic.net/f51LY.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/f51LY.jpg" alt="enter image description here"></a></p> <p>I am giving white noise as input to an adaptive filter which is initialized to zero (value of filter coefficients of adaptive filter is 0). I am getting a desired response <span class="math-container">$d(n)$</span> by passing white noise through an unknown channel of impulse response <span class="math-container">$h(n)$</span>. </p> <p>Now using LMS algorithm, I am trying to update the adaptive filter coefficients by using the equation <span class="math-container">$$w(n+1)=w(n)+\mu u(n) e(n)$$</span> where <span class="math-container">$\mu$</span> is the step size or adaptation speed of the algorithm, <span class="math-container">$u(n)$</span> is the white noise which is passed to a speaker and <span class="math-container">$e(n)$</span> is the difference between desired response and estimated response.</p> <p>Even after <span class="math-container">$n$</span> number of iterations, why is that the error signal, which is the difference between desired response and estimated response, not decreasing but remaining almost constant.</p> Answer: <p>As mentioned in the comment, I modified the code given here and was able to adapt the LMS filter with error tapering to zero. The only assumption I made is that (since I am not an audio expert and do not know how the channel from speaker to the microphone would look like), I assumed a 10 tap channel with only first 3 non-zero values (multi-path reflection from walls). OP is free to use a channel of his/her choice. Using this I generated 'actual_fb_path' by convolving white-noise with assumed channel. If I get access to 'actual_fb_path' it would be great. <strong>I would request OP to modify this as per the system model to see if it adapts to the delay.</strong></p> <pre><code>clc clear all close all training_input = rand(1,100); h_actual = [0.8 0.3 0.05 zeros(1,7)]; %channel assumption actual_fb_path = conv(training_input, h_actual); d = actual_fb_path; mu = 0.1; %ha = lms(40,mu); %[y,e] = filter(ha, training_input, d); lms = dsp.LMSFilter; lms.StepSize = mu; lms.Length = 10; [y,e]=lms([training_input zeros(1,9)]', d'); %subplot(2,1,1) N=length(training_input) + length(h_actual)-1; figure() plot(1:N,d,'r',1:N,y,'b',1:N,e,'g') title('System') legend('Desired','Output','Error') </code></pre> <p><a href="https://i.sstatic.net/BIan4.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/BIan4.png" alt="enter image description here"></a></p>
https://dsp.stackexchange.com/questions/64515/why-is-the-error-between-the-desired-signal-and-estimated-signal-in-the-case-of
Question: <p>I am trying to create an adaptive noise canceller using the RLS algorithm. The dsp toolbox from matlab offers <a href="https://de.mathworks.com/help/dsp/ref/dsp.rlsfilter-class.html" rel="nofollow noreferrer">the RLS adaptive filter</a> already implemented, so this saved me some trouble.</p> <p>My goal is to filter out the hearth beat signal from the muscle signal, however, so far I have had zero to no success. After reading a decent amount of articles on the internet, I found out that the adaptive filters are suitable for this purpose as I have a reference signal of the electrocardiogram, which I want to remove. I chose the RLS algorithm, as it converges faster than the LMS algorithm, so it should be the better option. The filter order is set to 60 and the <code>ForgettingFactor</code> is 0.999, which according to multiple sources, should result the removal of the noise signal, however, in my case the hearth beat signal is still significantly noticeable.</p> <p><a href="https://i.sstatic.net/iUi8y.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/iUi8y.jpg" alt="Raw Data"></a> <a href="https://i.sstatic.net/cWxzx.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/cWxzx.jpg" alt="Filtered Data"></a></p> <p>From the attached images, you can see that the signal is not filtered. Should I process the signal before using the adaptive filter or is the method wrong (or badly implemented) and I should try something else?</p> Answer:
https://dsp.stackexchange.com/questions/43075/noise-cancellation-using-rls-filter
Question: <p>I understand how echo cancellation works with a single speaker and no reverberation (using adaptive filtering and freezing the coefficients during double-talk). However, in cases with more than one speaker source or reverberation causing different propagation of the same signal, would this not completely change the combined signal and cause issues with the ability to cancel the echo? Thanks in advance!</p> Answer:
https://dsp.stackexchange.com/questions/50679/how-do-state-of-the-art-echo-cancellation-algorithms-deal-with-variable-propagat
Question: <p>In "adaptive filter theory" and "advance signal processing and Noise reduction" they have directly come up with the term gain without stating how they got it.</p> <p>In adaptive filter theory they have jumped from equation 13.16 to 13.18.</p> <p><a href="https://i.sstatic.net/Ene7I.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Ene7I.png" alt="enter image description here"></a></p> <p>Same in advance signal processing equation 7.74 to 7.76. I have shared the derivation from both the books.</p> <p><a href="https://i.sstatic.net/2R1uM.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2R1uM.png" alt="enter image description here"></a></p> <p>In negative feedback control system,the Transfer function is g(s)/(1+g(s)h(s)).Is it any how related to this.</p> <p><a href="https://i.sstatic.net/wMLgG.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/wMLgG.png" alt="Signal Flow graph of RLS algorithm (Adaptive Filter theory Simon Haykin)"></a><a href="https://i.sstatic.net/4QOCc.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4QOCc.png" alt="Gain of RLS algorithm"></a></p> Answer: <p>In all adaptive signal processing schemes, be it a Least Mean Squares (LMS), Recursive Least Squares (RLS) or a Kalman Filter, The fundamental concept is the <strong>update</strong> of some parameter: such as the vector filter coefficients of a Transversal Tapped Delay Line (an FIR indeed) structure of LMS or a state of a dynamical system as in the Kalman filter.</p> <p>The generic structure of the update mechanisms resembles the following:</p> <pre><code> parameter(n+1) = parameter(n) + K(n)*errorfunction(n) </code></pre> <p>in which the thing called <strong>parameter</strong> is updated from its previous value at index n to its current value at (n+1), based on a correction term that is some meaningful function of error (denoted by errorfunction(n)) and weighted by a specific multiplier <strong>K</strong>(n) commonly referred to as the GAIN.</p> <p>As you can see, the gain multiplier, determines the amount of correction that will be applied to the current value of the parameter so as to update it to its next value. That's why its called as the gain. The larger the gain K(n) the more correction there will be hence more responsive will the filter be untill it becomes unstable due to too much gain etc... The gain K(n) shall be made variable based on the convergence properties of the filter.</p> <p>The specific form and derivation of an optimal gain term is completely dependent on the filter structure and the necessary mathematical manipulations of the signals inside the processing blocks, so as to get the required update equations...</p>
https://dsp.stackexchange.com/questions/35337/how-the-gain-term-k-left-n-right-is-derived-why-is-it-called-gain
Question: <p>I am using a Recursive least square adaptive filter to process electromyography signals and it is working decently so far. I decided to implement an LMS adaptive filter as a noise cancellation, so that I can compare the results, however, going through the matlab documentation for the <a href="https://de.mathworks.com/help/dsp/ref/dsp.lmsfilter-class.html" rel="noreferrer">LMS filter</a> and seeing the <code>LeakingFactor</code> $$0&lt;\alpha&lt;1$$ and the <code>ForgettingFactor</code> of the RLS filter$$0&lt;\lambda&lt;1$$ I am now confused if there is an actual difference between those two parameters or is the difference only in the names?</p> Answer: <p>The play similar role in those algorithms - the ability to forget the past and adapt to current reality. </p> <p>In the LMS, the classic implementation has $ \alpha = 1 $.<br> Namely the optimal weights at any point are function of all inputs. </p> <p>The Leakage factor allows to weigh the past differently in a damped manner which over times means the far past has practically no significance on the current result.<br> The other side means the ability to integrate data against noise is decreased which is the same balance the user stands when selecting the parameters of the RLS.</p> <p>Namely, as usual, the balance between high bandwidth filter which adapts fast yet is sensitive to noise or the low bandwidth filter which is slow yet if the data is stationary can handle high energy noise.</p>
https://dsp.stackexchange.com/questions/42938/difference-between-leaking-factor-and-forgetting-factor
Question: <p>While reading a book on adaptive filter, I have came across a term 'nonlinear' associated with signal.</p> <p>But I have learned about the linear and non linear system, which is defined by the principle of homogeneity and additive. I am curious to know the definitions of a non-linear signal. I have search over the internet but not found any definitions related to 'linear or non linear signal.'</p> <p>For reference I have attached the screenshot of that book (Adaptive Filter Theory -Simon Haykin).<a href="https://i.sstatic.net/8M5e9f0T.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/8M5e9f0T.jpg" alt="screenshot of book" /></a></p> Answer: <blockquote> <p>I am curious to know the definitions of a non-linear signal</p> </blockquote> <p>There is no such thing. Linearity (or lack thereof) are a property of systems, not signals. Linearity is only defined for the relationship between an input and an output signal. The term and it's definition are meaningless for a single signal.</p>
https://dsp.stackexchange.com/questions/97847/non-linear-signal-mean
Question: <p>I do understand that MPC is a control method and requires known model in the feedback path. LMS, on the other hand, is more like an adaptive filtering, which estimates the tap coefficients yielding the minimum mean squared error. Plus, LMS does not require known model.</p> <p>Besides the differences I mentioned above, what is the difference between LMS and MPC, and when would one use LMS (or MPC) over the other?</p> Answer:
https://dsp.stackexchange.com/questions/73701/what-is-the-difference-between-lms-and-mpc
Question: <p>I'm tinkering in Matlab with a problem that's very similar to active noise cancellation. In the literature, the secondary path is described as the transfer function from the output of the adaptive filter to the error input sensor. The algorithm needs to model this path to obtain good results.</p> <p>However, there is also the transfer function from the noise source to the adaptive filter. The ADC will always have some transition band below the Nyquist rate. When I simulate the ADC in Matlab, the adaptive filter tries to invert the ADC response as well as model the system I'm trying to cancel. In fact, if the system is purely a delay, this is exactly the inverse system identification problem.</p> <p>In some applications, the ADC can be ignored because the signal may already be digital, but I don't think that is ever the case with ANC. Why is this not mentioned as being a problem? Is it because, in practice, the impulse response of the ADC is short compared to the system response?</p> Answer: <p>You are correct that the system will attempt to invert the ADC filter. In acoustics this is not usually a problem because there is not much energy at those frequencies. If your application is not a standard acoustic system, there may be an opportunity to put a copy of the ADC filter in the plant path (this is normally not possible because the error summation only exists in the acoustic domain). Alternatively you can put a gentle low pass filter on the error signal so the adaptive filter will not respond to near-Nyquist frequencies. This will slow down the adaptation speed slightly. </p>
https://dsp.stackexchange.com/questions/28058/modeling-adc-in-active-noise-cancellation
Question: <p>I meet a problem with designing a filter. I have two different instruments that could measure the same AC signal (usually ~200hz, always &lt;1kHz), <strong><em>A</em></strong> and <strong><em>B</em></strong>. <strong>A</strong> can carry out signal measurement during the normal operation of the instrument. <strong><em>B</em></strong> can only be used during instrument calibration, and <strong><em>A</em></strong> can also be used at this time. <strong><em>B</em></strong> can accurately measure the signal. The measurement accuracy of <strong><em>A</em></strong> is lower than that of <strong><em>B</em></strong>.</p> <p>I want to design a real-time filter for <strong><em>A</em></strong> to filter out the interference noise. The parameters of the filter are adjustable. When the instrument is calibrated, both <strong><em>A</em></strong> and <strong><em>B</em></strong> are used to measure the signal. The measurement result of <strong><em>B</em></strong> is taken as the standard result to calculate the parameters of the filter adaptively. After setting the parameters of the filter, <strong><em>A</em></strong> is used to measure the signal without <strong><em>B</em></strong>.</p> <p>I have investigated a variety of filters and found that the adaptive filter is quite suitable for my needs. However, the adaptive filter needs to input two signals, while I can only provide the measurement result of <strong><em>A</em></strong> during the operation of the instrument. So the adaptive filter is not completely suitable for my needs. </p> <p>I don't know how to solve this problem. Is there any method that suits my needs? Thank you very much!</p> Answer: <p>If you can use a higher precision instrument to measure the signal, then, if the signal maintains it's characteristics, you can build a system's model and use a Kalman filter for the "not so good" input channel.</p>
https://dsp.stackexchange.com/questions/67728/how-to-design-a-filter-that-can-filter-out-noise-accurately-after-setting-the-p
Question: <p>I am trying to remove low frequencies from a signal and intuitively I chose the high-pass filter, more specifically - a Butterworth filter, Order 4 (because I am not sure how to choose properly the order and 4 seemed as a good choice) and cutoff frequency of 50 Hz. The problem is, that the filter removes the low frequencies, however, the peaks that were caused from those low frequencies are still to be seen.</p> <p>I have read also about adaptive filtering, but according to the literature, I need a reference signal, which would be used as a desired signal. I tried implementing an adaptive RLS/LMS filter and as a reference signal, I processed my data with a low-pass filter - Butterworth, 4th Order, 50 Hz for the cutoff frequency. This method also did not get me far.</p> <p>I have provided a <a href="https://www.dropbox.com/sh/k5i3gavyczor2y1/AAAhtWISRs0wHgIT66xVP3gAa?dl=0" rel="nofollow noreferrer">a copy of my data</a>, which is sampled at 1500 Hz. <a href="https://i.sstatic.net/qheYy.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/qheYy.jpg" alt="enter image description here"></a></p> Answer: <p>You want to remove the heart beat signal and keep the "noise". We can solve this problem by using a denoising algorithm, and subtracting the denoised signal from the original signal.</p> <p>Setting frequency cutoffs for a frequency domain filter can get tricky and turn into a game of whack-a-mole because there's "high frequency" components in the heartbeat blip (due to the sudden rise and fall) and also in the wiggly stuff between a heart beat's T wave and the next heart beat's P wave.</p> <p>Loosely speaking, the requirements in this de-noising problem are as follows:</p> <ul> <li>Remove the little wiggles</li> <li>Maintain larger jumps that appear in a heart beat PQRST waveform</li> </ul> <p>This sounds like a great place to apply $\ell_1$ denoising or total variation denoising. The idea is to approximate the given signal $y$ with a signal $x$ such that the derivative of $x$ is "sparse" i.e. it doesn't change too frequently, but when it changes, the change is large. The denoised estimate $\hat x$ is given by: $$ \hat x = \min_x ||y-x||_2^2 +\lambda\sum|x_i-x_{i-1}| $$</p> <p>I used <a href="https://github.com/albarji/proxTV" rel="noreferrer">proxTV toolbox in Python</a> to solve this optimization problem.</p> <pre><code>import scipy.io as sio import numpy as np import matplotlib.pyplot as plt import prox_tv as ptv mat_struct = sio.loadmat('Signal1.mat') noisy_signal = mat_struct['x'].T[0] filtered_signal = ptv.tv1_1d(noisy_signal, 50) time_vec = np.linspace(0, len(noisy_signal)/1500., len(noisy_signal)) plt.close('all') fig, ax = plt.subplots(3,1,sharex=True) ax[0].plot(time_vec,noisy_signal) ax[0].set_title('noisy signal') ax[1].plot(time_vec,filtered_signal) ax[1].set_title('filtered signal') ax[2].plot(time_vec,noisy_signal - filtered_signal) ax[2].set_title('noise') ax[2].set_xlabel('time (s)') plt.tight_layout() plt.show(block=False) </code></pre> <p>And here's the resulting plot: <a href="https://i.sstatic.net/YlLuJ.png" rel="noreferrer"><img src="https://i.sstatic.net/YlLuJ.png" alt="enter image description here"></a></p> <p>Of course, there's a different kind of whack-a-mole you'll have to play with this technique: the $\lambda$ parameter which I set to $50$ in the code.</p>
https://dsp.stackexchange.com/questions/43374/removing-low-frequencies-from-a-signal
Question: <p>Suppose,I have an input of length of lenght 100. data=[x0...x99]; I take a window of lenght 11 from x0 to x10. windowed data=[x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10], now, I compute 7 wiener coefficients which are [w0 w1 w2 w3 w4 w5 w6]; next I will move by window one sample forward, new windowed data= [x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11],</p> <p>My question how can I use the previously calculated wiener coefficients to calculate the new wiener coefficients for the new windowed data? Also I want this to be done in the shortest possible time.</p> Answer:
https://dsp.stackexchange.com/questions/11475/adaptive-calculations-of-wiener-filter-coefficients
Question: <p>$$\hat f(x, y) = g(x, y)-\frac{\sigma_n^2}{\sigma_L^2}\left[g(x, y)-m_L\right]$$</p> <p>What are the meanings of the following terms:</p> <ul> <li>$m_L$</li> <li>${\sigma_\eta}^2$</li> <li>${\sigma_L}^2$</li> </ul> <p>Here we see that $m_L$ is subtracted from the Image and then the whole term is multiplied by $\frac{{\sigma_\eta}^2}{{\sigma_L}^2} $. Then, the whole term is again subtracted from $g(x,y)$.</p> <p>What does that actually mean?</p> Answer: <p>A wild guess. $L$ denotes a region $R$ around pixel $g(x,y)$, potentially a symmetric one of size $(2L+1)\times (2L+1)$. $m_L$ and $\sigma_L^2$ are the average and variance in $R$. And $\sigma_n^2$? Probably the estimated noise variance over the whole image, supposed stationary.</p> <p>In a flat region with noise $\sigma_L^2 \sim \sigma_n^2$, the result could be close to the average. Around edges, one expect an higher response, so sharper. Potential problems arise when $\sigma_L \ll \sigma_n $. Another interpretation: </p> <p>$$\hat{f}(x,y)=(1-\frac{\sigma_n^2}{\sigma_L^2})g(x,y)+ \frac{\sigma_n^2}{\sigma_L^2}m_L(x,y)$$ is a sort of weighted mean (since weights sum to one) of the image and its smoothed version, whose dependency on $(x,y)$ is made more explicit. </p>
https://dsp.stackexchange.com/questions/29513/what-is-an-adaptive-mean-filter
Question: <p>I'm working with AEC of Speex. The algorithm is based on the MDF adaptive filter + an adaptive learning rate. I'm using it like a ANC and it works very well. Does anybody have some material, as block scheme, data flow diagram of the AEC of Speex. I have read the documentation but it is not very useful for the dsp concepts. thank you so much m</p> Answer:
https://dsp.stackexchange.com/questions/15075/aec-speex-how-does-it-work
Question: <p>I'm trying to implement a simulation of an ANC system with python, using this model <a href="https://www.mathworks.com/help/audio/ug/active-noise-control-with-simulink.html#d122e12289" rel="nofollow noreferrer">here</a>. <a href="https://i.sstatic.net/5sCIt.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/5sCIt.png" alt="enter image description here" /></a></p> <p>My simulation keeps diverging, and I honestly don't know why. I'm using a source for LMS adaptive filter from <a href="https://www.mathworks.com/help/dsp/ref/lmsupdate.html#bvbj4f3" rel="nofollow noreferrer">Mathworks here</a>. When I comment out the LMS update function, the system is stable, and the output is exactly the input. But when I plug in the adaptive filter update, the system starts to diverge. So I thought the problem is with my LMS update. And I implemented the LMS adaptive filter with padasip package. The system is still diverging. Now I honestly don't know how I copied the model from Matlab wrong. Can someone help? Though It's not a syntax error, I pasted my code below for reference. I used all difference equations for every system.</p> <p>Some values I used in this, The input I'm using is a white noise file I generated from Matlab, 1dB power and sampling frequency of 16000 Hz.</p> <p>b for S(z) is [0.5,0.5,-.3,-.3,-.2,-.2,]</p> <p>b for S_est(z) is [0.466,0.533,-0.257,-0.274,-0.231,-0.175]</p> <p>b for Main path S(z) is [0.0500,0,0.0200,0,-0.0000,0,-0.1250,0,-0.0500,0,0.0750,0,0.0300]</p> <p>All I copied from the Simulink simulation of the same system</p> <pre><code>#ANC Simulation Main import pyaudio, wave, struct, math import numpy as np from matplotlib import pyplot as plt import padasip as pa ## Variables Setup mu = 0.1 MAXVALUE = 2**15-1 # Maximum allowed output signal value (because WIDTH = 2) # Initialization of adaptive weight w w = np.zeros(13) # Main Path Filters order_path = 12 b_path = np.array([0.0500,0,0.0200,0,-0.0000,0,-0.1250,0,-0.0500,0,0.0750,0,0.0300]) x = np.zeros(13) y_main_path =0 #Adapt filter order_adapt = 12 y_adapt =np.zeros(13) filt = pa.filters.FilterLMS(13, mu=mu) #second path order_sec_path = 12 b_sec_path = [0.5,0.5,-.3,-.3,-.2,-.2,0,0,0,0,0,0,0] y_secpath = 0 #est sec path order_est_sec_path = 12 b_est_sec_path = np.array([0.466,0.533,-0.257,-0.274,-0.231,-0.175,0,0,0,0,0,0,0]) est_sec_out = 0 y_estsecpath = np.zeros(13) # File names wavfile = 'matlab_1db_wn.wav' output_wavfile = 'ANC_Result.wav' ## Read WAV file wf = wave.open(wavfile,'rb') CHANNELS = wf.getnchannels() # Number of channels RATE = wf.getframerate() # Sampling rate (frames/second) signal_length = wf.getnframes() # Signal length WIDTH = wf.getsampwidth() # Number of bytes per sample print('The file has %d channel(s).' % CHANNELS) print('The frame rate is %d frames/second.' % RATE) print('The file has %d frames.' % signal_length) print('There are %d bytes per sample.' % WIDTH) # Read first BLOCKLEN binary_data = wf.readframes(1) ## Output WAV file output_wf = wave.open(output_wavfile, 'w') output_wf.setframerate(RATE) output_wf.setsampwidth(WIDTH) output_wf.setnchannels(CHANNELS) ## Open audio stream p = pyaudio.PyAudio() stream = p.open( format = p.get_format_from_width(WIDTH), channels = CHANNELS, rate = RATE, input = False, output = True ) ## Main Loop while len(binary_data) &gt; 0: # convert binary data to numbers input_block = struct.unpack('h', binary_data) input_value = input_block[0] x = np.delete(x,-1) x = np.insert(x,0,input_value) y_main_path = np.dot(b_path,np.transpose(x)) y_adapt = filt.predict(input_value) #y_adapt = np.delete(y_adapt,-1) #y_adapt = np.insert(y_adapt,0,adapt_out) est_sec_out = np.dot(b_est_sec_path,np.transpose(x)) y_estsecpath = np.delete(y_estsecpath,-1) y_estsecpath = np.insert(y_estsecpath,0,est_sec_out) #sec path y_secpath = np.dot(b_sec_path,np.transpose(y_adapt)) output = y_main_path - input_value # LMS update filt.adapt(y_main_path,input_value) output = np.clip(output, -MAXVALUE, MAXVALUE) output = output.astype(int) binary_date = struct.pack('h', output) stream.write(binary_data) output_wf.writeframes(binary_data) binary_data = wf.readframes(1) stream.stop_stream() stream.close() p.terminate() # Close wavefiles wf.close() output_wf.close() </code></pre> Answer: <p>Turns out it's just a scaling issue. Because the struck.unpack() gives out a signed 16-bit value, the step size is too large for it. Two ways to go around this, you scale down your input and scale back up when outputting, or you just adjust the step size mu.</p> <p>I used a mu value of 10e-8 and seems like this value works differently in different environments, reasons unknown. With jupyter-notebook is around 10e-7, python idle is 10e-8, and Matlab is 10e-9. Just tweak around that range with the code I posted above and should give you a converged result.</p> <p>Hope this helps whoever is reading.</p> <p>edit; for MatLab, I scaled the input by 32768 so the mu value is 10e-9, if max amplitude is 1, use 0.1.</p>
https://dsp.stackexchange.com/questions/73668/what-is-causing-my-anc-lms-update-to-diverge
Question: <p>I found algorithms that seems the same to me, but they are described with different names (in field of adaptive filtering).</p> <p>For example:</p> <ol> <li><p><strong>LMS - least-mean-squares</strong> seems to be <strong>GD - stochastic gradient descent</strong> </p></li> <li><p>Often the <strong>stochastic gradient descent</strong> is called just <strong>gradient descent</strong> what seems to be something different (but still similar) according to wikipedia.</p></li> <li><p>Extension of GD (or LMS) with normalization seems to be always called NLMS, why not NGD?</p></li> </ol> <p>Why are the used names different? Are the algorithms really the same thing or am I wrong?</p> Answer: <p>The LMS algorithm is based on the idea of gradient descent to search for the optimal (minimum error) condition, with a cost function equal to the mean squared error at the filter output. However, it doesn't actually calculate the gradient directly, as that would require knowing:</p> <p>$$ E(\mathbf{x}[n]e^*[n]) $$</p> <p>where $\mathbf{x}[n]$ is the input vector and $e[n]$ is the filter output error at time instant $n$. The value of this expectation would typically be something that isn't known ahead of time, so it's instead approximated (in most cases) by the instantaneous value $\mathbf{x}[n]e^*[n]$ instead. This <a href="https://en.wikipedia.org/wiki/Least_mean_squares_filter#Simplifications" rel="noreferrer">(described in more detail at Wikipedia)</a> is the key feature of the LMS filter structure.</p> <p>Gradient descent just refers to the method used to hunt for the minimum-cost solution; it doesn't force the use of any particular cost function. An LMS filter is a specialization of gradient descent that uses a mean-squared error cost function and the aforementioned approximation for the gradient at each time step.</p> <p><em>Stochastic gradient descent</em> would refer to techniques that don't directly compute the gradient, instead using an approximation to the gradient that has similar stochastic properties (e.g. the same expected value). LMS would be an example of an algorithm that uses a SGD approach, using the approximation I described above.</p>
https://dsp.stackexchange.com/questions/30605/whats-the-difference-between-lms-and-gradient-descent-adaptation
Question: <p>I am trying to implement an NLMS algorithm for a multi-input single-output(MISO) structure. </p> <p>We take a reference signal x, then we made a new set of P input signals from it as follows: x_op (k) = x(k)^p. k denotes the k-th sample of our reference signal x.</p> <p>For the case where P = 1, our adaptive filter is just a vector of length N. But for P > 1, we have a matrix H (N x P) containing all the adaptive filters. (where N is the length of each filter).</p> <p>Now I am confused as what would be dimenstion of the estimated output at each iteration (for each sample). For the case where P = 1, we can simply write:</p> <p>y_hat = h_hat' * xk; where xk has the last N samples of x. </p> <p>and y_hat is then a scalar. What about this case when H is a matric and not a vector anymore? </p> <p>The way I understand it, y_hat for this case is no longer a scalar. But if it's not a scalar, then how I am supposed to define the error for each sample k, in order to write the adaption law equation? </p> Answer: <p>I can provide you coding example, but it solves more generic problem than you posted. It is for general dynamic system that converts two inputs x(t), y(t) into single output z(t) and defined by Urysohn integral equation. Hammerstein is particular case of Urysohn and linear system is particular case of Hammerstein. The code and some explanation is here: <a href="http://ezcodesample.com/NAF/MISO.html" rel="nofollow noreferrer">http://ezcodesample.com/NAF/MISO.html</a> <a href="http://ezcodesample.com/NAF/Wiener.html" rel="nofollow noreferrer">http://ezcodesample.com/NAF/Wiener.html</a> <a href="http://ezcodesample.com/NAF/reallife2.html" rel="nofollow noreferrer">http://ezcodesample.com/NAF/reallife2.html</a></p> <p>And most generic case when dynamic system is an operator that converts fragment of input x(t) from t - T to t into scalar z(t) <a href="http://ezcodesample.com/NAF/kolmogorov.html" rel="nofollow noreferrer">http://ezcodesample.com/NAF/kolmogorov.html</a></p>
https://dsp.stackexchange.com/questions/55874/nlms-algorithm-for-a-miso-structure
Question: <p>I checked the literature for recent algorithms used to design a digital filter that is a minimax approximation of a desired frequency response. All the articles I found work out examples where all the poles have magnitude less than 0.92, or less that 0.89, etc. I havn't seen a published example with a pole having magnitude 0.95 and certainly not 0.9995. If a filter is implemented with double precision machine arithmetic, how close to the unit circle can a pole get to get a useful filter? Would it be a bad idea to have a pole with magnitude 0.95?</p> Answer: <p>It would most likely depend upon the order of the filter, but having a pole at position $z_p$ where $|z_p| = 0.95$ shouldn't pose a stability problem if you're using double-precision floating-point arithmetic with a filter of reasonable length.</p> <p>Since I don't know anything about your specific application, one other effect of the pole magnitude that might be relevant is the resulting filter's impulse response. Recall that poles in a system's transfer function correspond to decaying exponential terms in the system's impulse response. <a href="http://en.wikipedia.org/wiki/Z-transform#Table_of_common_Z-transform_pairs" rel="nofollow">As Wikipedia notes:</a></p> <p>$$ a^nu[n] \Leftrightarrow \frac{1}{1-az^{-1}} $$</p> <p>where $u[n]$ is the <a href="http://en.wikipedia.org/wiki/Heaviside_step#Discrete_form" rel="nofollow">discrete unit step function</a>, used here to express that the impulse response is causal ($0\ \forall\ n &lt; 0$). Therefore, if your filter has a pole at $z = a$, then there will be a corresponding $a^n$ term in the filter's impulse response. </p> <ul> <li><p>For small $|a|$, this term will decay out in a relatively small number of samples. As $|a| \rightarrow 1$, the amount of time (measured in samples) required for the exponential function to decay increases. </p></li> <li><p>When you reach the "critically stable" point of $|a| = 1$, the exponential never decays and the system impulse response does not decay to zero. </p></li> <li><p>If $|a| &gt; 1$ (i.e. the pole lies outside the unit circle), then the exponential function diverges and the impulse response blows up to infinity; this is why a discrete-time system is not <a href="http://en.wikipedia.org/wiki/Bibo_stability" rel="nofollow">BIBO stable</a> if it contains poles outside the unit circle.</p></li> </ul> <p>Given the above, the other concern that you might have is the overall effective time duration of the filter's impulse response. Although, as its name would suggest, an <a href="http://en.wikipedia.org/wiki/Iir_filter" rel="nofollow">IIR filter</a> theoretically has an impulse response of infinite length, in practice the response will usually decay to a negligible level after a finite time period. If your application is sensitive to this characteristic, then it makes sense to choose pole locations that are further from the unit circle. There will be corresponding tradeoffs in frequency-domain characteristics, as placing poles near the unit circle can help to make transition regions sharper and more narrow, as is often desirable.</p>
https://dsp.stackexchange.com/questions/3057/abspoles-1-by-what-margin-for-a-stable-filter
Question: <p><a href="http://freeverb3.sourceforge.net/iir_filter.shtml" rel="nofollow">A practical guide for digital IIR audio filters</a> has cookbook-style values for creating higher-order Bessel filters out of biquads, but the values listed aren't very precise:</p> <pre><code>You should multiply the Fc for each stage by the following coefficients: 1: 1.00 2: 1.27 3: 1.32 1.45 4: 1.60 1.43 5: 1.50 1.76 1.56 6: 1.90 1.69 1.60 The corresponding Q values are: 1: --- 2: 0.58 3: --- 0.69 4: 0.81 0.52 5: ---- 0.92 0.56 6: 1.02 0.61 0.51 </code></pre> <p>What are the expressions to calculate these values exactly?</p> <p>For the Butterworth table, <a href="http://www.dsprelated.com/showmessage/74598/1.php" rel="nofollow">the values are given by</a> <code>Q = 1/(2 * sin((pi / N) * (n + 1 / 2)))</code>, for instance. So where the table says <code>4: 0.54 1.31</code>, the equation gives 1.3065629648763766 and 0.54119610014619701. But I can't find the expression for Bessel filters, except that <code>2: 0.58</code> is $1\over\sqrt3$.</p> <p><a href="http://read.pudn.com/downloads48/sourcecode/math/163974/besselap.m__.htm" rel="nofollow">Prototype-generating</a> <a href="https://github.com/scipy/scipy/blob/master/scipy/signal/filter_design.py#L1509" rel="nofollow">functions</a> just have long tables of numbers, so maybe these are not easy to calculate? (Bessel functions?) If so, a listing of these Q and Fc values for the first several orders would be good.</p> <p>(And yes, I know the bilinear transformed Bessel <a href="http://www.dsprelated.com/showmessage/78866/1.php" rel="nofollow">is no longer linear-phase</a>. :/ I just want to know where these numbers are from.)</p> Answer: <p>There is no simple closed-form equation to calculate Bessel filter bi-quad coefficients. The poles of the filter come from a Bessel polynomial. Higher order Bessel polynomials are determined using a recursion relationship. You need computer algorithms to calculate the poles and resolve the bi-quad coefficients. </p> <p>Two books I can recommend: <a href="http://rads.stackoverflow.com/amzn/click/047182352X" rel="nofollow">“Passive and Active Filters” by Wai-Kai Chen</a> and <a href="http://rads.stackoverflow.com/amzn/click/0195107349" rel="nofollow">“Analog Filter Design” by M.E. Van Valkenburg</a>.</p>
https://dsp.stackexchange.com/questions/7830/bessel-filter-second-order-sections-q-and-fc-multiplier-derivation
Question: <p>Why is the least squares cost function used in adaptive noise cancellation with the recursive least squares (RLS) algorithm, but the mean squared error used in signal estimation? </p> <p>For an ergodic source (where time and ensemble averages should be the same) I would have thought the choice was arbitrary.</p> <p>From my notes: LMS minimises $\|e[n]\|^{2}$ and RLS minimises $\sum_{i=0}^{N} e^{2}[i], $ where $e[n]$ is the difference between the desired signal and the output of the filter.</p> Answer: <p>You are actually asking 2 separate questions. If I have interpreted your post correctly, they are:</p> <ol> <li>Why is the RLS used in Noise Cancellation, whereas the LMS is used in signal estimation?</li> <li>(If we assume that the signal is ergodic) Isn't minimising the Ensemble average, $E\{e_n^2 \}$, equivalent to minimising the time average, $ \sum_{i = 1}^{N}e_i^2$; i.e. Shouldn't the LMS perform as good as the RLS? </li> </ol> <p>Answers:</p> <p>Q1:</p> <p>You are free to choose <em>ANY</em> adaptive filtering algorithm for <em>ANY</em> application (e.g. Adaptive Noise Cancellation -ANC). It need not be the RLS. The same goes with signal estimation, or any other application you can think of. </p> <p>However, if you have a specific application in mind, and you know something about the system or how the algorithm performs in that setting, you may want to choose one adaptive algorithm over another. (E.g. If your application is to do with converging faster as opposed to having a low error at steady state, you might choose Algorithm X over Y) </p> <p>Once again, this choice is not made based on whether you minimize the mean squared error or the sum of the squared error. </p> <hr> <p>Q2:</p> <p>This questions still keeps me up on some nights. Fundamentally, Minimum Mean Squared Error based algorithms are based on, finding the system parameters which minimise the $ E\{ e_n^2 \}$. Now, the expected value of the error </p> <p>Both the LMS and the RLS are <strong><em>based</em></strong> on minimising this quantity. How they do it, however, is quite different. Remember, that the Expected value is statistical operator - it's the average over all realisations of the random signal. In real life applications, we only have access to one realisation of this signal. </p> <p><em>Example: Let's say you have the price of a stock, all you get is one value at each time (e.g. £10) The stock price never says, "oh well I have a 5% chance of being £10, on the other hand I could be £12, or £14.....etc". But I digress.</em></p> <p>SO, How are we going to minimize the mean squared error, when we can't compute the true mean? The Least Mean Square (Widrow-Hoff) says, "You know what, I am going to drop the $E\{.\}$ and minimise $e_n^2$. Yes it is a hack, but my god what a hack! </p> <p>The RLS uses the fact you mentioned: Since the process is ergodic, you can get the time average instead of the ensemble. The sum squared error is equivalent to the average of the squared error. The only thing that's missing is the $1/N$ term in the sum squared error. It is discarded because, it cancels out with another $1/N$ term in the derivation of the RLS. So don't worry. </p> <p>The interesting thing is how this difference affects the performance of the 2 filters. <em>(This is a whole different question and I suggest that you ask it here - it might get a lot of people interested)</em> The RLS is known to converge faster than the LMS. But when tracking time-varying parameters the LMS can perform better than the RLS in certain conditions. </p> <hr> <p>LMS: $$ E\{e_n^2 \} \approx e_n^2$$ RLS: $$ E\{e_n^2 \} \approx \frac{1}{N} \sum_{i =1}^N e_i^2$$</p> <p>To sum up: Both the RLS and LMS try to approximate $E\{e^2\}$. They way they do it is different - so the way they behave is different. And you are free to choose any filter for any application. </p>
https://dsp.stackexchange.com/questions/8165/choice-of-cost-function-in-adaptive-noise-cancellation
Question: <p>I am multiplying two sine waves with the same frequency (f), but might have a phase difference 0 &lt;-> 90 degrees. The product is a two frequency sinusoidal wave with f1 = f-f = DC and f2 = f+f = 2f. I now want to filter out the 2f component. I am currently sampling at Fs = 32 x f. I get a 40th order equiripple FIR filter in Matlab which is ok, but if I later am to increase the sampling rate to 64xf, 128xf etc the filter order gets very high.</p> <p>I assume however that f1 will not be 0 Hz exactly but somewhere close to 0 Hz. Over this region the ripple in the passband might be unwanted. Can the ripple change that much over such a narrow range? (within whatever limit one has set as the maximum ripple in the passband).</p> <p>I am using the Filter Design &amp; Analysis tool in Matlab and saw that it does not seem like an equiripple filter has any ripple close to DC (0&lt;->1Hz)? Is this correct? </p> <p>I need a filter that can attenuate the 2f component with 60dB and need as little computing power as possible. (working on a MCU without FPU using fixed-point).</p> <p>Is there any other filter that can do a better job than equiripple for what I described? I am open for other types of filters as IIR if someone can convince me of their advantages.</p> Answer: <p>You're correct; if the signal that you're applying to the input of the filter isn't exactly at DC (0 Hz), then you might see a slight difference in the amplitude of the output due to the filter's passband ripple. I would assert that for most applications, this is either imperceptible or negligible for typical values of passband ripple (1 dB or less). Are you sure that your application requires such insertion loss consistency?</p> <p>If you are sure, then there are some things you can do to mitigate the problem:</p> <ul> <li><p><strong>Design a better equiripple filter.</strong> If 1 dB of passband ripple is too much, try designing one that has 0.5 dB. If that's too much, think about 0.1 dB. You see where I'm going here. True, there will be some limit beyond which it will be difficult to generate a numerically-realizable filter that has little enough ripple, but again, I would expect that it's quite unlikely that your application is intolerant of 0.1 dB of passband ripple. Also, ratcheting down the allowed ripple is going to have a direct impact on the required filter order, possibly to the point where it's no longer feasible to implement given your system's constraints.</p></li> <li><p><strong>Don't use an equiripple filter.</strong> With your latest edit to the question, you state that your goal is to attenuate your $2f$ frequency component by a minimum of 60 dB with as little processing power as possible. In that case, this might be a good application for an <a href="http://en.wikipedia.org/wiki/Infinite_impulse_response">IIR filter</a>. Digital IIR filters are usually realized as approximations to one of a few standard classes of analog prototype filters. Specifically, for your application, you might look at a <a href="http://en.wikipedia.org/wiki/Butterworth_filter">Butterworth</a> or <a href="http://en.wikipedia.org/wiki/Chebyshev_filter">Chebyshev type II</a> structure. </p> <p>Both of these classes of filters offer no ripple across their passband, so they may be more amenable to your appilcation if you're picky about how much attenuation you see near DC. Plus, you can meet the same filter performance specifications (i.e. attenuate the unwanted component by at least 60 dB) with a much lower-order filter when compared to the equiripple FIR approach. If computational speed is a limiting factor in your system, this could be attractive.</p> <p>What do you give up with an IIR structure? FIR filters are nice because they are always BIBO stable. Plus, they are easier to implement robustly in finite-precision arithmetic (IIR implementations might need to use <a href="http://en.wikipedia.org/wiki/Noise_shaping">noise-shaping</a> techniques to mitigate the effects of quantization error that is fed back into the filter). Lastly, symmetric FIR filters offer <a href="http://en.wikipedia.org/wiki/Linear_phase">linear phase response</a>, which can be nice for some applications. </p> <p>Linear phase response means that for a sinusoidal input, the phase lag induced by the filter is equal to a constant time delay, no matter what the sinusoid frequency is. This can be useful if you care about the phase of the filter output with respect to some other unfiltered signal. While it is possible to design linear-phase IIR filters, in general they do not have this property.</p></li> </ul>
https://dsp.stackexchange.com/questions/10460/how-does-a-fir-equiripple-filter-behave-close-to-dc
Question: <p>I'm trying to get my dsp sea legs a bit, and am trying to complete a problem that asks for the mean delay and expected SNR boost for a given difference equation: y[n] = (x[n] + ... + x[n-N+1])/N</p> <p>I'd love some general guidance on how to learn more about how to address this. Specifically,</p> <ul> <li>I'd like to plot the filter function in octave/matlab, but am not sure how to get there from the difference equation. most of the examples I've come across assume that I have a frequency band to specify, but I'm not sure how I can derive that from just the difference equation.</li> <li>I'm not sure how to calculate the expected SNR boost in the absence of any info about the noise source. Is it possible to calculate some concept of the amount of 'smoothing' the filter is expected to provide, and consider that to be the reduction in noise between the input and the output?</li> </ul> <p>Thanks for any hints!</p> Answer: <p>I'll give you some hints to help you solve the problem by yourself. Looking at the input-output relation, you can see that the output signal is computed only from a combination of delayed input signal values, and not from delayed output signal values. So your impulse response has a finite length and the filter can be implemented by a non-recursive structure (FIR filter). Using the impulse response, you can write the input-output relation as a finite convolution sum</p> <p>$$y[n]=\sum_{k=0}^{N-1}x[n-k]h[k]\tag{1}$$</p> <p>Comparing (1) to your difference equation, you can easily see what the system's impulse response $h[n]$ is. Once you have the impulse response, you can compute the frequency response using an FFT. Plot its magnitude and phase to see how the filter behaves in the frequency domain.</p> <p>The (group) delay is the negative derivative of the filter's phase response. You will find that the phase is a linear function, so the delay is a constant. You just need to determine the slope of the phase (either analytically or by inspection of the phase plot).</p> <p>Without any further knowledge of your desired signal and the noise characteristics, you cannot say much about a possible SNR improvement.</p>
https://dsp.stackexchange.com/questions/15048/fir-filter-mean-delay-and-snr-from-difference-equation
Question: <p>As I understand it, FIR filtering is a linear process. That mean for me that the whole filtering process will have a fully predictable behavior. So, could someone explain why a universal deterministic and optimal filter design method to obtain the desired response doesn't exist and why recursive approach seems to be of great interest in practice ?</p> <p>EDIT: just to clarify, my question is about an "optimal" method, that is one which compute the shortest filter response while staying the closest to the design criteria.</p> Answer: <p>Sure, FIR filters are "simple" linear objects. But a typical FIR filter design task looks like this:</p> <blockquote> <p>Find a set of numbers (the filter coefficients) such that the magnitude of their Discrete Fourier Transform is as close as possible to a target response. "As close as possible" being defined as "by minimizing the $L_\infty$ norm of the difference between ideal and actual response over some frequency ranges".</p> </blockquote> <p>This is a non-linear, sometimes non-convex optimization problem and there is no universal, trivial procedure to solve those.</p> <p>We have to use procedures like the Parks-McClellan algorithm because the real-world engineering constraints we want to impose when designing FIR filters do not translate into simple linear or quadratic constraints. For example, a least-square error criterion (L2 norm often leads to more tractable procedures than other norms...) would not be an acceptable choice for engineering applications, because it could allow solutions that are close to the required response <strong>on average</strong>, but with an outlier value.</p>
https://dsp.stackexchange.com/questions/17198/why-are-recursives-methods-useful-for-fir-filter-design
Question: <p>I have a RLC circuit with transformation $$H(s) = \frac{R}{Ls+\frac{1}{Cs}+R}$$ and I know that by setting $s=j\omega$ I can obtain the frequency response of this system. What I don't understand is how I can use the frequency response graph to decide which values I should set on R and f $(L=2\pi f, C=1\mu F)$ to filter out a specific frequency from the input signal $u(t)$.</p> <p>Lets say that I have u(t) which I know consists of two signals, $400 Hz$ and $800 Hz$ (by calculating the amplitude spectrum $U(\omega)$ and plotting the graph). How do I design a filter to filter out one of them?</p> Answer:
https://dsp.stackexchange.com/questions/18829/which-values-do-i-use-to-filter-a-specific-frequency-with-an-rlc-circuit
Question: <p>Why a filter of the form </p> <p>$$ 1+a_0 z^{-1} +a_1 z^{-2}+ a_2 z^{-3} $$ has the same amplitude response when in the reversed form $$ a_2+a_1 z^{-1} +a_0 z^{-2}+z^{-3} $$ but the phase response is different. I don't get it, and can't understand what the differences in terms of the relative group delays mean.</p> Answer: <p>If you have a causal length $N$ FIR filter with impulse response $h[n]$, and with frequency response $H(e^{j\omega})$, and you invert it on the time axis, you get a new filter</p> <p>$$g[n]=h[-n]\tag{1}$$</p> <p>This filter is non-causal, but since it is an FIR filter, it can be made causal by shifting it to the left by $N-1$ samples:</p> <p>$$f[n]=g[n-(N-1)]=h[N-1-n]\tag{2}$$</p> <p>This is what you're doing. Now since</p> <p>$$H(e^{j\omega})=\sum_{n=-\infty}^{\infty}h[n]e^{-jn\omega}\tag{3}$$</p> <p>you have</p> <p>$$G(e^{j\omega})=\sum_{n=-\infty}^{\infty}h[-n]e^{-jn\omega}=\sum_{n=-\infty}^{\infty}h[n]e^{jn\omega}=H(e^{-j\omega})$$</p> <p>and</p> <p>$$F(e^{j\omega})=G(e^{j\omega})e^{-j(N-1)\omega}=H(e^{-j\omega})e^{-j(N-1)\omega}$$</p> <p>From (3) you can see that for real-valued $h[n]$ you have $H(e^{-j\omega})=H^*(e^{j\omega})$ (where $*$ denotes complex conjugation). So you finally get</p> <p>$$F(e^{j\omega})=H^*(e^{j\omega})e^{-j(N-1)\omega}\tag{4}$$</p> <p>and since $|e^{-j(N-1)\omega}|=1$, and $|H^*(e^{j\omega})|=|H(e^{j\omega})|$ you have</p> <p>$$|F(e^{j\omega})|=|H(e^{j\omega})|\tag{5}$$</p> <p>So the magnitude responses of the original filter and the time-reversed filter are identical. The phase responses are different: from (4) you have</p> <p>$$|F(e^{j\omega})|e^{j\phi_F(\omega)}=|H(e^{j\omega})|e^{-j\phi_H(\omega)}e^{-j(N-1)\omega}\tag{6}$$</p> <p>from which</p> <p>$$\phi_F(\omega)=-\phi_H(\omega)-(N-1)\omega\tag{7}$$</p> <p>follows. Since the group delay is the negative derivative of the phase, the group delays are related by</p> <p>$$\tau_F(\omega)=-\tau_H(\omega)+N-1\tag{8}$$</p>
https://dsp.stackexchange.com/questions/22728/why-this-two-fir-filters-have-the-same-amplitude-but-different-phase-response
Question: <p>I would like to be able to implement an All-Pass filter with a frequency-dependent group delay. I need a maximum group delay at low frequency of about 20 samples (for F<em>s</em> = 44.1kHz), and it needs to fall to zero(-ish) at the Nyquist frequency. Ideally, I would like to specify a corner frequency and a rate at which the delay falls off either side of it. How the heck would I design such a thing?</p> <p>I'm afraid I'm not sufficiently competent to follow the design approaches I can find on the web that plunge straight into poles, zeros, transfer functions and complex conjugates. What I can do, though, is implement the darned thing efficiently in code once it is designed.</p> <p>I am able to use Matlab to design FIR and IIR low-pass filters, because it has a built-in tool that spits them out. But it doesn't have an All-Pass filter design tool (at least not one I can find).</p> Answer: <p>This is an excerpt from the FilterScript user's guide, which should provide you with enough information on how to design the filter. Please refer to the other product resources on <a href="http://www.advsolned.com/asn_filter_designer.html" rel="nofollow noreferrer">the tool's homepage for more information.</a></p> <p><a href="https://i.sstatic.net/60XUp.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/60XUp.jpg" alt="FilterScript code for a second order all-pass filter"></a></p>
https://dsp.stackexchange.com/questions/24031/any-simple-digital-all-pass-filter-design-tools
Question: <p>Have been trying to design IIR and FIR 60Hz notch filters but all have step response way above 10ms. </p> Answer: <p>You can trade off steepness of the notch against time domain ringing. That's a fundamental trade off and there is no way around it. When using an IIR notch you can simply adjust the "Q" (quality factor). A Q of 3 will give a step response that's roughly 10ms long. </p>
https://dsp.stackexchange.com/questions/26161/is-it-possible-to-design-a-digital-filter-that-rejects-60hz-noise-while-keeping
Question: <p>FIR filter coefficients are known. Then what is the matlab code or function that is used to determine the corresponding farrow structure coefficients? </p> Answer: <p>There is no standard way to determine the coefficients of the Farrow structure for a given FIR filter. The Farrow structure is an implementation of a whole class of FIR filters with transfer function(s) $H_{\mu}(z)$ with a continuous control parameter $\mu$. Often this parameter $\mu$ determines a fractional delay, but it could as well be any other adjustable filter property.</p> <p>The transfer function $H_{\mu}(z)$ of the Farrow structure is given by</p> <p>$$H_{\mu}(z)=\sum_{k=0}^{K-1}C_k(z)\mu^k\tag{1}$$</p> <p>where $C_k(z)$ are FIR transfer functions. From $(1)$, the impulse response is</p> <p>$$h_{\mu}[n]=\sum_{k=0}^{K-1}c_k[n]\mu^k\tag{2}$$</p> <p>So each filter coefficient (of the corresponding transversal filter structure) $h_{\mu}[n]$ is implemented as a weighted sum of coefficients $c_k[n]$. This is why there is no one-to-one mapping from given FIR filter coefficients to the coefficients of the Farrow structure.</p> <p>You need to specify which filter property the parameter $\mu$ is supposed to control, and then you need to design the coefficients $c_k[n]$ of the Farrow structure accordingly.</p>
https://dsp.stackexchange.com/questions/27094/how-to-find-out-the-farrow-coefficients-if-fir-coefficients-are-given
Question: <p>I have a 10 bit ADC sample stream in which I would like to apply a digital band pass filter. Is there a theoretical filter tap count that would define the threshold of "usefulness"? </p> <p>I guess my thought process is: There are only 10 bits, so at some point (via increasing the tap count) the attenuation will be so great that even a maximum amplitude frequency component will get attenuated down to a fraction of a bit, and rounded down to 0. At that point, the effects of additional taps could not be seen. </p> Answer: <p>Since you can widen your bit width with each operation, no, there's no such maximum useful width.</p> <p>Take GPS receivers as an example: many of them <sup>citation needed</sup> use 2 bit ADCs and yet are useful, because the signal, already hidden in noise before it reaches the ADC, only gets "visible" by massive processing gain.</p> <p>A typical step with massive processing gain would be a very sharp digital filter. Those can get very long. </p> <p>There's a lot of experienced audio and video folks on here. They can tell you much more about the astronomical lengths high-quality filters can get.</p>
https://dsp.stackexchange.com/questions/37314/max-useful-filter-tap-count-for-given-fixed-point-bitwidth
Question: <p>hi i'm going to design a low pass FIR filter for an EEG signal for the detection of eppileptic siezure and i want to know what is the suitable design Method to the filter? i need this FIR filter just to smooth the signal to use it for discret wavelet transform. thanks</p> Answer: <p>For a quick filter design without getting into trouble, I recommend avoiding any IIR structure and design an FIR using either least squares (firls in matlab) or Parks McClellan (firpm in matlab, remez in octave). There are plenty of answers here on how many taps you will need, (such as <a href="https://dsp.stackexchange.com/questions/31066/how-many-taps-does-an-fir-filter-need/31210#31210">How many taps does an FIR filter need?</a>) so you start with that for initial guidance and then refer to the specific help for firpm or firls for further design details using those tools. </p> <p>Below is a slide I have on my typical design path for simple linear phase FIR filters. Starting with the specifications I estimate the number of taps, and then use that estimate to come up with (floating point) coefficients. I then confirm (using freqz in Matlab, Octave or Python typically) passband and stopband performance and adjust number of taps accordingly. Once the number of coefficients and values is settled, I then map to a fixed point implementation if needed using the guidance further given below and again confirm performance specifications. For final verification, especially if I have gone to fixed point, I do actual SNR testing with test waveforms through the filter at the maximum and minimum signal levels I would expect in my application using test waveforms. This is a good way to confirm that there are no disastrous overflow conditions or poor assumptions on quantization levels needed to maintain a target SNR directly at a component level test. </p> <p><a href="https://i.sstatic.net/xW3oR.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xW3oR.png" alt="enter image description here"></a></p> <p><strong>Design Tools:</strong> </p> <p>Matlab: firpm, firls</p> <p>Octave: remez, firls</p> <p>Python: scipy.signal remez, firls</p> <p>Online Tools: </p> <p>Equiripple (Parks-McClellan): <a href="http://cnx.org/content/m12799/latest/" rel="nofollow noreferrer">http://cnx.org/content/m12799/latest/</a></p> <p>Least squares: <a href="http://cnx.org/content/m10577/latest/" rel="nofollow noreferrer">http://cnx.org/content/m10577/latest/</a></p> <p><strong>Other tips:</strong></p> <p>Scale the output, let the filter grow the signal! I think it was fred harris that had the view of analog filters attenuating signals out of band while digital signals grow the signal in band. I found that very insightful. To adjust the output level, scale after the filter; don't be tempted to adjust the output by scaling the input or scaling your coefficients (as it degrades SNR, output noise is accumulated noise from every tap and scaling coefficients increases their own individual error terms), beyond scaling to the proper precision setting as suggested below. This is the reason for "extended precision accumulators"; they let the accumulated value from every tap grow and then once accumulated truncate the output in one location. </p> <p>Coefficient bit width: A reasonable rule of thumb is to use at least 2 more bits for your coefficients than your datapath width if your datapath was sized based on SNR (or 2 more bits than your SNR requirement directly if your datapath is much wider than necessary). </p> <p>You can also size the coefficient width based on your rejection requirement using 6 dB/bit (if you need a filter with 60 dB rejection, use 12 bits for your coefficients, with the coefficients scaled to fill that precision of course). Typically actual rejection achieved if limited by coefficient bit width is on the order of 5 to 6 dB / bit; I like to add at least the extra 2 bits for margin unless my design is severely resource constrained in that area.</p> <p>Least Squares vs Parks McClellan (equiripple): In most of my design applications related to communications I have been more concerned with overall signal and noise than an absolute limit at any one given frequency, so typically use the Least Squares design method. That is the distinction between the two design choices (LS or P-McC) explained simply: Least Squares will minimize the error in a least squares sense, while Park McClellan minimizes the absolute error. Given the same number of taps, the total noise due to pass-band ripple and finite out of band rejection will be less with the Least Squares design approach when integrated over the entire waveform in time or over all frequencies, while the peak error at specific locations in time or frequency can be worst. </p>
https://dsp.stackexchange.com/questions/38620/what-is-the-suitable-design-method-to-the-filter
Question: <p>Please tell me, why low-pass FIR Equiripple filters are designed with 3 dB of ripple in the pass-band and at least 60 dB of attenuation in the stop-band and not other values ? I want to know are these values simply a convention?</p> Answer: <p>Stop band attenuation is a good thing right? After all it's the primary reason why you want a frequency selective filter: stop the unwanted frequencies. So a 60dB attenuation in the stop band of a filter is considered to be the norm in many typical applications. But not always so, as the comments indicate; you must always refer to your application requirements for determining how much attenuation is enough (or necessary) for your case.</p> <p>That being said, there exist <strong>tradeoffs</strong> in filter design, just like in many other design procedures. And the most fundamental of those tradeoff parameters, for digital FIR filter design, are namely the passband ripple, stopband attenuation, transition band width and the resulting filter's length.</p> <p>Among these parameters transition band width and stop band attenuation affects the <strong>selectivity</strong> quality of your filter. But a short transition band with a large stop band attenuation means a (very) high order (long impulse response) FIR filter, which creates opposition due to computational burden. </p> <p>To overcome this computational burden, due to narrow transition band, once can consider <strong>relaxing</strong> the filter's definition in, for example, the pass-band region, so that instead of a monotonic or an un-equal ripple filter, you distribute the ripples equally by allowing as large as possible but fixed amplitude ripples in every where through the passband, so that the FIR filter length will be kept short enough.</p> <p>3dB passband ripple can be considered a reasonable choice for some applications in which pass band <strong>distortions</strong> due to those ripples may be tolerable.</p>
https://dsp.stackexchange.com/questions/38759/why-low-pass-fir-equiripple-filter-is-designed-with-3-db-of-ripple-in-the-pass-b
Question: <p>I was studying about realization structures of digital filters. Is it mandatory to have the order of numerator must be less than that of denominator of transfer function for realization of filter using direct form I and II?</p> Answer: <p>no. but, for a <strong>causal</strong> LTI digital filter with a rational transfer function, it is necessary that the number of zeros, $M$, not exceed the number of poles, $N$.</p> <p>$$\begin{align} \\ H(z) \triangleq \frac{Y(z)}{X(z)} &amp; = H_0 \frac{(z-q_1)(z-q_2)(z-q_3)...(z-q_M)}{(z-p_1)(z-p_2)(z-p_3)...(z-p_N)} \\ \\ &amp; = H_0 \frac{z^M (1-q_1 z^{-1})(1-q_2 z^{-1})(1-q_3 z^{-1})...(1-q_M z^{-1})}{z^N (1-p_1 z^{-1})(1-p_2 z^{-1})(1-p_3 z^{-1})...(1-p_N z^{-1})} \\ \\ &amp; = z^{M-N} \ \frac{H_0 \ (1-q_1 z^{-1})(1-q_2 z^{-1})(1-q_3 z^{-1})...(1-q_M z^{-1})}{(1-p_1 z^{-1})(1-p_2 z^{-1})(1-p_3 z^{-1})...(1-p_N z^{-1})} \\ \\ &amp; = z^{M-N} \ \frac{b_0 + b_1 z^{-1} + b_2 z^{-2} + b_3 z^{-3} + ... + b_M z^{-M} }{ 1 + a_1 z^{-1} + a_2 z^{-2} + a_3 z^{-3} + ... + + a_N z^{-N} } \end{align}$$</p> <p>this gets manipulated:</p> <p>$$\begin{align} Y(z) &amp; \left( 1 + a_1 z^{-1} + a_2 z^{-2} + ... + a_N z^{-N} \right) \\ &amp; \quad = X(z) z^{M-N} \left( b_0 + b_1 z^{-1} + b_2 z^{-2} + ... + b_M z^{-M} \right) \end{align}$$</p> <p>or</p> <p>$$\begin{align} Y(z) = \ &amp; b_0 z^{M-N} X(z) + b_1 z^{M-N-1} X(z) + b_2 z^{M-N-2} X(z) + ... \\ &amp; \quad ... + b_M z^{-N} X(z) - a_1 z^{-1}Y(z) - a_2 z^{-2}Y(z) - ... - a_N z^{-N}Y(z) \end{align}$$</p> <p>inverting the Z Transform, this becomes </p> <p>$$\begin{align} y[n] = \ &amp; b_0 \ x[n+M-N] + b_1 \ x[n+M-N-1] + b_2 \ x[n+M-N-2] + ... \\ &amp; \quad ... + b_M \ x[n-N] - a_1 \ y[n-1] - a_2 \ y[n-2] - ... - a_N \ y[n-N] \end{align}$$</p> <p>for a <strong>causal</strong> system or filter, we cannot look into the future for any input sample $x[n]$. that means $M \le N$ so that there is no negative delay on the $x[n+M-N]$ term. a negative delay means the LTI filter is peeking into the future, which is not causal.</p> <p>but if you remove that leading delay factor and have this:</p> <p>$$ H(z) = \frac{b_0 + b_1 z^{-1} + b_2 z^{-2} + b_3 z^{-3} + ... + b_M z^{-M} }{ 1 + a_1 z^{-1} + a_2 z^{-2} + a_3 z^{-3} + ... + + a_N z^{-N} } $$</p> <p>there is no reason that $M$ cannot be larger than $N$. but the number of poles will still be as large as $M$. if $M&gt;N$, then some of the poles will have to be at the origin $z=0$. in fact, if $N=0$, then you have an FIR filter and <strong>all</strong> of the poles are at the origin.</p>
https://dsp.stackexchange.com/questions/46046/direct-form-i-and-direct-form-ii
Question: <p>I try to understand the 'arbitrary' what does it meant? I had read many references ,such a one it is 'begin the process with a transfer function of your choice' ,in other reference :related by the starting point,</p> <p>In other hand i read about Chebyshev approximation with arbitrary magnitude, how can i find the better design with arbitrary magnitude ? any method of design have a criteria ,the 'arbitrary' related by the method of design or related by the transfer function?</p> Answer: <p>The term "arbitrary" in this context refers to the desired frequency response, and what it means is that the respective design method accepts any desired response. So unlike required by many standard design routines, the magnitude response does not need to be piecewise constant or linear, and, more importantly, the phase response need not be linear or minimum-phase. The corresponding design problem is a complex approximation problem because the desired frequency response which must be approximated is a complex-valued function. </p>
https://dsp.stackexchange.com/questions/51111/what-is-meant-by-arbitrary-in-the-context-of-digital-filter-design
Question: <p>In the window method for filter design it is explained that we do an ideal filter and then we pass it to time domain, but it will be time limited and then...</p> <p>Why don't we filter directly in the frequency domain?</p> Answer:
https://dsp.stackexchange.com/questions/56586/fir-filter-window-method
Question: <p>What are the uses of ripples in the filter design. We try to design a filter with least ripples but sometimes we design a filter to have 2 or 3 ripples. Why is it so? </p> Answer: <p>Ripples are usually an undesired side effect. E.g., when designing a frequency selective filter you normally want a piecewise constant magnitude of the frequency response, but this is physically impossible.</p> <p>Certain design criteria result in filters without ripples, such as the Butterworth criterion, which results in filters with a maximally flat response.</p>
https://dsp.stackexchange.com/questions/60113/ripples-in-filter
Question: <p>I'm trying to write an accelerometer calibration script that uses filters to convert from volts into <span class="math-container">$m/s^2$</span>. As accelerometers tend to have non-flat response curves, this means I have to design a rather complex filter. I'm not worried about phase, as I can just apply the filter twice in opposing directions to correct for any phase offsets (like matlab's <code>filtfilt</code>), so the focus is on designing a filter that approximates a user-provided magnitude curve.</p> <p>Ideally, the user provides a calibration curve as input into an analytic algorithm to solve for the best fitting filter poles.</p> <p>I'm aware MATLAB has a filter design function, but I don't know what the underlying algorithm is (if its an optimizer, or a closed form solution).</p> <p>So my question is...</p> <ul> <li>Is there an analytic solution to my filter design problem? Or do I have to use optimisation scripts to get the best filter?</li> </ul> <p>I'm not mentioning programming language here, as I want to understand the underlying math behind this.</p> Answer: <p>If you are not concerned on the phase and just want to approximate a magnitude response, then your first option should be the <strong>frequency sampling</strong> method implemented in Matlab/Octave fir2() function.</p> <p>You would provide the frequency grid and corresponding frequency response magnitude at those frequencies.</p> <p>As you have also mentioned, least-squares approach is another alternative. Indeed by using suitable weights, you can distribute the error according to your priority cirteria.</p> <p>Magnitude approximation based on LMS adaptive system identification is also a possible option. </p>
https://dsp.stackexchange.com/questions/64858/analytic-solution-for-non-flat-filter-design
Question: <p>I am trying to go from a time-domain description of a filter, via frequency domain, generating a filter based on that frequency domain description, then seeing how far from the original I end up.</p> <pre><code>L = 10-1; h = zeros(L+1,1); h(2) = 1; L2 = 1024-1; H = fft(h, L2+1); H1 = H(1:(L2/2+2)); W = 2*pi*(0:(L2+1)/2)/(L2+1); n = 6; m = 2; [b,a] = invfreqz(H1,W,n,m); ir_in = impz(h); ir_out = impz(b,a); [H2,W2] = freqz(b, a); </code></pre> <p>For a simple input like this, I get a warning about singular or badly scaled matrix, and the solution (as viewed in the filter time domain) is quite different from the original:</p> <pre><code>b = 0.0000 1.0000 -1.4219 0.2578 -0.0000 0.0000 0.0000 a = 1.0000 -1.4219 0.2578 </code></pre> <p>The frequency magnitude and phase response of the new filter looks great, but the numerical properties not so much.</p> <p>I realize that setting m = 2 is kind of silly in this example, but having an automated and generic process would have been nice.</p> Answer: <p>The warning is due to modeling a unit delay which has wide (constant) frequency response thus will have very large number differences (ill conditioned matrices) in the translation between domains and looking for an IIR solution to the FIR problem (note that the algorithm converges to a trivial but valid solution where the denominator coefficients match the numerator-- if the OP set <span class="math-container">$m$</span> to be larger, the algorithm will converge to populate those coefficients as well in the numerator). The recommended approach is to start with FIR only, and only introduce IIR if needed. Regardless the result does match the expected very well in both time and frequency as plotted below after running the OP's code:</p> <p><strong>Frequency Response</strong></p> <p><a href="https://i.sstatic.net/SEZ4P.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/SEZ4P.png" alt="Frequency Response"></a></p> <p><strong>Impulse Response</strong></p> <p><a href="https://i.sstatic.net/vVdQV.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/vVdQV.png" alt="Time Response"></a></p> <p>The above is the IIR equivalent to the OP's FIR target given <span class="math-container">$m=2$</span> in the call to invfreqz, which would then converge to an IIR solution. To force an FIR solution, set <span class="math-container">$m=0$</span> which results in the following for this case:</p> <p>b = 0 1 0 0 0 0 0 <br> a = 1 <br></p> <p>(Note the zeros for b were actually +/-3e-17 or lower) </p> <p>This is a useful approach for fitting to a precise frequency response curve. For general lowpass, bandpass and multiband filter design, I prefer to use the least squares <code>firls()</code> function with simple targets of 1 and 0 for the passbands and stopbands. However if a more elaborate response is desired (in a curve fitting sense), this is the approach I would take:</p> <p>Start with a very large <span class="math-container">$n$</span> and <span class="math-container">$m=0$</span> and run <code>invfreqz()</code> to evaluate the resulting impulse response (b coefficients). Assuming the impulse response converges sufficiently to what can be assumed 0 (finite) at the start and end of the filter (evaluate in dB scale as small values can have a significant impact), reduce <span class="math-container">$n$</span> to this length and rerun <code>invfrewqz</code>. Evaluate the frequency response using <code>freqz</code> and increase <span class="math-container">$n$</span> if needed to meet target (or reduce <span class="math-container">$n$</span> until desired maximum error is reached). The result of this is the best FIR only solution that can be achieved. Given the coefficients of the FIR filter is the impulse response, any filter with an impulse response that converges to zero can be realized as an FIR only filter, but implementing as an IIR can reduce the total number of coefficients needed (with all the cost of IIR implementation such as possible instability, round-off error accumulation, dead-beat responses, etc). </p> <p>If the number of elements in the FIR is unacceptably long such that an IIR solution is desired, increase <span class="math-container">$m$</span> and repeat which will result in a smaller <span class="math-container">$n$</span> and an IIR solution. (Make <span class="math-container">$m$</span> excessively long to start and evaluate b and a on a log scale to determine the number of significant coefficients). If using an IIR solution, it is recommended to then factor the resulting solution into 2nd order sections to minimize round-off errors that can accumulate significantly in higher order IIR filters. (Resulting in 2nd order biquad filters). </p>
https://dsp.stackexchange.com/questions/68166/invfreqz-and-frequency-domain-filter-specification
Question: <p>For the second order Lynn's low pass filter, the general form of the transfer function is: <span class="math-container">$$ H(z)=\frac{(1−z^{-m})^2}{ (1−z^{-1})^2 } $$</span> where <span class="math-container">$m$</span> is a positive integer. The gain for this is <span class="math-container">$m^2$</span>, time delay is <span class="math-container">$m-1$</span> samples and the nominal frequency corresponding to the location of the lowest frequency zero is <span class="math-container">$f_l = f_s /m$</span>. The frequency response is given by: <span class="math-container">$$ |H(e^{j\omega T})|=\frac{\sin^2(m\omega /2f_s)}{\sin^2(\omega /2f_s)} $$</span> At the 3 dB cutoff frequency, for unit gain we have: <span class="math-container">$$ |H(e^{j\omega_c T})|=\frac{\sin^2(m\omega_c /2f_s)}{m^2\sin^2(\omega_c /2f_s)} \\ \therefore \frac{1}{\sqrt2}=\frac{\sin^2(m\pi f_c /f_s)}{m^2\sin^2(\pi f_c /f_s)} $$</span></p> <p>Now, to design the filter for our required cutoff frequency <span class="math-container">$f_c$</span> and sampling frequency <span class="math-container">$f_s$</span>, we need to find the value of <span class="math-container">$m$</span> corresponding to these inputs. So how can we get this equation to the form <span class="math-container">$m = f(f_c, f_s)$</span>, so that we can avoid getting the <span class="math-container">$m$</span> value by trial-and-error or numerical methods? Or is there some other quick approximation formula that we can use?</p> Answer: <p>Meanwhile, we have got an approximation solution for this. Consider the equation: <span class="math-container">$$ \frac{1}{\sqrt2}=\frac{\sin^2(m\pi f_c /f_s)}{m^2\sin^2(\pi f_c /f_s)} $$</span></p> <p>In the right-hand side denominator, since <span class="math-container">$f_c &lt;&lt; f_s$</span>, we can write: <span class="math-container">$$sin(\pi f_c /f_s) \simeq \pi f_c /f_s$$</span> Also, in the numerator, since <span class="math-container">$f_l = f_s/m$</span>, we have <span class="math-container">$m\pi f_c /f_s = \pi f_c /f_l$</span>. Now, since <span class="math-container">$f_c &lt; f_l$</span>, we see that <span class="math-container">$0 &lt; \pi f_c /f_l &lt; \pi$</span>. This means we can use <a href="https://math.stackexchange.com/questions/976462/a-1-400-years-old-approximation-to-the-sine-function-by-mahabhaskariya-of-bhaska">Bhaskara I's sine approximation formula</a> and write: <span class="math-container">$$sin(m\pi f_c /f_s) \simeq \frac{16 (\pi -(m\pi f_c /f_s)) (m\pi f_c /f_s)}{5 \pi ^2-4 (\pi -(m\pi f_c /f_s)) (m\pi f_c /f_s)}\qquad $$</span> Plugging these back into the main equation, simplifying and solving the resulting quadratic equation for <span class="math-container">$m$</span>, we get: <span class="math-container">$$ m \simeq 0.3f_s/f_c$$</span> This gives quite accurate results. For example, if we need to design the filter for a sampling frequency of 200 Hz and cutoff frequency of 15 Hz, we get <span class="math-container">$m$</span> as 4. This gives us <span class="math-container">$|H(e^{j\omega_c T})|= 0.75$</span></p>
https://dsp.stackexchange.com/questions/73983/formula-for-designing-lynns-low-pass-filter
Question: <p>Where to learn about "analog prototype filters"?</p> <p>I've heard about them, but I'm unsure about what they really are and how they're constructed.</p> Answer: <p>"Analog prototype" filters are well-known analog filters that have specific desirable properties. They include (but aren't limited to):</p> <ul> <li><a href="https://en.wikipedia.org/wiki/Butterworth_filter" rel="nofollow noreferrer">Butterworth filters</a>: maximally-flat passband response</li> <li><a href="https://en.wikipedia.org/wiki/Chebyshev_filter" rel="nofollow noreferrer">Chebyshev filters</a>: sharper rolloff than Butterworth, equiripple in either the passband or stopband</li> <li><a href="https://en.wikipedia.org/wiki/Elliptic_filter" rel="nofollow noreferrer">Elliptic filters</a>: even sharper rolloff, equiripple in passband and stopband</li> <li><a href="https://en.wikipedia.org/wiki/Bessel_filter" rel="nofollow noreferrer">Bessel filters</a>: maximally-flat group delay</li> </ul> <p>These prototypes can be used to design digital filters that have approximately the same characteristics, for instance by using the <a href="https://en.wikipedia.org/wiki/Bilinear_transform" rel="nofollow noreferrer">bilinear transform</a>.</p>
https://dsp.stackexchange.com/questions/51277/where-to-learn-about-analog-prototype-filters
Question: <p>I have built a resonance filter using the code from <a href="https://wiki.multimedia.cx/index.php/Impulse_Tracker#IT214_sample_compression" rel="nofollow noreferrer">here</a> I would like to know what the construction of this filter is. I believe it is an IIR and that it is probably a second order/two pole filter but that is as far as my knowledge goes.</p> <p>My Code:</p> <pre><code>public class ItFilter implements ISimpleFilter { // static resonance table public static final float[] RESONANCE_TABLE = {//removed for simplicity}; // instance variables private double cutoffFrequency; private byte resonance; private double sampleRate; private double valueZero; private double valueOne; private double cutoffAmount; private double resonanceAmount; private double a, b, c, d, e; private boolean highPass; private double highPassValue; // constructor public ItFilter(double cutoffFrequency, double sampleRate, byte resonance, boolean highPass) { this.cutoffFrequency = cutoffFrequency; if (this.cutoffFrequency &gt; sampleRate / 2) { this.cutoffFrequency = sampleRate / 2; } this.cutoffFrequency = cutoffFrequency; this.sampleRate = sampleRate; this.resonance = resonance; this.highPass = highPass; cutoffAmount = 2.0 * Math.PI * this.cutoffFrequency / this.sampleRate; resonanceAmount = RESONANCE_TABLE[this.resonance]; d = resonanceAmount * cutoffAmount + resonanceAmount - 1.0; e = cutoffAmount * cutoffAmount; a = 1.0 / (1.0 + d + e); if (highPass) { a = 1.0 - a; } b = (d + 2 * e) / (1.0 + d + e); c = (-e) / (1.0 + d + e); highPassValue = (highPass) ? 1.0 : 0; valueZero = 0; valueOne = 0; } // setters @Override public void setCutoff(double cutoffFrequency) { this.cutoffFrequency = cutoffFrequency; if (this.cutoffFrequency &gt; sampleRate / 2) { this.cutoffFrequency = sampleRate / 2; } cutoffAmount = sampleRate / (2.0 * Math.PI * this.cutoffFrequency); d = resonanceAmount * cutoffAmount + resonanceAmount - 1.0; e = cutoffAmount * cutoffAmount; a = 1.0 / (1.0 + d + e); if (highPass) { a = 1.0 - a; } b = (d + 2 * e) / (1.0 + d + e); c = (-e) / (1.0 + d + e); } // low pass filter @Override public double filter(double point) { double filteredValue, returnValue; filteredValue = a * point + b * valueZero + c * valueOne; // normalise filteredValue filteredValue = (filteredValue &gt; 1) ? 1 : filteredValue; filteredValue = (filteredValue &lt; -1) ? -1 : filteredValue; valueOne = valueZero; valueZero = filteredValue - (point * highPassValue); returnValue = filteredValue; return returnValue; } } <span class="math-container">```</span> </code></pre> Answer: <p>This beginning of this answer is a reformatting of <a href="https://wiki.multimedia.cx/index.php/Impulse_Tracker#IT214_sample_compression" rel="nofollow noreferrer">Resonant filters</a>.</p> <p><span class="math-container">$$K[n] = aS[n] + bK[n-1] + cK[n-2]$$</span></p> <p>where:</p> <p><span class="math-container">$K[n]$</span> is the output value at time n<br/> <span class="math-container">$S[n]$</span> is the input value at time n<br/></p> <p><span class="math-container">$a = \frac{1}{1+d+e}$</span><br/> <span class="math-container">$b = \frac{d+2e}{1+d+e}$</span><br/> <span class="math-container">$c = -\frac{e}{1+d+e}$</span><br/></p> <p><span class="math-container">$d = 2pr+2p-1$</span><br/> <span class="math-container">$e = r^2$</span></p> <p><span class="math-container">$r = \text{playback_frequency} \frac{2.0\cdot\pi\cdot110.0\cdot(2.0^{0.25})}{2^{\text{cutoff}/24.0}}$</span><br/> <span class="math-container">$p = 10^{(-\text{resonance}\cdot24.0)/(128.0\cdot20.0)}$</span></p> <p>The z-transform of the filter is: <span class="math-container">$$K(z) = aS(z) + bK(z)z^{-1} + cK(z)z^{-2}$$</span></p> <p>Yielding the transfer function: <span class="math-container">$$K(z) - bK(z)z^{-1} - cK(z)z^{-2} = aS(z)$$</span> <span class="math-container">$$K(z)\frac{1}{a}\left[1 - bz^{-1} - cz^{-2}\right] = S(z)$$</span> <span class="math-container">$$H(z) = \frac{K(z)}{S(z)} = \frac{1}{\frac{1}{a}\left[1 - bz^{-1} - cz^{-2}\right]} = \frac{a}{1 - bz^{-1} - cz^{-2}}$$</span></p> <p>This is indeed a 2-pole, second order filter, infinite impulse response (IIR) filter. The specifics of its filtering characteristics will be dependent on the other input paramaters.</p>
https://dsp.stackexchange.com/questions/75884/what-is-the-construction-of-this-filter
Question: <p>I'm looking for an algorithm to detect the slew rate of a 50Hz discrete input signal sampled at 400Hz. I'm doing the obvious - so a low-pass filter on <em>(sample - prev_sample) / deltaT</em> but this results in an oscillating output. I think this is because often the input is zero because <em>sample == prev_sample</em> and then you get this step input followed by zero again. What I need is a way of producing a smooth output that reacts quickly to large changes in input but doesn't ring when the input changes are small. I feel like I am missing some obvious reference here so if someone could set me straight that would be great!</p> Answer:
https://dsp.stackexchange.com/questions/83243/digital-slew-detection
Question: <p>I'd like to implement freuqency sampling method for linear phase FIR filter design using IDFT transform.</p> <p>My procedure goes like this :</p> <ol> <li>determine desired magnitude response value in frequency points</li> <li>I add linear phase response function with group delay (N-1)/2 to get complex frequency response values and equidistant points in frequency</li> <li>use IDFT to calculate system's impulse response.</li> </ol> <p>This approach works for odd-length FIR filter but I have problems with even-length FIR filters - I just don't get proper result.</p> <p>I guess I'm doing something wrong maybe with phase function or something else - but what ?</p> <p>Thanks in advance, regards, Bul.</p> Answer: <p>Your procedure is of course correct. It is in the details where things usually go wrong. One important thing is how to extend the desired frequency response beyond Nyquist taking the required symmetry into account. In order for the filter coefficients to be real-valued, the desired frequency response must satisfy</p> <p>$$D[k]=D^*[N-k],\quad k=0,1,\ldots,N-1\tag{1}$$</p> <p>where $*$ denotes complex conjugation, and $N$ is the FFT length (= filter length). From (1) it follows that for even $N$, the elements of the complex desired frequency response are</p> <p>$$D_0,D_1,\ldots,D_{N/2},D^*_{N/2-1},\ldots,D^*_1$$</p> <p>For odd $N$ you get</p> <p>$$D_0,D_1,\ldots,D_{(N-1)/2},D^*_{(N-1)/2},\ldots,D^*_1$$ Note that in order for (1) to be satisfied, $D_0$ and, for even $N$, $D_{N/2}$ must be real-valued.</p> <p>This little Matlab/Octave code works for even and odd filter lengths.</p> <pre> % frequency sampling design of linear phase FIR filter N = 64; % FFT length = filter length np = floor(N/2) + 1; % number of independent frequency points n = 0:np-1; w = n*2*pi/N; % frequency vector M = sin(n*pi/(np-1)); % some desired magnitude response D = M.*exp(-1i*(N-1)/2*w); % desired complex frequency response (linear phase) D = [D,conj(D(N-np+1:-1:2))]; % append redundant points for IFFT h = ifft(D); % compute impulse response max(abs(imag(h))) % should be very close to 0 h = real(h); % remove numerical inaccuracies % check result [H,w2] = freqz(h,1,4*N); plot(w/2/pi,abs(D(1:np)),'.',w2/2/pi,abs(H)) </pre>
https://dsp.stackexchange.com/questions/19625/fir-filter-design-with-frequency-sampling-method-setting-proper-phase-response
Question: <p>How does the transition width of a FIR filter relate to phase delay at the output of the filter?</p> <p>I have been trying to find information on the subject for days.</p> Answer: <p>In <a href="https://dsp.stackexchange.com/a/34307/4298">this answer</a> I gave two well-known heuristic design formulas relating the filter order of (linear-phase) FIR low-pass filters to the transition bandwidth. According to both formulas, the transition bandwidth is inversely proportional to the filter order. Since the phase delay of a linear-phase FIR filter equals $M/2$, where $M$ is the filter order, the phase delay $\tau_p$ and the transition bandwidth $\Delta\omega$ are also inversely proportional to each other:</p> <p>$$\Delta\omega\propto \frac{1}{\tau_p}$$</p>
https://dsp.stackexchange.com/questions/35607/relation-between-fir-filters-transition-width-and-phase-delay
Question: <p>When decimating a narrow-band signal with a <a href="http://en.wikipedia.org/wiki/Cascaded_integrator-comb_filter">cascaded integrator-comb (CIC) filter</a>, which FIR filter is more suitable to compensate the CIC frecuency response?</p> Answer: <p>There is no single answer to your question: as with any filter-design problem, it depends upon your requirements. As described pretty well on the <a href="http://en.wikipedia.org/wiki/Cascaded_integrator-comb_filter" rel="nofollow">Wikipedia page</a>, CIC (cascaded-integrator-comb) filters consist of a number of pairs of integrator and comb stages (hence the name). Each integrator-comb stage has an aggregate impulse response that is equivalent to a boxcar filter (i.e. one with a rectangular frequency response). A boxcar's frequency (magnitude) response has a shape resembling a sinc function, so the overall CIC structure is going to have a magnitude response that looks like a sinc function taken to some power $N$, where $N$ is the number of integrator-comb stages.</p> <p>There aren't a whole lot of knobs for you to tweak based on any application-specific requirements, however. You can tweak the decimation/interpolation ratio of the CIC structure, the comb delay, and the number of stages, but you're still stuck with the sinc-like frequency response, which isn't particularly ideal, as it's not flat across the main lobe and has relatively high sidelobes. So, it's typical for a CIC to be followed by another filter that "cleans up" the overall response.</p> <p>The rub: what you need from any compensating filter that you put after the CIC is going to be defined by your application. What's really important is the response of the overall cascade, which you would constrain based on your application's needs. There's no specific filter that is "most suitable."</p>
https://dsp.stackexchange.com/questions/160/fir-filter-compensator-when-using-a-cic-decimation-filter
Question: <p>If a time-domain signal has sharp corners, its frequency spectrum will contain high-frequency components. Truncating the spectrum results in Gibbs' phenomenon. So if you're trying to design an FIR, you really want the target frequency response to be nice and smooth so that windowing the impulse response down to a finite length doesn't distort the frequency response too much.</p> <p>Currently I'm contemplating trying to design a very strange filter: One that has unit gain at all frequencies, but <em>non-zero</em> phase. I'm wondering whether or not a similar phenomenon occurs: If the filter has unit gain at all frequencies, then what does truncating the impulse response do to the phase alignment?</p> Answer: <p>This would be an allpass filter. Except for the trivial case of unity and integer-sample delays, these can't be done as FIR filters and in general an IIR filter is required. However, they are easy to make. The zeroes of an allpass are simply the inverse of the poles (and vice versa). If you have the poles in polynomial form, you can simply flip them to get the zero polynomials. For example a second order allpass looks like this $$H(z)=\frac{a_{2}\cdot z^{0} + a_{1}\cdot z^{-1} + a_{0}\cdot z^{-2}}{a_{0}\cdot z^{0} + a_{1}\cdot z^{-1} + a_{2}\cdot z^{-2}}$$ Strict allpass filter have $\left \|H(e^{j\cdot \omega })\right \|=1 $ for all frequencies. You can certainly design approximation using FIR filters if you only need this property for a limited frequency range and if the magnitude doesn't have to be exactly unity.</p>
https://dsp.stackexchange.com/questions/2934/phase-shift-filter-design
Question: <p>Is it possible to dynamically filter a signal in realtime on a microcontroller? </p> <p>What I mean by dynamically is to change the cut off frequency of the filter on the fly. </p> <p>I have some DSP knowledge and realize that I probably do not have the computational power to do an FFT on the fly. Instead I should be looking at creating an IIR or FIR filter that I can continually convolve with my signal. </p> <p>The issue is now whether or not I have enough computational power to generate the filter coeffecients quickly and then convolve with the signal. I'm guessing that because of this I'm going to have to be very lenient on the response of the filter which is ok for my application. </p> <p>I have looked at algorithms such as the Remez Exchange algorithm and believe this may be able to work but am not sure. I wanted to check before I start the lengthy process of implementing whether or not I am on the right track.</p> Answer: <ul> <li>You can pre-compute the coefficients for a bunch (say $N=1024$) different cutoff frequencies. If your application doesn't need to provide fine control over the cutoff frequency, just read from your table and you're done. This works best if you have a lot of ROM and/or you use short FIR or IIR filters.</li> <li>If you need finer control than those $N$ values, and if the relationship between your coefficients and cutoff frequency is well-behaved (ideally, monotonic), you can use linear interpolation within the pre-computed table of coefficients. This works best with well-behaved structures like state-variable filters - for which the coefficients are monotonic functions of the cutoff frequencies, and which do not get unstable when modulating them at fast rates. This is a very common problem in musical audio applications (equalizers, synthesizer analog filter emulation...). If you use other filter topologies, make sure that they cannot get unstable when their coefficients are changed "in mid-flight" - to me, this is a harder problem than actually computing them.</li> </ul>
https://dsp.stackexchange.com/questions/8120/realtime-filtering-on-a-microcontroller-with-dynamic-cut-off-frequencies
Question: <p>I have a filter design, and it filters over a 1-2 kHz range.<br> What should I do if I want to apply it to data with a different sample rate than the one for which it was designed?</p> <p>Let's say it consists of Bessel and Chebyshev filters. How do I find a function that defines each filter's coefficients at an arbitrary sample rate? Or should I do this by hand?</p> Answer: <p>Since you mention sampling, you are presumably talking of a digital filter.</p> <p>The cut-off frequency or half-power frequency of a digital filter is actually relative to the sampling frequency $f_s$. If your digital filter is passing signals in the $1$ kHz to $2$ kHz range when you feed it a signal sampled at $f_s = 20$ kHz, then the pass band is from $5\%$ to $10\%$ of $f_s$. These ratios do not change if $f_s$ changes to some other value, say $40$ kHz. The same digital filter will become a filter with passband $2$ kHz to $4$ kHz without your having to do anything.</p>
https://dsp.stackexchange.com/questions/1104/applying-fir-filter-to-data-with-different-sample-rates
Question: <p>The famous <a href="https://www.w3.org/TR/audio-eq-cookbook/" rel="nofollow noreferrer">https://www.w3.org/TR/audio-eq-cookbook/</a> offers a set of [real] biquad filter calculation formulas that generally work fine.</p> <p>However, when filter's frequency approaches Nyquist frequency the Q (bandwidth) specification of a filter becomes greatly distorted - usually it shrinks a lot (even though the author mentioned that he performed a necessary pre-warping).</p> <p>I'm in quest for filter formulas that do not have such strong bandwidth distortion. I need peaking/bell, band-pass, low-pass, high-pass, high-shelf, notch filters. I know this can be done as previously I've bought a peaking/bell/band-pass filter formulas with less distortion, but they are still not perfect and I need other filter types.</p> <p>So, I'm also willing to pay for the solution if the price is right.</p> <p>Alternatively, if one could point me to an optimization algorithm that works with Z-domain filters that would be great, too. Unfortunately, most usual optimization algorithms do not work well in Z-domain - they can't optimize a set of parameters to match a desired frequency response (probably due to periodic functions used to calculate the frequency response).</p> Answer: <p>here is a quick look at how the 5 degrees of freedom for the parametric EQ can be viewed. it's my take on what Knud Christensen of tc electronic came up with about a decade ago at <a href="http://www.aes.org/e-lib/browse.cfm?elib=12429" rel="nofollow">an AES convention</a> and <a href="http://www.google.com/patents/WO2004054099A1" rel="nofollow">this patent</a>.</p> <p>so, forget about the Cookbook (and the issues of Q and bandwidth therein) and consider (in the s-plane) the parametric EQ as the sum of a bandpass filter (with a $Q$ value) in parallel with a wire:</p> <p>$$ H(s) = (G_\text{boost} - 1)\frac{\frac{1}{Q}\frac{s}{\omega_0}}{\left(\frac{s}{\omega_0}\right)^2 + \frac{1}{Q}\frac{s}{\omega_0} + 1} + 1 $$</p> <p>$G_\text{boost} = 10^{\frac{dB}{20}}$ is the gain of the peak (or valley, if $dB&lt;0$). the gain at DC and at Nyquist is 0 dB. that's a 2nd-order IIR and there are 3 independent parameters. 2 more to go. so we next add an overall gain parameter:</p> <p>$$ H(s) = G_0 \left((G_\text{boost} - 1)\frac{\frac{1}{Q}\frac{s}{\omega_0}}{\left(\frac{s}{\omega_0}\right)^2 + \frac{1}{Q}\frac{s}{\omega_0} + 1} + 1 \right) $$</p> <p>that's 4 knobs to twist. one more knob to add (without raising the filter order) and we will be done with adding more independent parameters.</p> <p>so what Knud does here is replace that "wire" (that trailing "$1$" in the transfer function) with a prototype shelving filter that <strong>must</strong> have the same poles, the same $Q$ and $\omega_0$ as the BPF, so that the denominator is the same. the transfer function of that shelf is:</p> <p>$$ H_\text{shelf}(s) = \frac{R\left(\frac{s}{\omega_0}\right)^2 + \frac{\sqrt{R}}{Q}\frac{s}{\omega_0} + 1}{\left(\frac{s}{\omega_0}\right)^2 + \frac{1}{Q}\frac{s}{\omega_0} + 1} $$</p> <p>where $R \triangleq 10^{\frac{tilt}{20}}$ and $tilt$ is the gain differential of the shelf in dB. this is what offsets the gain at Nyquist to be different than the gain at DC. After bilinear transformation, Nyquist gets boosted by $tilt$ dB and the gain at DC remains unchanged. Like the $dB$ boost parameter, the $tilt$ parameter can be either positive or negative. $G_0 \cdot R$ is the linear gain at Nyquist.</p> <p>put that all together and you get:</p> <p>$$ \begin{align} H(s) &amp; = G_0 \left((G_\text{boost} - 1)\frac{\frac{1}{Q}\frac{s}{\omega_0}}{\left(\frac{s}{\omega_0}\right)^2 + \frac{1}{Q}\frac{s}{\omega_0} + 1} + H_\text{shelf}(s) \right) \\ &amp; = G_0 \left((G_\text{boost} - 1)\frac{\frac{1}{Q}\frac{s}{\omega_0}}{\left(\frac{s}{\omega_0}\right)^2 + \frac{1}{Q}\frac{s}{\omega_0} + 1} + \frac{R\left(\frac{s}{\omega_0}\right)^2 + \frac{\sqrt{R}}{Q}\frac{s}{\omega_0} + 1}{\left(\frac{s}{\omega_0}\right)^2 + \frac{1}{Q}\frac{s}{\omega_0} + 1} \right) \\ &amp; = G_0 \frac{R\left(\frac{s}{\omega_0}\right)^2 + (G_\text{boost}+\sqrt{R}-1)\frac{1}{Q}\frac{s}{\omega_0} + 1}{\left(\frac{s}{\omega_0}\right)^2 + \frac{1}{Q}\frac{s}{\omega_0} + 1} \\ \end{align}$$</p> <p>no matter how you look at that, this has 5 degrees of freedom and those 5 biquad coefficients are <strong>fully</strong> defined from these 5 parameters. doesn't matter if you map from $s$ to $z$ using the blinear transform or the trapezoidal rule (effectively the same thing) or any other method that does <em>not</em> change the order of the filter. you may have to fudge the definition of $Q$ or bandwidth, you may have to compensate $\omega_0$ and/or $Q$ for frequency warping effects (like you get with the blinear transform), but if you paid big bucks for something that gets you a 2nd-order IIR filter, it doesn't matter if you implement it with any Direct Form or transposed Direct Form or Lattice or Normalized Ladder or Hal Chamberlin's State-Variable or Andrew Simpson's modeling of <strong>linear</strong> analog with trapezoidal integration, eventually you get to 5 coefficients and they can be mapped to these 5 independent parameters. <strong>it's all the same.</strong> whether or not you paid money for a license or not. the math is stronger than any claims made by whomever you are licensing from.</p> <p>Just FYI, i solved where the true peak or valley frequency is when there <strong>is</strong> a $tilt$ that is not zero. the frequency where the peak or valley has been nudged over by the tilt is:</p> <p>$$ \omega_\text{peak} \ = \ \omega_0 \ \sqrt{ \frac{Q^2 \left(R - \frac{1}{R}\right)}{G_\text{boost}^2 - R + 2 Q^2 (R - 1)} + \\ \sqrt{\frac{G_\text{boost}^2 - \frac{1}{R} + 2 Q^2 \left(\frac{1}{R} - 1\right)}{G_\text{boost}^2 - R + 2 Q^2 (R - 1)} + \frac{Q^4 \left(R - \frac{1}{R}\right)^2}{\left(G_\text{boost}^2 - R + 2 Q^2 (R - 1)\right)^2} } } $$</p> <p>you can see that when $tilt = 0$, then $R=1$ and consequently $\omega_\text{peak} = \omega_0$. the peak gain $G_\text{boost}$ might also have to be adjusted a little and that has yet to be worked out. a good first guess would be $G_\text{boost} \leftarrow \frac{G_\text{boost}}{\sqrt{R}}$ or maybe $G_\text{boost} \leftarrow G_\text{boost}-(\sqrt{R}-1)$.</p>
https://dsp.stackexchange.com/questions/19225/audio-eq-cookbook-without-frequency-warping
Question: <p>I calculated the order of the FIR filter to be 31(N). so, the number of coefficients has to be 32 (N+1). so, I have to increase it to 33 to make it an odd number.</p> <p>Why the number of filter coefficients is required to be an odd number?</p> Answer: <p>I think it is about having a linear phase. Having a linear phase is often what you want because it means the delay introduced by the filter will be the same across all the frequency. Then, if you want a linear phase filter, you need to have a symmetrical arrangement of coefficient <em>around</em> the centre coefficient. As for why you have to have a symmetrical number of coefficient around the centre to be of linear phase, I need to verify something then I will update the answer. :)</p> <p><strong>Edit</strong>: Jason R got the answer while I was looking for it! +1</p>
https://dsp.stackexchange.com/questions/18413/why-the-number-of-filter-coefficients-in-fir-filter-has-to-be-an-odd-number
Question: <p>I have a sensor producing (more or less) bandlimited data with a cut-off of about 45Hz, with a roll-off and <a href="http://en.wikipedia.org/wiki/Additive_white_Gaussian_noise" rel="noreferrer">AWGN</a>. I have an ADC that samples said signal at 800Hz, with a single-pole anti-aliasing filter at about 200Hz. The problem is, I only have enough communication bandwidth to send samples at 100Hz and therefore some decimation is necessary.</p> <p>Currently, I simply have an 8-sample moving average filter and send every 8th sample. This feels dirty and suboptimal. Surely there must be a better way.</p> <p>Is there an accepted "best" thing to do in this instance? Should I, for example, do a low-pass FIR filter to squeeze out as close to 50Hz of signal bandwidth as possible? Or, is there some sort of optimal estimation scheme will do better? </p> <p>The aim is to implement several channels (9 channels) on a smallish microcontroller (ARM Cortex M4, for example), so the computationally cheaper the better! </p> Answer: <blockquote> <p>Should I, for example, do a low-pass FIR filter to squeeze out as close to 50Hz of signal bandwidth as possible?</p> </blockquote> <p>Yes, that is exactly what you should do. That is an extremely low data rate, so even with a wimpy processor I would think that should be able to do a pretty good filter. Especially since you only need to calculate $\frac{1}{8}$ of the filter outputs.</p>
https://dsp.stackexchange.com/questions/3293/oversampling-and-decimation-what-filter-to-use
Question: <p>Is there any current ideas about IIR filter algorithm parallelization with thread count greater than filter order?</p> <p>Ideally, parallelization method should load GPU efficiently.</p> Answer: <p>You might be interested in the following paper:</p> <p>Nehab, D; Maximo, A; Lima, R; Hoppe, H: GPU-Efficient Recursive Filtering and Summed-Area Tables. ACM Trans. Graph. 30(6):176 (December 2011). doi://10.1145/2024156.2024210 <a href="http://w3.impa.br/~diego/publications/NehEtAl11.pdf" rel="nofollow">http://w3.impa.br/~diego/publications/NehEtAl11.pdf</a></p> <p>The basic idea is to recognize that linear filters are associative (at least in theory) and thus you can</p> <ol> <li>divide your input into chunks.</li> <li>every thread initializes its iir filter state with 0s and processes its chunk.</li> <li>every thread stores the final state of its iir filter for its chunk.</li> <li>now (because of associativity) you can figure out what the beginning filter state is of every chunk.</li> <li>so then you run the filter over the chunk again, this time correctly initialized and get the correct output.</li> </ol> <p>As @jonsca pointed out, you were a bit vague about your use case. The above all assumes that you can do batch processing on your input. If you need some kind of real-time filtering none of what I said is relevant.</p>
https://dsp.stackexchange.com/questions/8020/iir-filter-parallelization