How can I plot square waves with an increasing/decreasing linear pattern?
조회 수: 4 (최근 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)
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!