Create converging gratings in matlab

4 views (last 30 days)
Mohini Sengupta
Mohini Sengupta on 12 Apr 2022
Answered: VINAYAK LUHA on 27 Sep 2023
I have created square gratings and can move them left or right with the following code. However I want to move the grating in a converging direction that is both sides, left and right more towards the center. How can I modify the code to do that?
sf=6;
n=50;
for i=1:n
x=linspace(-pi, pi, 100);
sinewave=[];
sinewave=square((x*sf)+i); % -i for the other direction
onematrix=ones(size(sinewave));
sinewave2D=(onematrix' * sinewave);
colormap(gray);
imagesc(sinewave2D);
drawnow;
end
Thanks

Answers (1)

VINAYAK LUHA
VINAYAK LUHA on 27 Sep 2023
Hi Mohini,
It is my understanding that you want to know the modifications required in your code to make your gratings converge towards the center.
Here is a modification which involves decreasing the spatial frequency of the square wave in your code by modifying its frequency parameter as shown below:
F = (x * (sf - i/2));
Here is the complete code for your reference:
sf = 100;
n = 50;
for i = 1:n
x = linspace(-pi, pi, 100);
sinewave = [];
sinewave = square((x * (sf - i/2)));
onematrix = ones(size(sinewave));
sinewave2D = onematrix' * sinewave;
colormap(gray);
imagesc(sinewave2D);
drawnow;
end
Hope this helps.
Regards,
Vinayak Luha

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!