# To Apply 2D sliding window on data to calculate doppler parameter rapidly

7 Ansichten (letzte 30 Tage)
Amjad Iqbal am 20 Mai 2021
Beantwortet: Shashank Gupta am 26 Mai 2021
I need help to merge 2-for loops using filter2 (2D) filter or any suitable way to make my code efficient enough.
I want to run a 2D sliding window of 256*256 to move through whole data and calculate one 'dc' for each patch, moreover, I just received last value of ''dc'' while rest of previous values are 0.
img= [1:1664,1:4352] %% Size of image
PRF = 1925;
k = 128; % size of patch
C= zeros(size(img));
for i = k+1:size(img_o,1)-k
for j = k+1:size(img_o,2)-k
Bb = img_o(i-kk:i+kk-1, j-kk:j+kk-1);
dc(k) = doppler_centroid(Bb, PRF); %% this function calculate doppler centroid ''dc''
C(i,j) = dc(k);
end;
end;
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Shashank Gupta am 26 Mai 2021
There are many things, I don't understand in the code. First line defining the variable "img" seems odd because the way you defined it give the same of "img" as [ 1 ,6016] which I don't think is intended. May be that's the reason of you getting abrubt values in C. You can simply define the size of image in img and define C accordingly
img = [1664,4352] % Size of image.
C = zeros(img); % Define C according to the size of image.
Also, yes these can be optimized, I don't know what the doppler_centroid function do. But you can remove both the for loop and convert this problem in matrix space and then use a convolution filter to solve the problem, Refer conv2 function. I will give an example describing how it can be useful.
% Let try to find a simple mean of the sliding window.
A = rand(10,10);
B = ones(2,2)./4; % Design a matrix for taking average.
C = conv2(A,B,"same"); % This matrix is the result of average over a sliding window of length 2.
I hope this helps.
Cheers.
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Discrete Fourier and Cosine Transforms finden Sie in Help Center und File Exchange

R2016a

### Community Treasure Hunt

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

Start Hunting!

Translated by