フィルターのクリア

help finding vector slope

9 ビュー (過去 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 Center および File ExchangeMatched Filter and Ambiguity Function についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by