Last data update: 2014.03.03

R: Plots and prints Short Time Fourier Transforms
plot.stftR Documentation

Plots and prints Short Time Fourier Transforms

Description

Processes a dataset, creating an object contained processed time-frequency analyses. These can then be plotted.

Usage

## S3 method for class 'stft'
plot(x, mode = c("decibels", "modulus", "pval"), log = "", showmax = TRUE, median = FALSE, xaxis = TRUE, topthresh, reassign = (!(is.null(x$LGD)) && !("mv" %in% x$type)), ylim, xlim,new = TRUE, zlim.raw,zlim.quantile, cex, col = gray (63:0/63),...)
## S3 method for class 'stft'
print(x, ...)

Arguments

x

"stft" class object to be processed.

mode

What should be plotted?

"decibels": log10 of FFT modulus
"modulus": Raw FFT modulus
"pvalue": P-value of each frequence's modulus assuming that window was in fact white noise of equal equal standard deviation

log

For log = "y", use a log scale on the y axis.

showmax

Vector or logical. Compute and plot the principle frequency components?

median

logical. If TRUE, smooth the STFT plot in the time direction with a running median.

xaxis

logical. If TRUE, plot pretty time axes.

topthresh

For finite values, crop plot for frequencies higher than this value, and show a summary plot up top.

reassign

logical. Plot reassigned stft, if available?

xlim, ylim

Parameters controlling axes limits of plot.

new

logical. If TRUE, make a new plot. Otherwise overlay on to existing plot.

zlim.raw

Raw values at which to threshold values for computation of heatmap colours.

zlim.quantile

Quantile values at which to threshold values for computation of heatmap colours.

cex

Size of points for reassigned STFT plotting.

col

Vector of colours to be used for plotting.

...

Additional arguments to be passed to methods.

Details

STFT objects are created by the stft function. These methods print some useful summary statistics about them, and produce plots.

mode determines the type of plot. "decibel" and "modulus" work with the raw values, while "pvalue" conducts some degree of normalisation in each time window and so is perhaps more useful for data showing a large variation in sd across different points in time. If the null.calc was set in the original stft argument, that is used - otherwise, an Exponential distribution is fit to each window, and the pvalues computed from that.

By default, the function uses some empirical quantile based colour thresholds designed to give somewhat reasonable and informative plots. This can be overridden, however, by setting different zlim.raw or zlim.quantile results. This can be useful for comparing two different datasets.

Reassigned stft plots are constructed, by default, when they are available, and when the original was not a "mv" stft. Unlike the heatmap used in the usual stft plot, a 2d scatterplot is used instead. This means that if there are few data points, it can be advantageous to set a higher cex value for larger points and better display.

With Accelerometer data, often the frequencies of interest are concentrated at the lower frequencies. Topthresh crops the frequency display to show only those frequencies. A summary plot is show on the top, to compensate. Choosing a grid of frequencies, this plot draws one line to represent the energies present in the signal at that particular frequency, and higher. Black lines are drawn for frequencies less than 2/3 the topthresh, red lines for 2/3 - 1 times topthresh, and blue lines for frequencies higher than topthresh. Alternative, set log = "y" to put frequencies on a log scale.

Value

These functions are run for their side effects.

See Also

stft, image.default

Examples


#Real data
binfile  = system.file("binfile/TESTfile.bin", package = "GENEAread")[1]

#Read in the entire file, calibrated
procfile<-read.bin(binfile)
#Create stft object
obj = stft(procfile, type = "svm", quiet = TRUE)
#Look at it
print(obj)

plot(obj, cex = 5)
plot(obj, showmax = FALSE, cex = 5) #suppress principals

#pval plot
plot(obj, mode = "pval", cex = 5)
#disable reassigned stft
plot(obj, mode = "pval", reassign = FALSE) 
#median smoothing
plot(obj, mode = "pval", reassign = FALSE, median = TRUE) 
#log scale frequency, no top bar
dev.new(); plot(obj, mode = "pval", reassign = FALSE, topthresh = Inf, log = "y") 

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(GENEAread)
Loading required package: bitops
GENEAread 1.1.1 loaded

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/GENEAread/plot.stft.Rd_%03d_medium.png", width=480, height=480)
> ### Name: plot.stft
> ### Title: Plots and prints Short Time Fourier Transforms
> ### Aliases: plot.stft print.stft
> ### Keywords: hplot
> 
> ### ** Examples
> 
> 
> #Real data
> binfile  = system.file("binfile/TESTfile.bin", package = "GENEAread")[1]
> 
> #Read in the entire file, calibrated
> procfile<-read.bin(binfile)
Loading required package: mmap
Number of pages in binary file: 104 
Calculated page references... 
Processing...
================================================================================
Processing took: 0.055 secs .
Loaded 31200 records (Approx  2 MB of RAM)
12-05-23 16:47:50.000 (Wed)  to  12-05-23 16:53:01.990 (Wed) 
Warning message:
In FUN(newX[, i], ...) : NAs introduced by coercion
> #Create stft object
> obj = stft(procfile, type = "svm", quiet = TRUE)
Extracting time interval:  16:47:50 16:53:01 
> #Look at it
> print(obj)
STFT object:
12-05-23 16:47:54.990 (Wed)  to  12-05-23 16:52:54.990 (Wed) 
61 increments of 5 s 
Window size:  1000 ( 10 s ) -> f resolution:  0.1 Hz
[SVM][Reassign]
------ 
{ stft(X = procfile, type = "svm", quiet = TRUE) }
> 
> plot(obj, cex = 5)
> plot(obj, showmax = FALSE, cex = 5) #suppress principals
> 
> #pval plot
> plot(obj, mode = "pval", cex = 5)
> #disable reassigned stft
> plot(obj, mode = "pval", reassign = FALSE) 
> #median smoothing
> plot(obj, mode = "pval", reassign = FALSE, median = TRUE) 
> #log scale frequency, no top bar
> dev.new(); plot(obj, mode = "pval", reassign = FALSE, topthresh = Inf, log = "y") 
dev.new(): using pdf(file="Rplots959.pdf")
> 
> 
> 
> 
> 
> dev.off()
png 
  2 
>