2

I have a numpy array representing magnitudes of a fourier transform, and I want to resample it logarithmically:

Lets say it was from 100hz to 10khz, and each bucket was 100hz, I want to take that discrete distribution, create a continuous distribution, and then resample that continuous distribution logarithmically (i.e. bucket 1 is 100hz to 200hz, bucket 2 is 200hz to 400hz, etc (not specifically doubling, but for any logarithmic base)).

I can definitely conceive of a manual way to do this, but I'm absolutely sure that there is a far more pythonic way of doing this in like 2 lines (and I bet you can configure even the interpolation method (linear, logarithmic, parabolic, etc), maybe even as part of numpy).

1 Answer 1

2

A possible implementation is given below. The logspace() routine from numpy creates the bucket boundaries and I subsequently draw a random index.

import random
import numpy as np

NumberOfBuckets = 10
LogGrid = np.logspace(2.0, 4.0, num=NumberOfBuckets) % 10^2 to 10^4
IntDraw = random.randint(0,NumberOfBuckets-1)
RandomInterval = [LogGrid[IntDraw], LogGrid[IntDraw+1]]
print(RandomInterval)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.