VEWOXIC / FITS

FITS: Frequency Interpolation Time Series Analysis Baseline
Apache License 2.0
106 stars 12 forks source link

`self.length_ratio` for energy compensation #1

Closed Hank0626 closed 5 months ago

Hank0626 commented 6 months ago

I've been reviewing the code in the FITS repository, and I'd like to discuss the handling of the temporal length of the tensor low_xy. Specifically, I am referring to this line:

https://github.com/VEWOXIC/FITS/blob/220afee504736f76229688737a01bb2af54b4bf7/models/FITS.py#L55

My understanding is that this line performs a scalar multiplication of the tensor low_xy, but it does not seem to alter its temporal length. It appears to me that the adjustment of the temporal length of low_xy is actually handled by a different section of the code, as shown here:

https://github.com/VEWOXIC/FITS/blob/220afee504736f76229688737a01bb2af54b4bf7/models/FITS.py#L52

I believe this interpolation is where the temporal length change is compensated for. Could you please confirm if my understanding is correct, or provide further clarification if I've misunderstood the code's functionality?

Thank you for your time and for the work on this project.

VEWOXIC commented 5 months ago

Thanks for asking.

As you mentioned, the Line 52 is just to create a placeholder for the spectrum of interpolated time series. As you can see, we just create a new zero tensor of the specified shape. It involves no scaling and energy compensation.

However, in Line 55, we perform the scaling to compensate the amplitude change caused by the changing of time series length. Specifically, in spectral analysis, amplitude is usually proportional to the number of times a frequency component appears in the signal. The Fourier transform, an energy-conserving transformation, redistributes the energy of a time-domain signal into the frequency domain. As the signal length increases (here, the number of cycles), the energy (or amplitude) of the same frequency component increases because this frequency component occurs more frequently in the signal. For instance, a Fourier transform of a 100-point segment (5 cycles) of a sine wave with a period of 20 points would result in a peak at frequency 5 with an amplitude of 250, but transforming a 200-point segment (10 cycles) would yield a peak at frequency 10 with an amplitude of 500. Compensation for this energy increase due to sequence length is achieved by multiplying by a scalar, namely (output length/input length).

Hope above explanation can address your question. You may also write a simple Python script to test this claim.

VEWOXIC commented 5 months ago

Hi, I have updated the misleading comment in Line 55, please check.

Hank0626 commented 5 months ago

Thanks! it is clear to me now.

Hank0626 commented 5 months ago

By the way, the following two lines of code confuse me: https://github.com/VEWOXIC/FITS/blob/aba1737ce1efcaf11d3f36e23e789fcc33207552/models/FITS.py#L42 https://github.com/VEWOXIC/FITS/blob/aba1737ce1efcaf11d3f36e23e789fcc33207552/models/FITS.py#L43

I think the code in line 42 is meaningless due to the fact that the value in line 43 only takes the frequency before self.dominance_freq.

VEWOXIC commented 5 months ago

Yeah, seems so. Anyway, I did not change it if it works properly XD.

If there is no further question, I will close this issue.