Create converging gratings in matlab

1 次查看(过去 30 天)
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

回答(1 个)

VINAYAK LUHA
VINAYAK LUHA 2023-9-27
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

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by