Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1D radial power spectrum issue #516

Open
alexandrefortin opened this issue Sep 11, 2024 · 2 comments
Open

1D radial power spectrum issue #516

alexandrefortin opened this issue Sep 11, 2024 · 2 comments

Comments

@alexandrefortin
Copy link

Thank you very much for providing this free library.

I tried to apply the code provided on Noise Power Pylinac documentation to some simple synthetic 2D signals including 4 spatial frequencies of equal amplitude A :

  • noise_cartesian(X,Y) = A cos(2π* f1 * X) + A cos(2π* f2 * Y) + A cos(2π* f3 * X) + A cos(2π* f4 * Y)

  • noise_radial(R) = A cos(2π* f1 * R) + A cos(2π* f2 * R) + A cos(2π* f3 * R) + A cos(2π* f4 * R)

    f1 = 0.18 mm-1
    f2 = 0.32 mm-1
    f3 = 0.45 mm-1
    f4 = 0.61 mm-1

I was expecting to find 4 peaks of equal power on the corresponding 1D radial power spectrum :

Figure_1

However I had two issues :

  1. The peaks power are not equal (it seems to decrease as 1/f)
  2. The peaks frequencies are shifted from the input values

Am I missing something ? By definition the power spectrum is expected to give a power proportional to the squared amplitude, am I wrong ?

Here is my modified code : PyLinac_SelfGeneratedNoise.txt

Thank you for your reply.

@alexandrefortin
Copy link
Author

alexandrefortin commented Sep 13, 2024

Complement to my previous post

I tried to slightly modify the core/nsp.py file by removing the common normalization over the number of pixels bin in the radial_average. By doing so, I got the expected power for the peaks (however their frequency still seems shifted downward on the 1D spectrum, whereas the values measured on the 2D spectrum are correct).

image

@alexandrefortin
Copy link
Author

I think I found the issue origin for the frequency shift.

It seems to be a simple scaling problem, as the highest frequency bin is located in the image diagonal, so a √2 factor is to be applied to the axis and to the average power values :
scalingFactor = 1. / mmPixel_Size / math.sqrt(2)
x_vals = np.arange(len(nps1d_1))/len(nps1d_1) * scalingFactor

With this, the output frequencies match the input :
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant