![]() cutoff is the normalized cutoff frequency of the input signal, specified as a fraction of the Nyquist. y interp (x,r,n,cutoff) specifies two additional values: n is half the number of original sample values used to interpolate the expanded signal. Also, if you do get it to work, but it doesn't speed things up much, I'd be very interested to know that, so please post the result here. y interp (x,r) increases the sample rate of input signal x by a factor of r. Let me know if you can't get it to work and I'll try and put together something more explicit once I get home. You may be able to simply replace with and of course, adjust the inputs to cellfun appropriately. Then the call to cellfun applies the sum function to each cell in VCell, and returns the result in A. The mat2cell function converts V to a cell column vector, where each cell contains a row of V. But I think the method I've used extends to your situation. Of course, what I've done is equivalent to sum(V, 2). VCell = mat2cell(V, ones(NumRow, 1), NumCol) It seems to me that you can get rid of the explicit loop using mat2cell and cellfun.Ī simple example of what I mean is as follows: NumRow = 4 The tic and toc statements are there simply to provide timing information and on my system the. One way of doing this in MATLAB is to use the interp1 function as follows. Having said that, since the iterations of your loop do not depend on each other, vectorization should be possible. and you want to interpolate this data on a fine grid between x0 and x1 using piecewise cubic Hermite interpolation. I'm at work and so don't have time to familiarize myself with interp1 (I've never used it before), so if the following answer is inappropriate, I apologize in advance. It will likely grow with system size due to a more efficient memory bandwidth utilization. The following version is around 20% faster on my computer for N=1000, S=10000 and TI of 10000 elements. Hence, I would suggest you transpose your matrices in your entire code, unless of course you rely on this exact data layout somewhere else for performance reasons.Įdit Because of the column layout of matrices your original code can be improved by transposing the matrices and working column-wise. If you pass V as an SxN matrix it potentially allows for more efficient parallelization of interp1, since all CPUs can access the memory in a more efficient manner. This is because MATLAB stores matrices column-wise (columns are contiguous in memory). Here you have to transpose V since interp1 interpolates within columns. If on the other hand the measurements have been taken at the same times for different values of N (T is a vector of size S, and not a matrix, or in other words all rows of T are equal) you can interpolate in one call to interp1. You might not need it - it depends on what you later do with the data. It returns a cell of vectors, so the second line makes sure that you have a matrix as output. Np.If you have, as you say, different time of measurement for all measurements (T is a matrix and not a vector), you can do what you want with one call to arrayfun as follows: VI = 1:size(V, 1), 'UniformOutput', false) Īrrayfun is similar to a loop, but since it is an internal matlab function it might be faster. Plt.legend(('Original','OP_scipy', 'OP_matlab', 'askewchan_scipy', 'OP style scipy'), loc='lower right') Set_interp = interp1d(x, y, kind='linear') # 'linear' has no effect since it's the default, but I'll plot it too: See below for a demonstration: import numpy as np ![]() For me, the results from scipy match perfectly with your results from matlab. ![]() Described in table lookup terms, the table is tab x,y. Interpolation is the same operation as table lookup. This is shown below, along with the relationship between vectors x, Y, xi, and yi. It finds values of a one-dimensional function f (x) underlying the data at intermediate points. I think that your data from scipy might be messed up somehow, because I can't reproduce your problem. The interp1 command interpolates between data points.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |