# Generating a time domain signal using the fundamental frequencies

I currently have the power spectrum (in dB) of a signal through which I obtained the fundamental frequencies and amplitudes. My question is: how to generate a time domain signal using these amplitudes and frequencies (using C++ for example)?

## 1 Answer

No way. You cannot recover a time domain signal from its fundamental frequency. Although, it is not clear what does a plural means here, "the fundamental frequencies and amplitudes", so maybe I am not quite understanding you.

Also, the power spectral density (PSD) alone, whether in dB or else, is not sufficient to recover a time domain signal: you need an energy spectral density for this deed. Citing a Wikipedia article:

The above definition of energy spectral density is suitable for transients (pulse-like signals) whose energy is concentrated around one time window; then the Fourier transforms of the signals generally exist.

The Fourier transform of the signal is what you need in order to recover a time domain signal, because the PSD lacks the phase information. Moreover, a periodogram, if it is what you hint by mentioning "fundamental frequency", does embrace averaging, either in time or frequency, which makes the periodogram still less suitable for a time domain signal recovery.

Although it seems that your question is about PSD, you may be interested in retrieving phase information from energy spectral density. There is a number of techniques, the classical one is use of the Kramers Kronig relations for analytical signal. See also a review of three techniques (including KK) used in optical measurements, in Deep learning as phase retrieval tool for CARS spectra. Section 2.2 of this article presents the formula for deducing the phase from the squared modulus (formula 15), with stipulations made about a noise and discrete nature of measurements.

A word about implementation: in order to write a C++ implementation, you need a thorough understanding of signal processing algorithms. Searching github.com for open source implementations of phase retrieval techniques, I've found a Python implementation of phase retrieval for Raman spectroscopy, with Jupyter notebook, explaining the implementation details, see CRIKit2: Hyperspectral imaging toolkit. You may browse this presentation, at least out of curiosity.

• The signal contain about three fundamental frequencies. Fortunately, I do have the FFT of the signal using MATLAB. The number of samples for the time domain signal (from t=0 to t=26.24sec) is 3281 and so fft(signal) yields a 1-dimensional array of length 3281. The sample frequency used is 125Hz. From all of this, how to know which element in the array [fft(signal)] corresponds to which frequency? Then, how to construct a time domain signal using only the fundamental frequencies only? Thank you in advance – William Dec 20 '20 at 1:07
• First, please explain your terminology. "Sample frequency": do you mean sampling frequency? Now, the Wiki article (en.wikipedia.org/wiki/Fundamental_frequency) defines the fundamental frequency as the lowest frequency of a periodic waveform. Do you mean "the fundamental frequency" in accordance with the Wiki definition? If yes, does your signal data represent one period of a periodic waveform? If also yes, which of your three fundamental frequencies is the lowest frequency of this periodic waveform and why you call the other ones "fundamental"? – V.V.T Dec 20 '20 at 11:42
• Second, even if your signal data represents one period of a periodic waveform, you still cannot reconstruct a time domain signal from a power spectrum, because a power spectral distribution lacks phase information. But you can retrieve a time domain signal from the FFT array with the help of MATLAB's ifft function, see MATLAB help, similar to how you calculated FFT with the fft function, but only in inverse direction. – V.V.T Dec 20 '20 at 11:42
• Third, the frequency bin size and the mapping of bins to frequency values can be computed with your parameters. The sampling frequency is Fs = 3280/26.24 ≈ 125Hz. The bin size is the sampling frequency divided by the number of samples, Δf = Fs/N = 3280/26.24/3280 = 1/26.24 ≈ 0.0381Hz. The k-th bin frequency is k·Δf. The highest frequency depends on whether your FFT is a double-sided or single-sided spectrum. Your FFT array size is equal to the number of samples, therefore, your FFT is double-sided spectrum, right? If this is the case, the highest frequency is at bin #(k/2): Fs/2 - Fs/N. – V.V.T Dec 20 '20 at 11:44
• And your "power spectrum (in dB) of a signal" is ten-times decimal logarithms of squared magnitudes of FFT, am I right? – V.V.T Dec 20 '20 at 11:59