[Python] List construction by concatenation after FFT [closed]

Discussão em 'Python' iniciado por Stack, Março 12, 2025.

  1. Stack

    Stack Membro Participativo

    Is there a simpler Way to construct frequency components after FFT?

    I am computing the FFT of a signal and normalizing it as follows:

    import numpy as np
    from scipy.fftpack import fft

    # By calculating FFT...
    Y = fft(y) / n # FFT computing and normalization
    # Constructing a new list with one-sided frequency range
    Y = [Y[0]] + [2 * Y for i in range(1, n//2)]


    This works correctly, but I initially attempted a more compact form:

    Y = [Y[0]] + [2 * Y[range(1, n//2)]] # This does NOT work


    which will actually increase to 2D instead of concatenating indices from 0 to 1:n//2.

    My question is: Is there a simpler or more Pythonic way to achieve this one-sided frequency range construction? Ideally, something cleaner than my working solution while maintaining efficiency.

    Continue reading...

Compartilhe esta Página