Create a binary signal

조회 수: 7 (최근 30일)
Rafael Rafael
Rafael Rafael 2019년 3월 21일
답변: chourouk 2023년 1월 31일
Hello, anyone have any ideia how can I make this signal in a plot? The time must be between -3 and 3 with a range of 1ms.
Thanks

채택된 답변

Adam Danz
Adam Danz 2019년 3월 22일
편집: Adam Danz 2019년 3월 22일
This solution uses the square() funciton which converts a sin wave into a square wave with normalized values between [-1:1]. All you have to do is create a sin wave that fits your description, convert it to square wave, and then vertically scale it.
% Set params
width = 1.0; % Width of each step
height = 1.0; % Height of step (max - min)
base = 0.0; % min value
start = -3; % starting x value
stop = 3; % ending x value
res = 0.001; % resolution
horzShift = .5; % horizontally shift (negative = leftward)
% Compute square wave
x = start : res : stop;
y = (square(sin((x+horzShift)/width*pi))+1)/2*height + base;
% figure
plot(x,y, 'k-', 'linewidth', 3)
ylim([base - 1, base+height+1])
  댓글 수: 2
Rafael Rafael
Rafael Rafael 2019년 3월 22일
Oh thanks, that is an inteligent solution :)
Adam Danz
Adam Danz 2019년 3월 22일
Glad it worked for you!

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

추가 답변 (1개)

chourouk
chourouk 2023년 1월 31일
comment cree un signal binaire entre recepteur et emetteur?

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by