フィルターのクリア

little problem in plotting a signal. Both x, y has the same lenght but is not plotting correctly

1 回表示 (過去 30 日間)
Hello!! I have this code and I am not getting what I should, that actually is a kind of sin that decrease whith the time. I have check that both arrays have the same lenght, but the problem is that the variable a that I used for the loop is fixed to 100. All this values I checked at the workspace. Here it goes the code
Tc=1*10e-3;
f=linspace(0.1,2e6);
R=zeros(1,100);%preallocate
for a=1:1:100
R(a)=i*Tc*sinc(f(a).*Tc/2).*sin(pi*f(a).*Tc/2);
end
plot(f,R)
Thanks in advance Nicolas

回答 (3 件)

Honglei Chen
Honglei Chen 2012 年 3 月 14 日
I don't think a is the issue here. In your R(a), do you mean pi instead of i for the first term?
BTW you should be able to write this in vectorized form, just do
R = pi*Tc*sinc(f.*Tc/2).*sin(pi*f.*Tc/2)
  1 件のコメント
Nicolas
Nicolas 2012 年 3 月 14 日
Hello!Thanks for the response.
By i I mean the imaginary unit. What I am trying to do with the loop is to calculate the vector R, the 100 positions of R vector.
What I dont understand is the vectorized form?I dont need to write the loop then?
thanks

サインインしてコメントする。


Nicolas
Nicolas 2012 年 3 月 14 日
Hello!Thanks for the response. By i I mean the imaginary unit. What I am trying to do with the loop is to calculate the vector R, the 100 positions of R vector. What I dont understand is the vectorized form?I dont need to write the loop then? thanks

Honglei Chen
Honglei Chen 2012 年 3 月 14 日
Yes you don't need to write the loop, if you mean for imaginary part, then it is
R = 1i*Tc*sinc(f.*Tc/2).*sin(pi*f.*Tc/2)
plot(f,imag(R))

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by