time_shift_fft: Perform a shift in time domain on fft values

View source: R/dsp_tools.r

time_shift_fftR Documentation

Perform a shift in time domain on fft values

Description

Takes already calculated values of an fft and applies the relation between a shift in time domain and a multiplication by a complex factor in the frequency domain to obtain a shifted time signal.

Usage

time_shift_fft(fft_vals, sampling, time_shift)

Arguments

fft_vals

Values of the fourier transform of a function calculated at the frequencies given by sampling$fft_freqs.

sampling

An object providing information on the sampling paramters chosen. Usually constructed by the function create.sampling.

time_shift

The desired time shift in SI units, i.e. seconds.

Value

FFT values of the same frequencies as in fft_vals, but s.t. they produce a time-shifted signal when inverse transformed.

Note

This function will work but most likely produce undesired results when applied to signals of even length that have a non-zero coefficient at Fs/2. This coefficient is required to have a purely real coefficient for the inverse transformed signal to be purely real. However, the time-shift operation will possibly multiply this coefficient by a complex factor, thus resulting in a complex (as opposed to purely real) inverse FFT.

Examples

t <- seq(0.1, 1, 0.1)
y <- sin(2*pi*t)
fft_shifted <- semg.simulatr:::time_shift_fft(
    fft_vals = fft(y) / length(y),
    sampling = semg.simulatr:::create_sampling(Fs = 10, NFFT = 10),
    time_shift = 0.2)
dev.new()
plot(t,y)
points(t,Re(fft(fft_shifted, inverse = TRUE)), col = "red")


ime-luebeck/semgsim documentation built on April 14, 2022, 11:02 p.m.