필터 지우기
필터 지우기

how to design a single cycle square wave?

조회 수: 2 (최근 30일)
2NOR_Kh
2NOR_Kh 2022년 9월 13일
댓글: Chunru 2022년 9월 14일
I want to design a single cycle square wave and for theat I am using 'square' function but I don't know how to make it a single cycle wave.
I'm not exactly sure that for this purpuse I need to change the duty cycle or not, however I feel that's the case. But I wanted to ask professionals here to assure that.
This is my code for that:
f0=2.25e6;
fs=100e6;
t2=0:1/fs:2/f0;
offset=0;
amp=1;
duty=50;
sq_wav=offset+amp*square(2*pi*f0.*t2,duty);
plot(t2,sq_wav)

채택된 답변

Chunru
Chunru 2022년 9월 14일
% For single square pulse, you can specify:
% pulse width: pw
% simulation time: T
f0=2.25e6;
pw = 1/f0/2;
fs=100e6;
T=2/f0;
offset=0;
amp=1;
%duty=50;
ns = round(T*fs);
t2 = (0:ns-1)/fs;
sq_wav = zeros(ns, 1);
sq_wav(1:ceil(pw*fs)) = 1;
sq_wav=offset+amp*sq_wav;
plot(t2,sq_wav)
  댓글 수: 2
2NOR_Kh
2NOR_Kh 2022년 9월 14일
Thank you!
Could you please explain why you use this line of the code:
ns = round(T*fs);
Chunru
Chunru 2022년 9월 14일
Number of samples (ns) in the square wave is the prodcut of the simulation time (T) and the sampling frequency (fs) (which is number of samples per unit time).

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Pulse and Transition Metrics에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by