difference between lines using linespace

22 Ansichten (letzte 30 Tage)
ahmed youssef
ahmed youssef am 26 Dez. 2016
Kommentiert: ahmed youssef am 26 Dez. 2016
Hi there, I need to know what is the difference between these: f=linspace(-fs/2,fs/2,samp_Tr); f = -fs/2 + (0:samp_Tr-1)*fs/samp_Tr; actually it gives me in my system different solution
thanks in advance

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 26 Dez. 2016
The two are very similar. The difference is that linspace taked some extra care to reduce the effect of accumulated round-off error. For example, because 1/3 cannot be exactly represented in binary, if you add the closest binary value to 1/3 together three times, you will get a value slightly less than 1. Imagine that you did that 300 times in a row; the result would have to end up 100 times that small difference less than 100. That would happen with the : operator. linspace works with that by dividing the range into two pieces and allowing accumulated error from the beginning to the middle and accumulated error from the end towards the middle, so right in the middle the gap might be a slightly different size.

Weitere Antworten (1)

KSSV
KSSV am 26 Dez. 2016
f1=linspace(-fs/2,fs/2,samp_Tr); % gives samp_tr number of numbers between -fs/2 and fs/2, always this length will be samp_tr
f2 = -fs/2 + (0:samp_Tr-1)*fs/samp_Tr ;
% 0:samp_Tr-1 makes numbers from 0 to samp_Tr with difference one -----1
% (0:samp_Tr-1)*fs/samp_Tr this multiplies all the aobe generated (1)
% numbers with fs/samp_Tr ----2
% -fs/2 + (0:samp_Tr-1)*fs/samp_Tr this adds the above generated numbers
% (2) to -fs/2
This is a simple one, you can check on your own giving numbers for fs and samp_Tr
  1 Kommentar
ahmed youssef
ahmed youssef am 26 Dez. 2016
but it gives me the same line when plot individually. moreover, -fs/2 + (0:samp_Tr-1)*fs/samp_Tr means numbers with begin from -fs/2 ending fs/2. I beleive it is the same when I put linspace(-fs/2,fs/2,samp_Tr). any discussion

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Visual Exploration finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by