How can I plot square waves with an increasing/decreasing linear pattern?

조회 수: 4 (최근 30일)
Avril Cruz
Avril Cruz 2022년 6월 28일
댓글: Voss 2022년 6월 28일
Hello, I am trying to trace a triangle with a square wave. I have the square wave but I am having troubles increasing and decreasing it linearly to fit the shape of the triangle. It just stays at its original amplitude straight across.
%given
k_num=-45.6992;
h_num=60.3496;
%plotting lines of triangle
plot([k_num,0],[h_num,2*h_num],'m')
hold on
radius=sqrt((h_num.^2)+(k_num.^2));
newx=(k_num+radius);
plot([k_num,newx],[h_num,h_num])
plot([newx,(k_num-k_num)],[h_num,(h_num+h_num)])
%square wave
fnx = @(x,fn) ((h_num/2)*square(2*pi*fn*x)+(3*30.17));
ffs = 1000;
tp = k_num:1/ffs:newx;
pp = fnx(tp,.8);
plot(tp,pp)

채택된 답변

Voss
Voss 2022년 6월 28일
%given
k_num=-45.6992;
h_num=60.3496;
%plotting lines of triangle
plot([k_num,0],[h_num,2*h_num],'m')
hold on
radius=sqrt((h_num.^2)+(k_num.^2));
newx=(k_num+radius);
plot([k_num,newx],[h_num,h_num])
plot([newx,(k_num-k_num)],[h_num,(h_num+h_num)])
%square wave
% fnx = @(x,fn) ((h_num/2)*square(2*pi*fn*x)+(3*30.17));
fnx = @(x,fn)square(2*pi*fn*x);
ffs = 1000;
tp = k_num:1/ffs:newx;
amplitude = interp1([k_num 0 newx], [0 h_num 0]/2 , tp);
offset = interp1([k_num 0 newx], [0 h_num 0]/2+h_num, tp);
pp = fnx(tp,0.8).*amplitude + offset;
plot(tp,pp)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by