How to Implement an FIR Filter in C++ [DSP #15]

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 พ.ค. 2024
  • ✅ Check out the full article on TheWolfSound.com: thewolfsound.com/fir-filter-w...
    ➡️ and the associated code: github.com/JanWilczek/fir-simd
    ➡️ Convolution series: • Convolution Intuitivel...
    ➡️ 3 modes of convolution explained: • Convolution in Matlab ...
    ✅ Sign up for WolfSound's newsletter: thewolfsound.com/newsletter/
    ✅ Please subscribe to WolfSound to let the little Wolf 🐺 grow:
    th-cam.com/users/WolfSoundAu...
    🎧 Listen to my music: thewolfofficial.com/
    Hi, my name is Jan Wilczek and I am an audio programmer and a researcher. Welcome to WolfSound!
    WolfSound's mission is to provide high-quality, informative, and entertaining videos, articles, and courses on how to process sound by exploring mathematics, applying algorithms, and creating code in various programming languages. Topics include sound synthesis, digital signal processing, programming languages for audio (C, C++, Python, Rust), and audio effects. I am also sharing tips on how to learn fast and effectively. Make sure to visit www.thewolfsound.com/.
    WolfSound enables everybody to learn about audio programming!
    ABOUT THE VIDEO
    In this video, I show you how to implement a plain (unoptimized) FIR filter in C++.
    Learn how to
    💡 Rewrite the FIR filter convolution formula,
    💡 Pad the signals with zeros correctly, and
    💡 Implement it in C++.
    In case of any doubt in understanding, please, refer to the article above or ask a question in the comments 🙂
    Video edited by Vadzim Vezhnavets.
    ABOUT ME
    My name is Jan Wilczek. I am an audio programmer, a researcher in the field of music technology, and a musician. Through articles and videos from WolfSound, you will easily understand the main concepts of sound processing using software. My full story: • How I Got Started With...
    FOLLOW WOLFSOUND ONLINE
    ✅ Blog: www.thewolfsound.com/
    ✅ LinkedIn: / jan-wilczek-audio-prog...
    ✅ Twitter: / wilczek_jan
    ✅ Facebook: / janwilczekwolfsound
    ✅ Instagram: / janwolfwilczek
    ✅ Pinterest: / jawitrle
    TIME CODES
    00:00 Introduction
    00:22 What is an FIR filter?
    00:53 Mathematical definition of convolution
    01:33 Practical convolution formula
    02:08 How to pad the input signal with zeros?
    03:38 FIR filter implementation
    06:41 FIR filtering test
    07:34 Summary
    #dsp #cpp
  • แนวปฏิบัติและการใช้ชีวิต

ความคิดเห็น • 32

  • @WolfSoundAudio
    @WolfSoundAudio  2 ปีที่แล้ว

    Have I helped you with this video? If yes, please, consider buying me a ☕ coffee at www.buymeacoffee.com/janwilczek
    Thanks! 🙂

  • @asthasingh7267
    @asthasingh7267 หลายเดือนก่อน

    Thanks for putting this up! Great help😊

  • @alexeykononov5596
    @alexeykononov5596 หลายเดือนก่อน

    very thorough explanation, thanks 👍 I wish you well in your marketing agenda (it is much more complex than FIN Filter in C++ I presume 🤣)

  • @MoXyiD
    @MoXyiD ปีที่แล้ว +4

    Good shit bro! I needed to get re-upped on my convolution and you provided GREAT easy to understand (from an engineers perspective) content.

    • @WolfSoundAudio
      @WolfSoundAudio  ปีที่แล้ว

      That's great, I'm happy to hear that!

  • @velvetsound
    @velvetsound 2 ปีที่แล้ว +2

    This was fantastic, thank you. 😀

  • @robc3863
    @robc3863 ปีที่แล้ว +2

    Interesting that you used the sound response of a room to somehow make the music match. I think this needs a more generalised explanation because most non DSP mathematicians won't have understood IMO :)

  • @danmiller4091
    @danmiller4091 2 ปีที่แล้ว +1

    Super helpful video thank you very much!!

  • @nickst2797
    @nickst2797 4 หลายเดือนก่อน

    Thanks! Can you do an IIR tutorial as well?

  • @isaiahclemons1860
    @isaiahclemons1860 ปีที่แล้ว

    If I wanted to create an FIR low pass filter at a specific frequency how could I change this code to implement a desired corner frequency?

  • @arunaideepan293
    @arunaideepan293 2 ปีที่แล้ว +1

    Useful 👍

  • @farhatibrahim4034
    @farhatibrahim4034 2 ปีที่แล้ว +2

    Also it is a fundamental filter for Video coding ;)

    • @WolfSoundAudio
      @WolfSoundAudio  2 ปีที่แล้ว +1

      Yes, of course! And I want to leave talking about image and video FIR filters to more knowledgeable people :)

  • @bigmistqke
    @bigmistqke 2 ปีที่แล้ว +1

    Damn, that's a pretty crazy result for such a simple filter. I am a bit puzzled how we get from the impulse response to the coefficient list (dsp noob here), but will look into your code to figure out those details.

    • @bigmistqke
      @bigmistqke 2 ปีที่แล้ว

      So, after a bit of thinking, are the coefficients just the magnitudes of each sample of that audio wave? Because an impulse is only 1 sample, all the other sound we hear is a result of convolution, w decaying size over time. Ok, little eye opener over here.

    • @bigmistqke
      @bigmistqke 2 ปีที่แล้ว +1

      It's so bizarre and extremely fascinating how delay, reverberation and filtering are all one and the same thing. Makes sense in one way, twists around my head in the other.

    • @danmiller4091
      @danmiller4091 2 ปีที่แล้ว +1

      @@bigmistqke The coefficients are calculated by multiplying the ideal impulse response of the filter with a windowing function. The textbook DSP A practical Approach by E C. Ifeachor and B. W. Jerwis has a nice examples if you are interested.

    • @bigmistqke
      @bigmistqke 2 ปีที่แล้ว

      @@danmiller4091 thanks for answering my question! I am glossing over it right now, this dsp-literature is quite dense lol. But if i understand it correctly, this multiplying the audio-file of the impulse response by the windowing function is because we are interested in the energy of the signal, right? Makes sense, as it turns the waveform into how the volume changes over time, and that's what the coefficients are. And then from this generated buffer we would take sample #0 and this would be a(0), sample #1 a(1), ..., sample #n a(n)? I assume this is what they describe in the book as the 'direct method'.

    • @WolfSoundAudio
      @WolfSoundAudio  ปีที่แล้ว +2

      So the coefficients are just a reversed impulse response with some zero padding for the ease of implementation ;) If we want to use an impulse response of a room as a filter, we don't have to preprocess it :) Windowing is only used when we design the filter in the frequency domain. Thanks for your feedback; my videos are here exactly to make the DSP literature more approachable!

  • @athuldas44
    @athuldas44 7 หลายเดือนก่อน

    How are u implementing sound with the code please can I know this is not domain i am intrested please any one ???

  • @przekladanki
    @przekladanki 2 ปีที่แล้ว +1

    Nice look with this shirt 🙃

  • @MatkatMusic
    @MatkatMusic 2 ปีที่แล้ว +3

    Why not use std::vector instead of raw C-style arrays?

    • @WolfSoundAudio
      @WolfSoundAudio  2 ปีที่แล้ว +2

      Hi, Matkat Music, thanks for the question. Since in the filtering function we don't do any memory management, std::vector would be an unnecessary detail. However, if you look into the source code I linked to, you will see that these raw array pointers are initialized with std::vector::data() so they use vectors under the hood :)

    • @vblings
      @vblings 2 ปีที่แล้ว

      for up-to-date cpp, std::span would be better idea.

  • @sadewosat
    @sadewosat 8 หลายเดือนก่อน +1

    Can you explain Hilbert transform in c++ too?

    • @WolfSoundAudio
      @WolfSoundAudio  8 หลายเดือนก่อน

      Noted, will try! Thanks! 🙂

  • @heddshot87
    @heddshot87 9 หลายเดือนก่อน

    6:58 I thought you were playing Nokia ringtone