Adaptive FIR LMS filters: 50 Hz removal as an example in Python

Поделиться
HTML-код
  • Опубликовано: 29 окт 2024

Комментарии • 28

  • @GeorgeMaser-d7b
    @GeorgeMaser-d7b 11 месяцев назад

    Hello DSP, Great example, I am looking for an adapter filter that can predict a threshold on an Acceleration Pulse width while its slope is going in a positive direction. The pulse or the Shock in time is what I am measuring. From this can I get a velocity by integrating maybe. If not maybe counts at the threshold. Counting shock waves is not clean. Threshold is set by the adapter filter. Weights are changing as well as the magnitude of the waveform.

  • @911by911
    @911by911 Год назад

    Thank you for this great lessons. it inspired me to made some tests with your audio tool AudiClean, and the attached wav file music+extractor.wav and extractor.wav as the noise reference.
    It is very hard to find a entry point for a useful combination of the number of taps and learning rate for this 44k example. Do you have any hint for me?
    Another point: What is the best practice for the amplitude of the reference noise? This value wasn't scaled in your python code for the 50Hz Signal [-1,1], but the extractor.wav ref signal for example is much higher.

  • @bryanperf
    @bryanperf 3 года назад +1

    I'm having trouble understanding why an LMS filter is required here when we already have the isolated 50hz noise and the noisy d[n]. Can't we just remove the noise by subtracting x[n] (50hz) from d[n]? Furthermore, the LMS filter should be minimizing e[n] as much as possible by matching the filter output (referred to as the canceller in the video) to d[n] as best as possible. In that case, wouldn't e[n] be close to zero instead of having the denoised signal? There must be something obvious I am missing?

    • @DSPcourse
      @DSPcourse  3 года назад +5

      Excellent questions! We could subtract the 50Hz indeed manually but for that we'd need to know the exact amplitude and phase of the 50Hz. The LMS filter susses that out by itself. Also in an ECG recording the 50Hz noise will be changing all the time so a constant subtraction would only work for a short time. But more important is a slowly changing phase relationship because 50Hz powerline is never 50Hz exactly but sometimes a tiny bit less and sometimes a tiny bit more so that the LMS filter needs to adapt. That for example is a problem when the learning rate is to slow that it cannot adapt to changing phase relationships. -- Regarding you other question about e[n]: this is indeed counter-intuitive and was wondering how long it takes that somebody would stumble over it. So you are quick! The reason why the ECG is not removed is because we tell via x(n) that 50Hz needs to be removed. The LMS filter can only remove noise which is _correlated_ with d(n) so that it can only work on the 50Hz. The ECG will stay unaffected as it's not correlated to 50Hz. The error which is minimised is the mean correlation error between x(n) and d(n). This actually is a distinct advantage of this filter because the ECG won't be distorted at all in contrast to a narrow bandstop which would, because of it's long impulse response, create nasty ringing after an ECG peak. The HumBug (www.a-msystems.com/p-1270-hum-bug-noise-eliminator.aspx) works with exactly this principle and as you see they stress this fact. In particular in neuroscience signals can be quite pulse like and cannot be filtered with a narrow 50Hz filter as these would trigger long impulse responses so an LMS filter is used.

    • @bryanperf
      @bryanperf 3 года назад +1

      @@DSPcourse Thank you for the detailed response! This makes much more sense now that I realize the LMS filter only removes correlated noise. Please keep the great and informative videos coming!

  • @tomas5780
    @tomas5780 Год назад

    In the block diagram the output is also the error function, aren't we minimizing the error, so doesn't the output signal at the end gets reduced to nearly zero. I observed different block diagrams for LMS algorithm enabled adaptive filter in other sources. Is it error the output we get?

    • @DSPcourse
      @DSPcourse  9 месяцев назад

      Because the filter can only remove what's correlates between the noise ref and the contaminated signal. So only the noise ref is removed.

    • @DSPcourse
      @DSPcourse  9 месяцев назад

      Note there are loads of wrong papers and diagrans out there sadly.

    • @vinisharamkumar4181
      @vinisharamkumar4181 6 месяцев назад

      @@DSPcourse yes!! some papers suggest that, input=signal+noise; desired=signal which is misleading. but, input=ref_noise; desired= signal+noise. We are training the FIR to cancel the correlated noise from desired signal. Am i correct?

  • @amruthavl2576
    @amruthavl2576 2 года назад

    How can I do this for echo cancellation for in audio data eg:echo.wav?? Sir can you share this code??

  • @prathmeshmatodkar6391
    @prathmeshmatodkar6391 2 года назад

    Hello, I had a question, in the lms function is there a reason why you wrote coefficient[j]=coefficient[j]+error*mu*buffer[j] , shouldn't it be coefficient[j]=coefficient[j-1] or coefficient[j+1]=coefficient[j] , since the changing coefficients depend on "Previous" coefficients modified by the error ,mu values ?

    • @DSPcourse
      @DSPcourse  2 года назад

      No. The index j refers to the tap index. All tap indices / weights have to be changed at every time step. There are two time scales. One at every time step (over all j) and the slow correction of the coefficients via the error feedback.

    • @prathmeshmatodkar6391
      @prathmeshmatodkar6391 2 года назад

      @@DSPcourse Thank you for the answer, so how where does the slow correction happen in the code

  • @渇いた叫び
    @渇いた叫び 3 года назад

    Muy buen contenido amigo!

  • @bogmaerke
    @bogmaerke 2 года назад

    At 1:38 you say the idea is to remove the 50 Hz from d(n), I think you're mistaken - d(n) is the desired signal and should therefore not include the noise (50 Hz), I think you mean remove the 50 Hz from y(n).

    • @DSPcourse
      @DSPcourse  2 года назад

      No, the d(n) is the with noise polluted signal. A "normal" FIR filter, for example a bandstop would remove the 50Hz. However, here it's the opposite: y(n) is a "remover" or "canceller" so the FIR filter is not removing noise but is conditioning the reference noise x(n). The nomenclature is indeed confusing but stems from control theory where d(n) is the desired state.

  • @thatweebboy6625
    @thatweebboy6625 Год назад

    I am trying to run this code but every time it throws an error of not able to decode can u pls tell me what to do

  • @sam140167
    @sam140167 6 месяцев назад

    Thank's a lot! could you give us the python code please?

  • @karimelqouns6636
    @karimelqouns6636 2 года назад

    Thank you for explanations, but you injected 50hz because you know it's frequency, what if you didn't knew the noise/artifact frequency ?

    • @DSPcourse
      @DSPcourse  2 года назад

      If you remove 50Hz with a bandstop you also need to know it's 50Hz. So, you need to know what's noise and what's signal. However, the advantage of the LMS approach is that we can either artificially generate the reference noise or record it via an additional sensor.

  • @breezerlxd
    @breezerlxd 9 месяцев назад

    Could you please share your code?

    • @DSPcourse
      @DSPcourse  9 месяцев назад +1

      Write your own! :)

    • @breezerlxd
      @breezerlxd 9 месяцев назад +1

      haha, sure. lazy me. thanks for the reminder! @@DSPcourse

  • @lucarappez4204
    @lucarappez4204 3 года назад

    Maybe a stupid question but why not doing a bandpass filter to exclude the 50hz signal?

    • @DSPcourse
      @DSPcourse  3 года назад

      You mean bandstop? Of course that could be done. But for example for ECG with its delta-pulse like R-peaks a bandstop will create ringing. The adaptive filter won't. But the real power of an adaptive filter is when the noise is more complex, for example you want to cancel out noise in a hands free application where simple filtering is no longer possible but the noise needs to be subtracted. Here, neither the amount nor the pre-filtering is known and needs to be learned by the filter. In addition this will change constantly so it needs to be adaptive. The 50Hz removal is a very simple example but even that it's not altering the original signal at all with a filter is very desirable and you can buy this as a commercial device. It's called "hum-bug": www.a-msystems.com/p-1270-hum-bug-noise-eliminator.aspx For a lot of people in neurophys labs it's worth its $1,700.00 price tag!

  • @qiupeizhao6526
    @qiupeizhao6526 3 года назад

    Still not entirly understand why take the error as the final output. aren't we suppose to minimising it?

    • @DSPcourse
      @DSPcourse  3 года назад

      Counter-intuitive, isn't it? Well the filter only minimises the error which is correlated to x(n). So if we give the filter 50Hz as its input we tell the filter: remove 50Hz but the ECG is not correlated to 50Hz so the filter won't remove that and can't.