MATLAB Answers

0

difference between lines using linespace

Asked by ahmed youssef on 26 Dec 2016
Latest activity Commented on by ahmed youssef on 26 Dec 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

  0 Comments

Sign in to comment.

Tags

2 Answers

Answer by Walter Roberson
on 26 Dec 2016
 Accepted Answer

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.

  1 Comment

great analysis thank you

Sign in to comment.


Answer by KSSV
on 26 Dec 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 Comment

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

Sign in to comment.