How to make cos function work only for short period then 0 of long period, and repeat?

3 次查看(过去 30 天)
hi all, i have to make a cos function that will work only for like 0.1 sec, then it will be zero for 1 sec, after 1 sec it will work for 0.1 sec again... and i have to repeat that 3 times i managed to generate it for 1 sec but i don't know how to shut it down after 0.1 sec !
thanks

回答(1 个)

Dimitris Kalogiros
Dimitris Kalogiros 2018-9-22
编辑:Dimitris Kalogiros 2018-9-22
I hope, this will help :
clearvars; clc; close all;
% simulation time step
dt=0.001;
% periods of ON and OFF
T1=0.1; %sec
T0=1; %sec
% switching functions
u1=ones(1, floor(T1/dt));
u0=zeros(1,floor(T0/dt));
u10=[u1 u0]; % one periode of T1+T0
% generation of cos function
time=3; %sec
t=0:dt:time; %time instants
myCos=zeros(1, length(t));
f=12; %frequency of the cosine (Hz)
for n=1:length(t)
myCos(n)=cos(2*pi*f*t(n))*u10(mod(n,length(u10))+1);
end
%plots
figure;
plot(t, cos(2*pi*f.*t), '-.r'); hold on;
plot(t,myCos,'-b*'); zoom on; grid on;
xlabel('t (sec)');
legend('cos', 'myCos');

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by