pwelch: Estimate Power Spectral Density Using Welch's Method

View source: R/pwelch.R

pwelchR Documentation

Estimate Power Spectral Density Using Welch's Method

Description

Estimates the power spectral density (PSD) of an input signal using Welch's method. This should function similarly to the Matlab function pwelch, but results may not be identical. Breaks the input signal into (usually) overlapping frames and averages the resulting PSD estimates

Usage

pwelch(
  x,
  nfft,
  noverlap = 0,
  sr = NULL,
  demean = c("long", "short", "none"),
  channel = 1
)

Arguments

x

input signal, either a numeric vector, Wave, WaveMC, or audioSample object. Can also be a path to a wav file and it will be read in

nfft

length of FFT window to use for individual frames

noverlap

number of samples each frame should overlap

sr

sample rate of data, only necessary if x is a vector

demean

method of demeaning the signal, one of 'long', 'short', or 'none'. Long subtracts the mean of the entire signal x, short subtracts the mean of each individual frame, none does no mean subtraction.

channel

channel number to analyse, ignored if x is a vector

Value

returns a list with items spec, the PSD estimate of the input signal, and freq, the frequency values (Hz) at each value of spec

Author(s)

Taiki Sakai taiki.sakai@noaa.gov

Examples

# wav example is synthetic echolocation clicks at 4kHz
wavFile <- system.file('extdata/testWav.wav', package='PAMmisc')
psd <- pwelch(wavFile, nfft=1e3, noverlap=500, demean='long')
plot(x=psd$freq, y=10*log10(psd$spec), type='l')


TaikiSan21/PAMmisc documentation built on Oct. 15, 2024, 9:29 p.m.