smooth function on long array
3 ビュー (過去 30 日間)
古いコメントを表示
Hello, i am writing a program that plots some data from serial port. i need to smooth data collected because it's noisy (i get it from 4 temperature sensors). the problem is that the program must run for several hours without freeze and get a new values of the four temperatures in about 3 seconds. When the program has collected something like 500 samples per temperature, it starts to become very laggy and at 7-800 samples it freezes. this because i run the smooth function with span of 101 samples every loop. how can i get a continuous function (as if i did a smooth on all the array) without doing it every loop? there is a workaround for my problem? thanks for answers alberto
2 件のコメント
Jan
2015 年 5 月 15 日
Without seeing the code, we cannot guess what you are doing or what's going wrong. What exactly is "laggy"? What are "7-800 samples"? Your code freezes, when you have 7 samples and run a smoothing function over 101 samples? Does this mean, that the smoothing function has a bug?
Please post relevant details - by editing the question, not as comment.
Walter Roberson
2015 年 5 月 16 日
If you post your smoothing function then we might be able to tell you how to run it without having the full previous input.
回答 (1 件)
Walter Roberson
2015 年 5 月 16 日
It sounds like you are not pre-allocated your arrays, so as your program runs the code gets slower and slower spending all of its time growing the arrays. You should allocate memory in advance to store a reasonable number of points, and if you detect that you are collecting more points than expected, you should grow the array by chunks rather than one-at-a-time. For example,
growby = 64;
curlen = 256;
v1 = zeros(curlen,1);
v2 = zeros(curlen,2);
maxsamp = 10000; %fail-safe, if we reach this the termination was missed
end_signaled = false;
for sampnum = 1 : maxsamp
end_signaled = check_for_end(); %external trigger to shut down?
if end_signaled
break;
end
if sampnum > curlen
curlen = curlen + growby;
v1(curlen) = 0; %extend the array by writing past the end of it
v2(curlen) = 0; %extend the array by writing past the end of it
end
...
v1(sampnum) = ....
v2(sampnum) = ....
end
%when we get here then if end_signaled is true we got a clean shutdown
%and otherwise it was because we reached our hard limit
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!