clear all;
close all;
p=0.001:.001:1;
o=ones(1,length(p));
z=zeros(1,length(p));
m=repmat([z o z o z o z o z o z o z o z o z o z o],[1,4]);
t=0.001:.001:length(m)/1000;
y=.5*sin(t/10);
x=y.*m;
y1=x;
for i = 2:length(t)
if m(i) == 1 && m(i-1) == 0 %if the rising edge is detected
y1(i) = m(i) * y(i); %sampling occurs
elseif m(i) == 1 && m(i-1) == 1 %and while the carrier signal is 1
y1(i) = y1(i-1); %the value of y1 remains constant
else
y1(i) = 0; %otherwise, y is zero
end
end
subplot(3,1,1);
plot(t,y);
subplot(3,1,2);
plot(t,x);
subplot(3,1,3);
plot(t,y1);