spec                 package:seewave                 R Documentation

_F_r_e_q_u_e_n_c_y _s_p_e_c_t_r_u_m _o_f _a _t_i_m_e _w_a_v_e

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

     This function returns the frequency spectrum (i.e. the relative
     amplitude of the frequency content) of a time wave. Results can be
     obtained either as absolute  or dB data.

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

     spec(wave, f, wl = FALSE, PSD = FALSE, dB = FALSE,
     at = FALSE, from = FALSE, to = FALSE, peaks = FALSE,
     identify = FALSE, col = "black", cex = 1, colpeaks = "red",
     cexpeaks = 1, fontpeaks = 1, plot = 1, flab = "Frequency (kHz)",
     alab = "Amplitude", flim = c(0, f/2000),alim = NULL,...)

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

    wave: data describing a time wave.

       f: sampling frequency of 'wave'.

      wl: if 'at' is not null, length of the window for the analysis
          (even number of points).

     PSD: if 'TRUE' return Power Spectra Density, _i. e._ the square of
          the spectra.

      dB: logical, if 'TRUE' return the spectrum in dB  (by default
          'FALSE').

      at: position where to compute the spectrum (in s).

    from: start mark where  to compute the spectrum (in s).

      to: end mark where to compute the spectrum (in s).

   peaks: returns peaks value for a given span (see 'details').

identify: to identify frequency values on the plot with the help of a
          cursor.

     col: colour of the spectrum.

     cex: pitch size of the spectrum.

colpeaks: colour of peaks value plotted on the spectrum.

cexpeaks: character size of peaks value plotted on the spectrum.

fontpeaks: font of peaks value plotted on the spectrum.

    plot: if '1' returns frequency on x-axis, if '2' returns  frequency
          on y-axis, (by default '1').

    flab: title of the frequency axis.

    alab: title of the amplitude axis.

    flim: the range of frequency values.

    alim: range of amplitude axis.

     ...: other 'plot' graphical parameters.

_D_e_t_a_i_l_s:

     A Hanning function is applied to the analysis window.
      If 'at', 'from' or 'to' are 'FALSE' then 'spec'  computes the
     spectrum of the whole signal.
      'peaks' setting corresponds to 'dimension' of 'embed'.
       When using 'identify', press 'stop' tools bar button to return
     values in the console.

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

     This function returns a vector of numeric data corresponding to
     the computed spectrum. If 'peaks' is 'TRUE', 'spec' returns a list
     with two elements: 

    spec: the spectrum computed

  peaks : the peaks value (in kHz).

_N_o_t_e:

     This function is based on 'fft'.

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

     Jrme Sueur jerome.sueur@ibaic.u-psud.fr and  Martin Maechler
     maechler@stat.math.ethz.ch for 'peaks'.

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

     'meanspec', 'corspec', 'fft'.

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

     data(tico)
     # spectrum of the whole signal, in absolute or dB amplitude,
     # horizontaly or vertically
     op<-par(mfrow=c(2,2))
     spec(tico,f=22050,type="l")
     spec(tico,f=22050,type="l",col="red",plot=2)
     spec(tico,f=22050,type="l",dB=TRUE,col="blue")
     spec(tico,f=22050,type="l",dB=TRUE,col="green",plot=2)
     par(op)
     # spectra computed at specific locations with peak value
     op<-par(mfrow=c(2,2))
     spec(tico,f=22050,wl=512,at=0.2,type="l",peak=175)
     title("Note A")
     spec(tico,f=22050,wl=512,at=0.7,type="l",peak=175)
     title("Note B")
     spec(tico,f=22050,wl=512,at=1.1,type="l",peak=175)
     title("Note C")
     spec(tico,f=22050,wl=512,at=1.6,type="l",peak=165)
     title("Note D")
     par(op)
     # an indirect way to compare spectra 
     a<-spec(tico,f=22050,wl=512,at=0.2,plot=FALSE)
     b<-spec(tico,f=22050,wl=512,at=0.7,plot=FALSE)
     c<-spec(tico,f=22050,wl=512,at=1.1,plot=FALSE)
     d<-spec(tico,f=22050,wl=512,at=1.6,plot=FALSE)
     all<-cbind(a,b,c,d)
     matplot(x=seq(0,11.025,length.out=nrow(all)),y=all,type="l",yaxt="n",
         xlab="Frequency (kHz)",ylab="Amplitude",xaxs="i")
     legend(8,0.8,c("Note A","Note B", "Note C", "Note D"),bty="o",
         lty=c(1:4),col=c(1:4))
     # spectrum from a particular position to another one
     op<-par(mfrow=c(2,1))
     oscillo(tico,f=22050)
     abline(v=c(0.5,0.9),col="red",lty=2)
     text(c("from 0.5 s","to 0.7 s"),
         x=c(0.5,0.9),y=rep(max(tico/1.1),2),col="red",pos=4)
     spec(tico,f=22050,wl=512,from=0.5,to=0.9,type="l",col="red")
     title("Spectrum of the note B")
     par(op)
     # spectrum and spectrogram
     data(orni)
     orni1<-cutw(orni,f=22050,from=0.32,to=0.39)
     layout(matrix(c(1,2),nc=2),widths=c(3,1))
     par(mar=c(5,4,3,0.5))
     spectro(orni1,f=22050,wl=128,zp=8,ovlp=85,scale=FALSE)
     par(mar=c(5,1,3,0.5))
     spec(orni1,f=22050,type="l",col="red",plot=2,flab="",yaxt="n")

