Menu

equivalent of octave filter

Marco
2020-03-24
2020-03-30
  • Marco

    Marco - 2020-03-24

    Hi, I am trying to create the equivalent of the octave/matlab "filter" function in my project.
    Until now I have achieved to translate y = filter(b,1,x), but now I also need the second vector that is returned from the filter function, i.e. [y,z] = filter(b,1,x).
    Do you know I can get z?

    This is how I have achieved y = filter(b,1,x):

    /**
     * @brief equivalent of matlab function filter(b,1,x)
     */
    template <class T1, class T2>
    static arma::Col<T2> firFilter(const arma::Col<T1>& b, const arma::Col<T2>& x) {
            sp::FIR_filt<T2,T1,T2> fir_filt;
            fir_filt.set_coeffs(b);
    
            unsigned int inputSize = x.size();
            arma::Col<T2> y(inputSize);  // Output sig
    
            for(unsigned int n=0;n<x.size();n++)
            {
                y[n] = fir_filt(x[n]);
            }
    
            return y;
        }
    

    Edit: after I get z I have to use it as the fourth argument of the filter, i.e. [y2,z2] = filter(b,1,x,z). Is this supported?

     

    Last edit: Marco 2020-03-24
  • Claes Rolen

    Claes Rolen - 2020-03-30

    Hi, thanks for using SigPack. I guess that the reason for you to add the internal states (z) from the filter is that you will call this function at different times and that it will have a "warm" start with the previous filter state. Actually this is already handled in SigPack since the filter itself is a class and the internal state will be encapsulated within the class between calls of filter() or the filter operator. BR Claes

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.