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

1 次查看(过去 30 天)
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