frequencies in Julia's real FFT - julia

I'm using Julia's FFT implementation to perform a 2D real FFT on a couple of arrays but I can't be sure of the order of the frequencies in the output. Consider the MWE
N=64
U = rand(Float64, N, N);
FFTW.set_num_threads(2)
prfor = plan_rfft(U, (1,2), flags=FFTW.MEASURE);
size(prfor*U)
The output is an array of size (33, 64).
Julia doesn't have a rfftfreq function like Numpy does, and the fact that Julia's output is different from Numpy's fft.rfftn default output makes me not want to use Numpy's default here. I read the documentation but it's not clear how the frequencies are organized just by reading that.
Is there anywhere that tells us the order of the frequencies?

I'm not sure what you are seeking exactly, but if you use DSP.jl, its util.jl file probably has what you may need:
https://github.com/JuliaDSP/DSP.jl/blob/master/src/util.jl
"""
rfftfreq(n, fs=1)
Return discrete fourier transform sample frequencies for use with
`rfft`. The returned Frequencies object is an AbstractVector
containing the frequency bin centers at every sample point. `fs`
is the sample rate of the input signal.
"""

Related

compute the tableau's nonbasic term in SCIP separator

In traditional Simplex Algorithm notation, we have x at the current basis selection B as so:
xB = AB-1b - AB-1ANxN. How can I compute the AB-1AN term inside a separator in SCIP, or at least iterate over its columns?
I see three helpful methods: getLPColsData, getLPRowsData, getLPBasisInd. I'm just not sure exactly what data those methods represent, particularly the last one, with its negative row indexes. How do I use those to get the value I want?
Do those methods return the same data no matter what LP algorithm is used? Or do I need to account for dual vs primal? How does the use of the "revised" algorithm play into my calculation?
Update: I discovered the getLPBInvARow and getLPBInvRow. That seems to be much closer to what I'm after. I don't yet understand their results; they seem to include more/less dimensions than expected. I'm still looking for understanding at how to use them to get the rays away from the corner.
you are correct that getLPBInvRow or getLPBInvARow are the methods you want. getLPBInvARow directly returns you a of the simplex tableau, but it is not more efficient to use than getLPBInvRow and doing the multiplication yourself since the LP solver needs to also compute the actual tableau first.
I suggest you look into either sepa_gomory.c or sepa_gmi.c for examples of how to use these methods. How do they include less dimensions than expected? They both return sparse vectors.

How can OpenMDAO be used to solve a linear system of equations without inverting the A matrix?

I have a system of equations that is in the form:
Ax = b
Where A and b are a mixture of known states and state rates derived from earlier components and x is a vector of four yet unknown state rates. I've used Matlab to linearise the problem, all I need to do now is to create some components to find x. However, the inverse of A is large in terms of the number of variables in each index, so I can't just turn these into a straightforward linear equation. Could someone suggest a route to go?
I don't fully understand what you mean by "the inverse of A is large in terms of the number of variables in each index", however I think mean that the inverse of A is to larger and dense to compute and store in memory.
OpenMDAO or not, When you run into this situation you are forced to use an iterative linear solver such as gmres. So that is broadly the approach that is needed here too.
OpenMDAO does have a LinearSystemComponent that you can use as a rough blueprint here. However, it does compute a factorization and store it which is not what you want. Regardless, it gives you the blueprint for how to represent a linear system as an implicit component in OpenMDAO.
Broadly, you have to think of defining a linear residual:
R = Ax-b = 0
Your component will have two inputs A and b, and and one output x.
The two key methods here are apply_nonlinear and solve_nonlinear. I realize that the word nonlinear in the method names is confusing. OpenMDAO assumes that the analysis is nonlinear. In your case it happens to be linear, but you use the nonlinear methods all the same.
I will assume that, although you can't compute/store [A] inverse you can compute/store A (perhaps in a sparse format). In that case you might pass the sparse data array of [A] as the input and fill the sparse matrix as needed from that.
the apply_nonlinear method would look like this:
def apply_nonlinear(self, inputs, outputs, residuals):
"""
R = Ax - b.
Parameters
----------
inputs : Vector
unscaled, dimensional input variables read via inputs[key]
outputs : Vector
unscaled, dimensional output variables read via outputs[key]
residuals : Vector
unscaled, dimensional residuals written to via residuals[key]
"""
residuals['x'] = inputs['A'].dot(outputs['x']) - inputs['b']
The key to your question is really the solve_nonlinear method. It would look something like this (using scipy gmres):
def solve_nonlinear(self, inputs, outputs):
"""
Use numpy to solve Ax=b for x.
Parameters
----------
inputs : Vector
unscaled, dimensional input variables read via inputs[key]
outputs : Vector
unscaled, dimensional output variables read via outputs[key]
"""
x, exitCode = gmres(inputs['A'], inputs['b'])
outputs['x'] = x

A distribution that returns only a single floating point value in Julia?

I have some simulation code that draws from various distributions. To facilitate some sanity checks, is there a way to make a Distribution that returns only a single floating-point value? That way I can test without changing code that calls rand on the distribution. Right now I'm doing something like, supposing I want to always get the value 2.2
mydist = Normal(2.2, 0.000001)
But this seems kind of silly. Of course, if I change the variance to 0 I get an error.
The Distibutions.jl docs have an extends section, so you can see what needs to be defined. An incomplete implementation of a new Distribution starts
using Distributions
struct OneFloatDistribution <: Distribution{Univariate,Continuous}
v::Float64
end
Base.rand(x::OneFloatDistribution) = x.v
You can get down to two possible floating point numbers with Uniform(1.0,nextfloat(1.0))

Calculate derivative of an array with apache-commons-math

Good Morning,
I have an array with about 3000 double values, I need to find all local minimum and maximum, for this I'm interested to first and second derivative, what's best way to achieve this with Apache Commons Math? My trouble is that I'm starting directly from the array, not from a function like sin(x).
Thanks
With just an array you wont be able to find a min/max.
If the array was calcualted from a known function, then you could differentiate it numerically (just calculate at X and X + epsilon, and divide by epsilon, assuming that there's a single parameter that you're differentating with respect to).
Alternatively, is the array actually the list of coefficients of a big polynomial? If so, then the same approach might work.

Amplitude and Phase of FFT

I have a sound function I am trying to break up into sines/cosines. So I resorted to Fast Fourier Transformation. By using the fft(y,inverse=FALSE) function I was able to convert the time domain of the sound into the frequency doman. The output is complex. I read that in order to convert this output which is in imaginary form and weed out the necessary information, which are the amplitude and the phase of A(v)cos(2*pi*v+P), one must use the abs() of the output to get the amplitude; however I am having difficulty finding the R function that gets us the phase. In MATLAB, the angle() function returns the phases of the FFT. What is the respective function in R to find the phase??
Update
Thank you for the suggestions guys; still expericieng an issue. I am running FFT on a simple function to test to see if it works. My function is y=cos(2*pi*(seq(0,10,by=.01)*(1/5)+7.5).
So the frequency is 1/5 with a phase shift of 7.5.
y=cos(2*pi*(seq(0,10,by=.01)*(1/5)+7.5)
fty=(y,inverse=F)
plot(abs(fty),xlim=c(0,10),type="l")
angle=atan2(Im(fty), Re(fty))
> angle[3]
[1] 1.222766
When I plot the series, the amplitude is peaking at a frequency value of 3 and the angle function (which should give me my phase at the frequency at which amplitude peaks at) is giving me a phase of 1.2. What am I doing wrong?
You might find that the atan2 function does what you want. You would give it the imaginary and real parts of the value, since the prototype is atan2(y, x). So you could do:
angle = atan2(Im(value), Re(value));

Resources