How do I generate a Triangle function

How would I generate code for implementing the triangle function triangle(2Bt-n) for n = 1:20
so far:
t = 0:0.005:1;
g_t = 0;
g_a = sin(2*pi*t)+(0.5*cos(6*pi*t))+(0.25*cos(18*pi*t)); %given
B = 10;
for n = 1:20
h = 2*B*t-n;
g_t = g_t + (n/(2*B)).*g_a.*(1-abs(2*B*t-n));
end
figure(1);
hold on;
box on;
plot(t,g_t,'r');
plot(t,g_a,'b');
ylabel('amplitude g(t)');
xlabel('time t');
title('sync waveform reconstruction');
axis([0 1 -2 2]);

답변 (1개)

Image Analyst
Image Analyst 2016년 2월 16일

0 개 추천

How about using sawtooth(), or using triang() followed by repmat()?

댓글 수: 3

James Stringer
James Stringer 2016년 2월 16일
So I am supposed to create my own triangle function (or something that acts like it) and not use MatLab's. I'm fairly new to MatLab so I'm not sure how that coding would look. This was for a homework assignment we did last week but as there were no solutions posted it is driving me crazy and I wanted to revisit it since I would actually like to be able to use MatLab.
Image Analyst
Image Analyst 2016년 2월 16일
Attached is my demo. I've posted it several times before.
James Stringer
James Stringer 2016년 2월 16일
thank you very much

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

질문:

2016년 2월 16일

댓글:

2016년 2월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by