help finding vector slope

조회 수: 18 (최근 30일)
tony karamp
tony karamp 2013년 2월 12일
hello all,
I am trying to plot a vector named vec1, where
con = abs(g1-g2)/abs(t1:t2)*Fs));
vec1 = [g1*ones(1,Fs*t1),con*ones(1,Fs*t2), g2*ones(1,Fs*t3)];
What I want to see is a graph that has a linear slope from t1 to t2.
There must be something wrong with the con variable, but I can't get my head around it. Any help?
Thank you in advance
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 12일
what are g1,g2,...

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

채택된 답변

Youssef  Khmou
Youssef Khmou 2013년 2월 12일
Try this :
Fs=1000;
T=(0:1/Fs:20-1/Fs);
V=zeros(1,length(T));
t1=3;
t2=5;
g1=7;
g2=4;
for t=1:length(T)
if T(t)<=t1
V(t)=g1;
elseif T(t)>t1 && T(t) <=t2
V(t)=-(g1-g2)/(t2-t1)*T(t)+1.65*g1;
elseif T(t)>t2
V(t)=g2;
end
end
figure,
plot(T,V)
axis([0 20 0 10]), xlabel('time in Seconds');
ylabel(' Magnitude dB');title(' Gain')
  댓글 수: 2
tony karamp
tony karamp 2013년 2월 12일
Thank you for your response. I have a question though... How did you derive to that? (line 16)
vec(t)=-(g1-g2)/(t2-t1)*T(t)+1.65*g1;
where did you get the 1.65 from?
Thanks
Youssef  Khmou
Youssef Khmou 2013년 2월 12일
편집: Youssef Khmou 2013년 2월 12일
Tony, yes i forgot to mention that :
So your function in the 2dn region is defined as : y =ax+ b with negative slope :
vect(t) = a*T(t) + constant .
The slope is a= g1-g2/(t2-t1)= -3/2 .
to derive the constant : you take the initial condition :
At t=t1 vect(t1)=g1=a*t1+constant => constant=g1-a*t1=11.5 .
you can put 11.55 instead of g1*1.65 ,the reason i did g1*1.65 is because i derived the solution before you gave the details g1,t1,.. it was an approximation rather than solution from ax+b.

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

추가 답변 (4개)

tony karamp
tony karamp 2013년 2월 12일
|
|
g1|---------------\
| \
| \
| \
g2| \---------------------
|
|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
t1 t2 t3
That's want I want to see!! Hope this helps!

the cyclist
the cyclist 2013년 2월 12일
You don't really give enough detail to diagnose this, but I did notice that in the line
con = abs(g1-g2)/abs(t1:t2)*Fs));
the parentheses are balanced, so it's not a valid MATLAB statement.

Youssef  Khmou
Youssef Khmou 2013년 2월 12일
hi, you have to declare all variables in your example like others said so as to examine the code , but now details are missing .

tony karamp
tony karamp 2013년 2월 12일
this is all I have
Fs = 1000; %sampling frequency
t1 = 3; %seconds
t2 = 5;
g1 = 7; %db
g2 = 4
from 0 to t1, the gain is equal to g1. at t1, all the way to t2, there is a linear slope, decreasing for g1 to g2. from t2 to t3 the gain is equal to g2.
That is all I have...

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by