trapezwin: Trapepezoid windows

Description Usage Arguments Examples

Description

Create isosceles (symmetric) trapezoid windows

Usage

1
2
trapezwin(l = 10, prop = 0.5, l.slopes, scale = c("sum", "max", "mean"),
  step = TRUE)

Arguments

l

integer; length of the window

prop

numeric; proportion of the length covered by slopes

l.slopes

integer; length of the slopes. Overrides prop

scale

character; how the window should be scaled. Divide by window sum (default), max or mean

step

logical; should the first and last point be lifted a small step from zero?

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Specifying shape using prop
x <- 99
plot(0, type="n", xlim=c(0, x), ylim=c(0, 2/x))
for (i in (1:20)/20){
    lines(trapezwin(x, prop=i))
}

# Specifying shape using l.slopes
x <- 99
plot(0, type="n", xlim=c(0, x), ylim=c(0, 2/x))
for (i in ceiling(seq(1, x %/% 2, length.out=20))){
    lines(trapezwin(x, l.slopes=i))
}

# Spectral response of windows tuned for minimum first side-lobe.
# Convolution using a trapezoid window con be thought of as convolving twice with
# rectangular windows of different size. If the relative sizes are chosen with
# care the null of the second window can be placed in the middle of the first
# side lobe of the first window, and thereby reducing it.
set.seed(1)
w <- 59
x <- rnorm(2e4)
par(mfcol=c(3, 1), mar=c(1.5, 1.5, 0.5, 0.5), mgp=c(0, 0.6, 0))
s <- c(0.80, 0.82, 0.84)
for (i in s) {
    win <- trapezwin(w, prop=i)
    rol <- rollconv(x, win, partial=TRUE, scale.window=TRUE)
    spectrum(rol, main="", xlab="", ylab="", sub="", lwd=0.4, 
      ylim=c(1e-12, 1), xlim=c(0, 0.25))
    abline(v=(1/w)/0.58, col="#FF000044")
    grid(col="#00000022", lty=1)
    legend("top", legend=paste("prop =", round(i, 3)), bty="n",
      text.col="blue", adj=c(0, 0.5))
}

AkselA/R-rollfun documentation built on May 31, 2019, 8:41 a.m.