1
votes

Statement of Problem:

  1. I have an array M with m rows and n columns. The array M is filled with non-zero elements.

  2. I also have a vector t with n elements, and a vector omega with m elements.

  3. The elements of t correspond to the columns of matrix M.

  4. The elements of omega correspond to the rows of matrix M.

Goal of Algorithm:

Define chi as the multiplication of vector t and omega. I need to obtain a 1D vector a, where each element of a is a function of chi.

Each element of chi is unique (i.e. every element is different).

Using mathematics notation, this can be expressed as a(chi)

Each element of vector a corresponds to an element or elements of M.

Matlab code:

Here is a code snippet showing how the vectors t and omega are generated. The matrix M is pre-existing.

[m,n] = size(M);
t = linspace(0,5,n);
omega = linspace(0,628,m);

Conceptual Diagram:

This appears to be a type of integration (if this is the right word for it) along constant chi.

Diagram

Reference:

Link to reference

The algorithm is not explicitly stated in the reference. I only wish that this algorithm was described in a manner reminiscent of computer science textbooks!

Looking at Figure 11.5, the matrix M is Figure 11.5(a). The goal is to find an algorithm to convert Figure 11.5(a) into 11.5(b).

It appears that the algorithm is a type of integration (averaging, perhaps?) along constant chi.

3
From the link you have given, I think that to get from figure 11.5(a) to 11.5(b) you should make something called Gabor Transform. Read the page 190 of the book you shared with us. This algorithm seems to be pretty involved. I suggest you try to understand it, and also to consult related pages in the matlab webpage: (1) search 'gabor transform matlab' in google. (2) check the webpage, mathworks.com/matlabcentral/fileexchange/… . This link from Matlab 'file exchange' is promising (4/5 stars from voters)! I think it could work pretty fast for you! Good luck!jespestana
@jespestana: Yes, I've written my own version of the Gabor transform, and I've used it to generate something similar to Figure 11.5(a), which is a 2D matrix as a 2D spectrum. Now that the Gabor transform has been calculated, the 2D spectrum needs to be collapsed into a 1D spectrum as noted on pg. 190. I still don't know if the spectral collapsing can be done with the Gabor transform.Nicholas Kinar
I think you should try to find another book. I do not understand why they use A(chi) without describing it... Anyway, if you want to integrate using the trapezoidal rule check the function trapz(t,y). Sorry, but I do not know anything about the Gabor transform, let alone about collapsing the data. If you could give us the exact formula you want to implement, it would be easier for us to suggest a solution.jespestana
I agree completely with you. If I had the exact formula or even a nice algorithm listing, it would be much easier. I will try to experiment some more and see where this leads me. Thanks for your help.Nicholas Kinar

3 Answers

2
votes

It appears to me that reshape is the matlab function you need to use. As noted in the link:

B = reshape(A,siz) returns an n-dimensional array with the same elements as A, but reshaped to siz, a vector representing the dimensions of the reshaped array.

That is, create a vector siz with the number m*n in it, and say A = reshape(P,siz), where P is the product of vectors t and ω; or perhaps say something like A = reshape(t*ω,[m*n]). (I don't have matlab here, or would run a test to see if I have the product the right way around.) Note, the link does not show an example with one number (instead of several) after the matrix parameter to reshape, but I would expect from the description that A = reshape(t*ω,m*n) might also work.

2
votes

You should add a pseudocode or a link to the algorithm you want to implement. From what I could understood I have developed the following code anyway:

M = [1 2 3 4; 5 6 7 8; 9 10 11 12]' % easy test M matrix
a = reshape(M, prod(size(M)), 1)    % convert M to vector 'a' with reshape command

[m,n] = size(M);                    % Your sample code
t = linspace(0,5,n);                % Your sample code
omega = linspace(0,628,m);          % Your sample code 

for i=1:length(t)
    for j=1:length(omega)           % Acces a(chi) in the desired order
        chi = length(omega)*(i-1)+j;
        t(i)                        % related t value
        omega(j)                    % related omega value
        a(chi)                      % related a(chi) value
    end
end

As you can see, I also think that the reshape() function is the solution to your problems. I hope that this code helps,

0
votes

The basic idea is to use two separate loops. The outer loop is over the chi variable values, whereas the inner loop is over the i variable values. Referring to the above diagram in the original question, the i variable corresponds to the x-axis (time), and the j variable corresponds to the y-axis (frequency). Assuming that the chi, i, and j variables can take on any real number, bilinear interpolation is then used to find an amplitude corresponding to an element in matrix M. The integration is just an averaging over elements of M.

The following code snippet provides an overview of the basic algorithm to express elements of a matrix as a vector using the spectral collapsing from 2D to 1D. I can't find any reference for this, but it is a solution that works for me.

% Amp = amplitude vector corresponding to Figure 11.5(b) in book reference
% M = matrix corresponding to the absolute value of the complex Gabor transform 
% matrix in Figure 11.5(a) in book reference
% Nchi = number of chi in chi vector
% prod = product of timestep and frequency step
% dt = time step
% domega = frequency step
% omega_max = maximum angular frequency
% i = time array element along x-axis
% j = frequency array element along y-axis
% current_i = current time array element in loop
% current_j = current frequency array element in loop
% Nchi = number of chi
% Nivar = number of i variables
% ivar = i variable vector

% calculate for chi = 0, which only occurs when
% t = 0 and omega = 0, at i = 1
av0 = mean( M(1,:) );           
av1 = mean( M(2:end,1) );       
av2 = mean( [av0 av1] );    
Amp(1) = av2;                  

% av_val holds the sum of all values that have been averaged
av_val_sum = 0;

% loop for rest of chi 
for ccnt = 2:Nchi                       % 2:Nchi

    av_val_sum = 0;                     % reset av_val_sum 
    current_chi = chi( ccnt );          % current value of chi

    % loop over i vector
    for icnt = 1:Nivar                  % 1:Nivar

        current_i = ivar( icnt );
        current_j = (current_chi / (prod * (current_i - 1))) + 1;
        current_t = dt * (current_i - 1);
        current_omega = domega * (current_j - 1);

        % values out of range
        if(current_omega > omega_max)
            continue;
        end

        % use bilinear interpolation to find an amplitude
        % at current_t and current_omega from matrix M
        % f_x_y is the bilinear interpolated amplitude

        % Insert bilinear interpolation code here

        % add to running sum
        av_val_sum = av_val_sum + f_x_y;
    end % icnt loop

        % compute the average over all i
        av = av_val_sum / Nivar;

        % assign the average to Amp
        Amp(ccnt) = av;

end % ccnt loop