Please can someone help me in moving the gratings pattern randomly to left and right.The code to generate gratings pattern is given below.

조회 수: 2 (최근 30일)
n = 101
[X,Y] = meshgrid(linspace(-pi,pi,n));
sinewave2D = 8*sin(4*X);
figure(1)
imagesc(sinewave2D)
axis equal; axis off; colormap(gray);
contrast = 2;
scaled_sinewave2D = (((contrast.*sinewave2D)+1)*127.5)+1;
image(scaled_sinewave2D)
% rescales numbers between -1 and 1 to lie between 1 and 256
colormap(gray(256))

답변 (1개)

Image Analyst
Image Analyst 2016년 4월 1일
Instead of X, use X-offset where offset is the distance you want to shift the signal.
offset = 2.5; % Whatever
sinewave2D = 8 * sin(4 * (X - offset));
  댓글 수: 2
Hannah Mathew
Hannah Mathew 2016년 4월 1일
Thanks. I don't need to shift the signal but it has to move continuously to right and left in random order.Can you help me with phase shifting in these codes?
Image Analyst
Image Analyst 2016년 4월 1일
The general formula is
signal = amplitude * sin((2 * pi / period) * (x - phaseShift)).
So just do this:
amplitude = 8; % Whatever you want.
period = 1.5708; % Whatever you want.
% Get random number between -pi and +pi
phaseShift = 2*pi*rand(1) - pi;
signal = amplitude * sin((2 * pi / period) * (x - phaseShift));

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Waveform Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by