How can I plot square waves with an increasing/decreasing linear pattern?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Voss
le 28 Juin 2022
%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)
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!