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

조회 수: 5 (최근 30일)
Abdulrahman Mohammed
Abdulrahman Mohammed 2018년 9월 22일
다시 열림: Walter Roberson 2018년 12월 22일
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에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by