Clear Filters
Clear Filters

How to change elements of only the pages of a matrix

1 view (last 30 days)
Hey everyone, I am trying to implement beamforming with adaptive weights and I am using subarray avareging in order to make the calculations for my spatial covariacne array more managable. In order to do this I also have to self average the dimension to which I will be applying the weights to, which in my case is the third dimension of a certain rf 3-D Matrix. Now I am averaging a 128x128 spatial covariance matrix into a 32x32 one so I need to find a way to also average the 128 pages of the rf matrix into 32. I am able to successfully split up the 128 element dimension into 96 overlapping arrays, populate a cell with them and average them into a single 32x1 array:
for i = 1:2048
for j = 1:128
for k = 1:96
rf_cell{k}=squeeze(rf(i,j,k:k+31));
end
end
end
rfthirddim = zeros(32,1);
for i = 1:96
rfthirddim = rfthirddim + rf_cell{i};
end
rfthirddim = (1/97)*rfthirddim;
Inbetween here I calculate the spatial covariance and through covariance the adaptive weights, however, I can not seem to find a way to correctly change the pages of my original array and apply the weights. I do it so :
for i = 1:2048
for j = 1:128
rf(i,j,1:32) = weights'*rfthirddim;
end
end
my resulting rf from here has the same element 1.77 at every entry. Weights is 32x1 so its transpose is 1x32 and its multiplied by a 32x1 array so my result should be populating just the 32 pages of rf. However I do udnerstand that in a MxNxP matrix there are P copies of MxN matrices so I am certain there is a fundamental error in the way I am trying to downsize the third dimension. This is my first time asking anything around here, please do let me know if the information I provide is not enough to answer this question!

Answers (1)

Nipun
Nipun on 30 May 2024
Hi Vakhtang,
It seems like you're trying to implement beamforming with adaptive weights and you're struggling with downsizing the third dimension of your RF matrix while applying the weights. Here's a breakdown of your code and some suggestions for improvement:
  1. Generating Overlapping Arrays: You're correctly generating overlapping arrays from your RF matrix in a cell array.
  2. Averaging Overlapping Arrays: You're averaging these overlapping arrays into a single array rfthirddim, which represents the downsized third dimension.
  3. Applying Adaptive Weights: However, the issue arises when you try to apply the adaptive weights to your original RF matrix. Your approach of directly multiplying the weights with rfthirddim and assigning it to the first 32 pages of rf is incorrect.
% Calculate rfthirddim (as you did before)
rfthirddim = zeros(32, 1);
for k = 1:96
rfthirddim = rfthirddim + rf_cell{k};
end
rfthirddim = (1/96) * rfthirddim;
% Apply adaptive weights to each page of rf
for i = 1:2048
for j = 1:128
for k = 1:32
rf(i, j, k) = weights' * squeeze(rf(i, j, (k-1)*4+1:k*4));
end
end
end
In this approach, we iterate over each page of rf and apply the adaptive weights to each 32-element subset of the original third dimension. squeeze is used to remove the singleton dimension created by selecting a subset of the third dimension.
Make sure that weights is a 32x1 column vector. If rf represents spatial data, you may also need to consider the spatial dimensions while applying the weights.
Hope this helps.
Regards,
Nipun

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!