1 view (last 30 days)

Show older comments

f=10; %frequency of the impulse in Hz

fs=f*100; % sample frequency is 10 times higher

t=-1:1/fs:1; % time vector

x= 100*cos(2*pi*1000*t);

y=zeros(size(t));

y(1:fs/f:end)=1;

for t= -1:1/fs:1

m = x.*y;

end

plot(t,m);

Walter Roberson
on 7 Jun 2021

f=10; %frequency of the impulse in Hz

fs=f*100; % sample frequency is 10 times higher

t=-1:1/fs:1; % time vector

numt = length(t);

y=zeros(size(t));

y(1:fs/f:end)=1;

for tidx = 1 : numt

x = 100*cos(2*pi*1000*t(tidx));

m(tidx, :) = x.*y;

end

plot(t,m);

Srivardhan Gadila
on 7 Jun 2021

Based on the above code it is clear that there is no use of the for loop by redefining the variable t to iterate over the loop and the value of m = x.*y; will be same for all the iterations. I think what you are looking for is may be the following:

f=10; %frequency of the impulse in Hz

fs=f*100; % sample frequency is 10 times higher

t=-1:1/fs:1; % time vector

x= 100*cos(2*pi*1000*t);

y=zeros(size(t));

y(1:fs/f:end)=1;

% Removing the for loop

m = x.*y;

plot(t,m);

Srivardhan Gadila
on 7 Jun 2021

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

Start Hunting!