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

3 vues (au cours des 30 derniers jours)
Abdulrahman Mohammed
Abdulrahman Mohammed le 22 Sep 2018
Rouvert : Walter Roberson le 22 Déc 2018
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

Réponses (1)

Dimitris Kalogiros
Dimitris Kalogiros le 22 Sep 2018
Modifié(e) : Dimitris Kalogiros le 22 Sep 2018
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');

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by