## ----setup, include = FALSE---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE ) old_par <- par("mfrow", "mai", "pty") options(width = 999) ## ----R_version, include = TRUE, echo = FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- out <- version cat( "R version: ", out$major, ".", out$minor, "\n", "Generated on: ", format(Sys.time(), "%d-%B-%Y"), sep = "" ) ## ----library------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- library(MatchingPursuit) ## ----empi_locate, include = TRUE, echo = TRUE---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- empi_locate() ## ----empi_install, include = TRUE, echo = TRUE--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # empi_install() ## ----empi_check, include = TRUE, echo = TRUE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- empi_check() ## ----7_non_stationary, include = TRUE, echo = TRUE, warning = FALSE------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ fs <- 1024 T <- 1 t <- seq(0, T - 1 / fs, 1 / fs) N <- length(t) # 7 non-stationary signals. x1 <- sin(2 * pi * (10 + 40 * t) * t) # linear chirp x2 <- sin(2 * pi * (20 * t^2) * t) # nonlinear chirp x3 <- (1 + 0.5 * sin(2 * pi * 2 * t)) * sin(2 * pi * 30 * t) # AM x4 <- sin(2 * pi * 50 * t + 5 * sin(2 * pi * 3 * t)) # FM x5 <- exp(-2 * t) * sin(2 * pi * 60 * t) # decreasing amplitude x6 <- sin(2 * pi * (5 + 20 * sin(2 * pi * t)) * t) # frequency modulated sine wave x7 <- t * sin(2 * pi * 40 * t) # increasing amplitude signal <- data.frame(x = x1 + x2 + x3 + x4 + x5 + x6 + x7) ## ----7_non_stationary_plot, include = TRUE, echo = FALSE, warning = FALSE, fig.width = 7, fig.height = 7----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- range <- range(signal) par(mfrow = c(8, 1), pty = "m", mai = c(0.2, 0.4, 0.2, 0.1)) plot(t, signal$x, type = "l", col = "blue", main = "", xlab = "", ylab = "") plot(t, x1, type = "l", ylab = "", xlab = "", xaxt = "n", yaxt = "s", main = "Linear chirp") plot(t, x2, type = "l", ylab = "", xlab = "", xaxt = "n", yaxt = "s", main = "Nonlinear chirp") plot(t, x3, type = "l", ylab = "", xlab = "", xaxt = "n", yaxt = "s", main = "AM") plot(t, x4, type = "l", ylab = "", xlab = "", xaxt = "n", yaxt = "s", main = "FM") plot(t, x5, type = "l", ylab = "", xlab = "", xaxt = "n", yaxt = "s", main = "Decreasing amplitude") plot(t, x6, type = "l", ylab = "", xlab = "", xaxt = "n", yaxt = "s", main = "Frequency modulated sine wave") plot(t, x7, type = "l", ylab = "", xlab = "", xaxt = "n", yaxt = "s", main = "Increasing amplitude") par(old_par) ## ----sample1_csv, include = TRUE, echo = TRUE, warning = FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # The sample1.csv file contains exactly the same data as shown in Step 1. file <- system.file("extdata", "sample1.csv", package = "MatchingPursuit") # The first line of the file contains two values: # the sampling rate in Hz (1024 Hz here) and the signal duration # in seconds (1 s here). out <- read.csv(file, header = FALSE) head(out) signal <- read_csv_signals(file) str(signal) ## ----empi_execute, include = TRUE, echo = TRUE, warning = FALSE---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # file <- system.file("extdata", "sample1.csv", package = "MatchingPursuit") # signal <- read_csv_signals(file) # empi_class <- empi_execute ( # signal = signal, # empi_options = "-o local --gabor -i 25", # write_to_file = TRUE, # path = NULL, # file_name = "sample1.db" # ) ## ----sample1_db, include = TRUE, echo = TRUE, warning = FALSE, fig.width = 7, fig.height = 7----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # Reading a SQLite file in which all generated atom parameters are stored. file <- system.file("extdata", "sample1.db", package = "MatchingPursuit") # Create time-frequency map based on MP atoms. out <- tf_map( x = file, channel = 1, mode = "sqrt", freq_divide = 4, increase_factor = 4, display_crosses = FALSE, display_atom_numbers = TRUE, out_mode = "plot" ) ## ----plot_empi, include = TRUE, echo = TRUE, warning = FALSE------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- file <- system.file("extdata", "sample1.csv", package = "MatchingPursuit") signal <- read_csv_signals(file, col_names = "ch1") # empi_class <- empi_execute(signal = signal) # plot(empi_class) ## ----read_edf_params, include = TRUE, echo = TRUE, warning = FALSE------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- file <- system.file("extdata", "EEG.edf", package = "MatchingPursuit") # Read signal parameters and display them in a tabular form. read_edf_params(file) ## ----read_edf_signal_resampling, include = TRUE, echo = TRUE, warning = FALSE-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # Original signal eeg <- read_edf_signals(file, resampling = FALSE, from = 0, to = 10) signal_eeg <- eeg$signal sampling_frequency <- eeg$sampling_frequency sampling_frequency # Resampled signal eeg_resampled <- read_edf_signals(file, resampling = TRUE, sf_new = 64, from = 0, to = 10) signal_eeg_r <- eeg_resampled$signal sampling_frequency_r <- eeg_resampled$sampling_frequency sampling_frequency_r ## ----sampling.results, include = TRUE, echo = FALSE, warning = FALSE, fig.width = 7, fig.height = 4---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- par(mfrow = c(2, 1), pty = "m", mai = c(0.8, 0.5, 0.5, 0.5)) # Not-filtered signal (raw signal). plot( signal_eeg[, 1], type = "l", panel_first = grid(), main = "Original signal (256 Hz), channel #1", xlab = "sample points", ylab = "", col = "blue" ) # Signal after filtering. plot( signal_eeg_r[, 1], type = "l", panel_first = grid(), main = "Signal after downsampling (64 Hz), channel #1", xlab = "sample points", ylab = "", col = "blue" ) par(old_par) ## ----eeg_montage, include = TRUE, echo = TRUE, warning = FALSE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # Pairs of signals for bipolar montage (so called "double banana"). pairs <- list( c("Fp2", "F4"), c("F4", "C4"), c("C4", "P4"), c("P4", "O2"), c("Fp1", "F3"), c("F3", "C3"), c("C3", "P3"), c("P3", "O1"), c("Fp2", "F8"), c("F8", "T4"), c("T4", "T6"), c("T6", "O2"), c("Fp1", "F7"), c("F7", "T3"), c("T3", "T5"), c("T5", "O1"), c("Fz", "Cz"), c("Cz", "Pz") ) # Make the bipolar montage. eeg_m <- eeg_montage(eeg, montage_type = c("bipolar"), bipolar_pairs = pairs) signal_eeg_m <- eeg_m$signal # Original signal (first 6 rows, first 6 channels). signal_eeg[1:6, 1:6] # Signal after banana montage (first 6 rows, first 6 channels). signal_eeg_m[1:6, 1:6] ## ----eeg_filtering, include = TRUE, echo = TRUE, warning = FALSE--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # Filter parameters that will be used (quite typical in filtering EEG signals). fc <- filters_coeff( sf = sampling_frequency, notch = c(49, 51), lowpass = 40, highpass = 1, ) # Filtering input signals. signal_eeg_m_f <- signal_eeg_m for (m in 1:ncol(signal_eeg_m)) { signal_eeg_m_f[, m] = signal::filtfilt(fc$notch, signal_eeg_m[, m]) # 50Hz notch filter signal_eeg_m_f[, m] = signal::filtfilt(fc$lowpass, signal_eeg_m_f[, m]) # Low pass IIR Butterworth signal_eeg_m_f[, m] = signal::filtfilt(fc$highpass, signal_eeg_m_f[, m]) # High pass IIR Butterwoth } ## ----no_filtering_and_filtering_plot, include = TRUE, echo = FALSE, warning = FALSE, fig.width = 7, fig.height = 4------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ch <- 1 par(mfrow = c(2, 1), pty = "m", mai = c(0.8, 0.5, 0.5, 0.5)) # Not-filtered signal (raw signal). plot( signal_eeg_m[, ch], type = "l", panel_first = grid(), main = paste(colnames(signal_eeg_m)[ch], " (raw signal, channel #1)", sep = ""), xlab = "sample points", ylab = "", col = "blue" ) # Signal after filtering. plot( signal_eeg_m_f[, ch], type = "l", panel.first = grid(), main = paste(colnames(signal_eeg_m)[ch], " (filtered signal, channel #1)", sep = ""), xlab = "sample points", ylab = "", col = "blue" ) par(old_par) ## ----eeg_empi_execute, include = TRUE, echo = TRUE, warning = FALSE, fig.width = 7, fig.height = 7----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # The empi_options parameter is NULL, so the EMPI program is # run with the parameters "-o local --gabor -i 50" # sig <- list(signal_eeg_m_f, sampling_frequency) # names(sig) <- c("signal", "sampling_frequency") # empi_class <- empi_execute ( # signal = sig, # empi_options = NULL, # write_to_file = TRUE, # path = NULL, # file_name = "EEG_bipolar_filtered.db" # ) ## ----eeg_tf_map, include = TRUE, echo = TRUE, warning = FALSE, fig.width = 7, fig.height = 7----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # Reading a SQLite file where all the generated atom's parameters are stored. file <- system.file("extdata", "EEG_bipolar_filtered.db", package = "MatchingPursuit") # Generate time-frequency map based on MP atoms. out <- tf_map( x = file, channel = 2, mode = "sqrt", increase_factor= 8, display_crosses = TRUE, display_atom_numbers = FALSE, out_mode = "plot" ) ## ----plot_eeg_filt, include = TRUE, echo = TRUE, warning = FALSE, fig.width = 7, fig.height = 7-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- temp <- eeg_m temp$signal <- signal_eeg_m_f plot( x = temp, begin = 0, end = 10, panel_height = NULL, rainbow = FALSE, bg_colour = "white", txt_col = "blue", zero_line = TRUE, main = "EEG.edf file after banana montage and after filtering" ) ## ----plot_eeg_no_filt, include = TRUE, echo = TRUE, warning = FALSE, fig.width = 7, fig.height = 7----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- temp <- eeg_m temp$signal <- signal_eeg_m plot( x = temp, begin = 0, end = 10, panel_height = NULL, rainbow = FALSE, bg_colour = "white", txt_col = "blue", zero_line = TRUE, main = "EEG.edf file after banana montage and after filtering" ) ## ----read_ecg_signals, include = TRUE, echo = TRUE, warning = FALSE------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ file <- system.file("extdata", "00001_lr.hea", package = "MatchingPursuit") out_ecg <- read_ecg_signals(file) head(out_ecg$signals) out_ecg$sampling_frequency out_ecg$lead_names out_ecg$record_name ## ----ecg_signal, include = TRUE, echo = TRUE, warning = FALSE------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ # Create a list compatible with the empi_execute() function. signal <- list( signal = data.frame(out_ecg$signal), sampling_frequency = out_ecg$sampling_frequency ) str(signal) ## ----ecg_empi_execute, include = TRUE, echo = TRUE, warning = FALSE------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ # empi_class <- empi_execute ( # signal = signal, # write_to_file = TRUE, # path = NULL, # file_name = "00001_lr.db" # ) ## ----00001_lr, include = TRUE, echo = TRUE, warning = FALSE, fig.width = 7, fig.height = 7------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # Reading a SQLite file in which all generated atom parameters are stored. file <- system.file("extdata", "00001_lr.db", package = "MatchingPursuit") # Create time-frequency map based on MP atoms. out <- tf_map( x = file, channel = 2, increase_factor = 8 ) ## ----plot_ecg, include = TRUE, echo = TRUE, warning = FALSE, fig.width = 7, fig.height = 7------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- plot( x = out_ecg, begin = 0, end = 10, panel_height = 1, zero_line = FALSE, small_squares = TRUE ) ## ----chirp_def, include = TRUE, echo = FALSE, warning = FALSE------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ n <- 1280 f <- 128 t1 = n / f t <- seq(from = 0, to = n - 1, by = 1) / f g1 <- gabor_fun(n, f, mean = 2, phase = 0, sigma = 1, frequency = 50, normalization = F) g2 <- gabor_fun(n, f, mean = 8, phase = 0, sigma = 1.5, frequency = 25, normalization = F) g3 <- gabor_fun(n, f, mean = 2, phase = 0, sigma = 2, frequency = 30, normalization = F) g4 <- gabor_fun(n, f, mean = 7, phase = 0, sigma = 0.5, frequency = 15, normalization = F) imp <- rep(0, n) imp[n / 2] <- 4 sine <- 0.2 * sin(2 * pi * 3 * t) chirp <- signal::chirp(t = t, f0 = 0, t1 = t1, f1 = 50, form = c("linear"), phase = 0) signal <- g1$gabor + g2$gabor + g3$gabor + g4$gabor + imp + chirp + sine ## ----chirp_plot, include = TRUE, echo = FALSE, warning = FALSE, fig.width = 7, fig.height = 7---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- par(mfcol = c(8, 1), pty = "m", mai = c(0.2, 0.1, 0.2, 0.1)) ylim <- c(-2, 2) plot(t, signal, ylim = ylim, xaxt = "s", yaxt = "n", bty = "o", col = "blue", type = "l", xlab = "", ylab = "", main = "The sum of the below functions") plot(t, g1$gabor, ylim = ylim, xaxt = "n", yaxt = "n", bty = "o", col = "brown", type = "l", xlab = "", ylab = "", main = "Gabor: f = 50Hz, mean = 2, sigma = 1, phase = 0") plot(t, g2$gabor, ylim = ylim, xaxt = "n", yaxt = "n", bty = "o", col = "brown", type = "l", xlab = "", ylab = "", main = "Gabor: f = 25Hz, mean = 8, sigma = 1.5, phase = 0") plot(t, g3$gabor, ylim = ylim, xaxt = "n", yaxt = "n", bty = "o", col = "brown", type = "l", xlab = "", ylab = "", main = "Gabor: f = 30Hz, mean = 2, sigma = 2, phase = 0") plot(t, g4$gabor, ylim = ylim, xaxt = "n", yaxt = "n", bty = "o", col = "brown", type = "l", xlab = "", ylab = "", main = "Gabor: f = 15Hz, mean = 7, sigma = 0.5, phase = 0") plot(t, imp, ylim = ylim, xaxt = "n", yaxt = "n", bty = "o", col = "brown", type = "l", xlab = "", ylab = "", main = "Unit impulse") plot(t, sine, ylim = ylim, xaxt = "n", yaxt = "n", bty = "o", col = "brown", type = "l", xlab = "", ylab = "", main = "Sine wave: 3 Hz") plot(t, chirp, ylim = ylim, xaxt = "n", yaxt = "n", bty = "o", col = "brown", type = "l", xlab = "", ylab = "", main = "Linear-frequency chirp (0Hz - 50Hz)") par(old_par) ## ----chirp_plot_tf, include = TRUE, echo = TRUE, warning = FALSE, fig.width = 7, fig.height = 6-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- file <- system.file("extdata", "sample2.db", package = "MatchingPursuit") out <- tf_map( x = file, channel = 1, mode = "sqrt", freq_divide = 1, increase_factor= 4, display_crosses = TRUE, display_atom_numbers = FALSE, out_mode = "plot", plot_signals = FALSE ) ## ----Gabor_fun, include = TRUE, echo = FALSE, fig.width = 7, fig.height = 5, fig.align = 'center'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ N <- 512 fs <- 256 # normalization = T --> signal's norm = 1 par(mfrow = c(2,2), pty = "m", mai = c(0.4, 0.4, 0.3, 0.2)) n <- 4 sigmas <- c(0.5, 0.2, 0.8, 0.5) frequencies <- c(14, 8, 4, 1) phases <- c(0, 1, 1.5, -2) means = c(0.5, 0.8, 1, 1.5) s <- rep(0, N) for (i in c(1:n)) { sigma <- sigmas[i] frequency <- frequencies[i] phase <- phases[i] mean <- means[i] main <- latex2exp::TeX(paste( "$\\mu=$", means[i], ", ", "$\\sigma=$", sigmas[i], ", ", "$\\f=$", frequencies[i], ", ", "$\\phi=$", phases[i], sep = "" ) ) gb <- gabor_fun(N, fs, mean, phase, sigma, frequency, normalization = F) plot( gb$t, gb$gauss, type="l", ylim = c(-1, 1), col = "red", xlab= "", ylab= "", xaxt = "t", yaxt = "t", bty = "or", cex.axis = 1, lwd = 2, main = main) lines(gb$t, gb$cosinus, type = "l", col = "grey") lines(gb$t, gb$gabor, col="blue", lwd = 2) s <- s + gb$gabor } par(old_par) ## ----restore_par, include = FALSE---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- par(old_par) ## ----read_dict, include = TRUE, echo = TRUE, warning = FALSE------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- sig_file <- system.file("extdata", "sample3.csv", package = "MatchingPursuit") sample3 <- read_csv_signals(sig_file, col_names_in_csv = TRUE) signal <- sample3$signal sf <- sample3$sampling_frequency duration <- nrow(sample3$signal) / sf xml_file <- system.file("extdata", "sample3_dict.xml", package = "MatchingPursuit") atoms_dict <- read_dict( xml_file, sf, duration, verbose = TRUE) ## ----topk_atoms, include = TRUE, echo = TRUE, warning = FALSE------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ dict_topk <- topk_atoms( atoms_dict = atoms_dict, signal = signal, sf = sf, topk = 5000, verbose = TRUE ) ## ----omp_execution, include = TRUE, echo = TRUE, warning = FALSE--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- fit <- omp_execute( dictionary = dict_topk, signal = signal, sf = sf, n_nonzero_coefs = 50, verbose = TRUE ) ## ----omp_plot, include = TRUE, echo = TRUE, warning = FALSE, fig.width = 7, fig.height = 7------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- plot(fit, channel = 3) ## ----run_omp_pipline, include = TRUE, echo = TRUE, warning = FALSE, fig.width = 7, fig.height = 7------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ out <- run_omp_pipeline( sig_file = sig_file, col_names_in_csv = TRUE, xml_file = xml_file, topk = 5000, n_nonzero_coefs = 50, verbose = FALSE ) class(out)