difference between lines using linespace
3 views (last 30 days)
Show older comments
ahmed youssef
on 26 Dec 2016
Commented: 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
Accepted Answer
Walter Roberson
on 26 Dec 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.
More Answers (1)
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
See Also
Categories
Find more on Visual Exploration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!