[Python] How can I correct a signal data using fft

Discussão em 'Python' iniciado por Stack, Junho 19, 2025.

  1. Stack

    Stack Membro Participativo

    I have a project where I get a npy-file of a signal and when you reconstruct it in an image, it shows the inside of a scotch tape. The file is an 4D-array consisting out of an t-, k-, x- and y-axis. I made the image using Fast Fourier Transform but it is not very detailled. My TA's told me I can correct this by using fft2 on the x- and y-axis and than fftshift on the same axes again to construct it around zero. Then I need to delete the areas around zero on (again) the same exes because those cause the most abberations. I tried some things seen in the code below, but I cannot get the correct image anymore which was constructed by transforming the k-axis, just some weird pixels. Either there is something wrong with my method or I am going crazy. So what can I do to correct my image by using fft?

    # original image
    z = np.fft.rfft(raw_data[0, :, :, 0], axis = 0)
    data_im = np.abs(z)

    plt.imshow(data_im, cmap='gray', aspect='auto', vmin=0, vmax=400)
    plt.ylabel("Depth (z)")
    plt.show()

    # filtered image
    everything_in_k_values = np.fft.fft2(raw_data[0, :, : :], axes=(-2,-1)) # (k, x, y) -> (k, kx, ky), just fft over last two axes, so x and y, goes automatocally
    data_shift = np.fft.fftshift(everything_in_k_values[:, :, :], axes=(-2,-1)) # fft over data that is now all k_values, so we get x,y and z,
    data_shift[0, -1:5, -1:5] = 0 # delete around zero so this does not influence intensity
    data_filt = np.fft.fft(data_shift[:, :, :]) # apply fft over k_z an k_x

    plt.imshow(np.log(np.abs(data_filt[:, :, 0])), cmap='gray', aspect='auto', vmin=0, vmax=30) # just using z and x for image
    plt.ylabel("Depth (z)")
    plt.show()

    Continue reading...

Compartilhe esta Página