kaiserord               package:signal               R Documentation

_P_a_r_a_m_e_t_e_r_s _f_o_r _a_n _F_I_R _f_i_l_t_e_r _f_r_o_m _a _K_a_i_s_e_r _w_i_n_d_o_w

_D_e_s_c_r_i_p_t_i_o_n:

     Returns the parameters needed for fir1 to produce a filter of the
     desired specification from a Kaiser window.

_U_s_a_g_e:

     kaiserord(f, m, dev, Fs = 2)

_A_r_g_u_m_e_n_t_s:

       f: frequency bands, given as pairs, with the first half of the
          first pair assumed to start at 0 and the last half of the
          last pair assumed to end at 1.  It is important to separate
          the band edges, since narrow transition regions require large
          order filters. 

       m: magnitude within each band.  Should be non-zero for pass band
          and zero for stop band.  All passbands must have the same
          magnitude, or you will get the error that pass and stop bands
          must be strictly alternating. 

     dev: deviation within each band.  Since all bands in the resulting
          filter have the same deviation, only the minimum deviation is
          used.  In this version, a single scalar will work just as
          well. 

      Fs: sampling rate.  Used to convert the frequency specification
          into the [0, 1], where 1 corresponds to the Nyquist
          frequency, Fs/2. 

_V_a_l_u_e:

     An object of class 'FilterOfOrder' with the following list
     elements: 

       n: filter order 

      Wc: cutoff frequency 

    type: filter type, one of "low", "high", "stop", "pass", "DC-0", or
          "DC-1" 

    beta: shape parameter 

_A_u_t_h_o_r(_s):

     Original Octave version by Paul Kienzle pkienzle@users.sf.net.
     Conversion to R by Tom Short.

_R_e_f_e_r_e_n_c_e_s:

     Oppenheim, A. V.; Schafer, R. W.; and Buck J. R. (1999).
     Discrete-time signal processing. Upper Saddle River, N.J.:
     Prentice Hall.

     <URL: http://en.wikipedia.org/wiki/Kaiser_window>

     Octave Forge <URL: http://octave.sf.net>

_S_e_e _A_l_s_o:

     'hamming', 'kaiser'

_E_x_a_m_p_l_e_s:

     Fs = 11025
     op = par(mfrow=c(2,2), mar=c(3,3,1,1))
     for ( i in 1 : 4) {
       if (i==1) {
         bands=c(1200, 1500); mag=c(1, 0); dev=c(0.1, 0.1)
       } else if (i==2) {
         bands=c(1000, 1500); mag=c(0, 1); dev=c(0.1, 0.1)
       } else if (i==3) {
         bands=c(1000, 1200, 3000, 3500); mag=c(0, 1, 0); dev=0.1
       } else if (i==4) {
         bands=100*c(10, 13, 15, 20, 30, 33, 35, 40)
         mag=c(1, 0, 1, 0, 1); dev=0.05
       }
       kaisprm = kaiserord(bands, mag, dev, Fs)
       with(kaisprm, {
         d <<- max(1,trunc(n/10))
         if (mag[length(mag)]==1 && d %% 2 ==1)
           d<<-d+1
         f1 <<- freqz(fir1(n,Wc,type,kaiser(n+1,beta),'noscale'), Fs = Fs)
         f2 <<- freqz(fir1(n-d,Wc,type,kaiser(n-d+1,beta),'noscale'), Fs = Fs)
       })                                                               
       plot(f1$f,abs(f1$h), col = "blue", type="l", xlab = "", ylab = "")
       lines(f2$f,abs(f2$h), col = "red")
       legend("right", paste("order", c(kaisprm$n-d, kaisprm$n)), col=c("red", "blue"), lty=1, bty="n")
       b = c(0, bands, Fs/2)
       for ( i in seq(2,length(b),by=2)) {
         hi=mag[i/2]+dev[1]; lo=max(mag[i/2]-dev[1],0)
         lines(c(b[i-1], b[i], b[i], b[i-1], b[i-1]),c(hi, hi, lo, lo, hi))
       } 
     }
     par(op)

