1
$\begingroup$

I have been looking at the FFT (in python) of various simple functions. Everything was working as expected, except when I take the Fourier transform of the function:

$$ f(t) = e^{-\gamma t}\cos^2\omega_1t $$

where I obtain a peak at $\omega=0$ which I would like to remove. This peak shows up in $g(t)=\cos^2(\omega_1 t)$ as well, and can be removed by subtracting the mean from the input signal. However, for $f(t)$ the exponential decay broadens the width of the peak in the Fourier spectrum and subtracting the mean does not fully remove it.

How would I go about removing the broadened peak at $\omega=0$ in $f(t)$ ?

import numpy as np
import matplotlib.pyplot as plt
from scipy import integrate

# number of points
samplingFrequency = 50

# spacing between points one second apart
samplingInterval = 1 / samplingFrequency

# begin and end time of signals
beginTime = 0
endTime = 100

# signal frequency (to find through fft)
signal1Frequency = 0.2

# time points (in terms of time step)
time = np.arange(beginTime, endTime, samplingInterval) 

# create default functions
y1 = np.cos(2*np.pi*signal1Frequency*time)

# create subplot
figure, axis = plt.subplots(3, 1, figsize=(12,14), sharex=False)
plt.subplots_adjust(hspace=0.3)

# time domain representation for y1 
axis[0].set_title('Cosine wave with a frequency of ' + str(signal1Frequency) +  ' Hz')
axis[0].plot(time, y1)
axis[0].set_xlabel('Time')
axis[0].set_ylabel('Amplitude')

# create signal to fourier transform
y3 = y1**2*np.exp(-0.1*time)

mean = np.mean(y3)

y3 = y3 - np.mean(y3)  # only removes 0Hz spike for cos squared without exp decay

# Time domain representation 
axis[1].plot(time, y3)
axis[1].set_xlabel('Time')
axis[1].set_ylabel('Amplitude')
axis[1].set_xlim([0,10])

# Frequency domain representation
fourierTransform = np.fft.fft(y3)/len(y3)      # Normalize amplitude
fourierTransform = fourierTransform[range(int(len(y3)/2))] 

tpCount     = len(y3)
values      = np.arange(int(tpCount/2))
timePeriod  = tpCount/samplingFrequency
frequencies = values/timePeriod


# Frequency domain plot
axis[2].set_title('Fourier transform depicting the frequency components')
axis[2].plot(frequencies, abs(fourierTransform))
axis[2].set_xlabel('Frequency')
axis[2].set_ylabel('Amplitude')
axis[2].set_xlim([0,1])
$\endgroup$
3
  • $\begingroup$ set_xlim([-.01, 1]). $\omega=0$ is DC by definition. $\endgroup$ Apr 18, 2023 at 14:49
  • $\begingroup$ @OverLordGoldDragon How can I remove the peak though, the peak is broadened (has a finite width) due to the exponential function and is not removed by conventional methods of subtracting the mean? $\endgroup$
    – Angus
    Apr 18, 2023 at 15:00
  • $\begingroup$ A peak has no width, it's a single point. If you mean to remove frequencies near DC, then highpass or bandreject filter. But that's just tossing out the signal, it helps to clarify your intent. $\endgroup$ Apr 18, 2023 at 15:04

1 Answer 1

2
$\begingroup$

You can run the signal through a high pass filter. The choice of filter depends on your application requirements and how much of the low frequency content you need to "remove".

Filter design is always a trade off between amplitude distortion, phase distortion, latency, causality etc.ㅤ

$\endgroup$
9
  • $\begingroup$ Thanks for your response. Just to clarify, you pass the fourier signal through the high pass filter? Also, if I want to do this for multiple signals, each with a different $\omega$ and $\gamma$, is there a specific high-pass filter you recommend. $\endgroup$
    – Angus
    Apr 18, 2023 at 15:24
  • $\begingroup$ You run the time domain signal through a high pass filter before doing the FFT. The filter needs to meet the requirements of your application (which I have no idea about). Technically the peak at DC is infinitely wide, so you can't remove it completely. It all comes down to how much you need to remove and how much "interference" with sine wave you can tolerate. $\endgroup$
    – Hilmar
    Apr 18, 2023 at 19:27
  • $\begingroup$ "peak at DC is infinitely wide, so you can't remove it completely" I don't know why you keep invoking the infinite continuous signal in every context. It's not being general, quite contrary, it's loaded with assumptions, and misleading to newcomers. We have a finite length sequence, it has a mean, and we can get rid of it. If we have a different signal model like periodic, we can work with that too. Nothing impossible about it. $\endgroup$ Apr 19, 2023 at 12:41
  • 2
    $\begingroup$ @OverLordGoldDragon: I think we have a semantics problem here. I consider a "peak" not a single frequency bin but a frequency range of increased energy like something you get from a peaking filter. So the unwanted energy is NOT just in the DC bin but it's also in the neighboring bins. Actually it's in ALL bins, but the amount decays as you move away from DC. The OP calls it "broadened peak". It's basically the shape of a 1rst order lowpass filter defined by the exponential decay. $\endgroup$
    – Hilmar
    Apr 20, 2023 at 16:32
  • 1
    $\begingroup$ It cannot be completely removed since (in frequency) the "peak" or "bump" overlaps with the part of the signal you want to keep. The exponential decay widens the line both at DC and at $2\cdot \omega_1$ and at some frequencies the two will overlap. That has nothing to do "float epsilon" or any limits in numerical precision. $\endgroup$
    – Hilmar
    Apr 21, 2023 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.