Does anyone know how to improve MATLAB performance with 2D figures? - Page 1
Forum section: electronics / general

author: AndrejaKo
author_rank: Frequent Contributor
timestamp: October 11, 2013, 01:10:18 pm
content: Hi guys! I hope that this is not too off-topic.I'm experimenting getting data from my scope to MATLAB. I took a 10 MB of samples from scope, saved it as .csv and imported it into MATLAB using csvread. Then I did FFT on the data using guide provided here:http://www.mathworks.com/help/matlab/ref/fft.html. I adjusted the length to 10M and the sample rate to 1G and plotted the output and got the expected results. So far so good.Now about my problem: When I try to do pretty much anything in the figure window I get, everything is very very slow including opening toolbars. It takes more time to zoom in (one click of the + magnifying glass) on some particular value than it took for the FFT to be calculated. I did some reading on this topic, but all results I'm getting advise users to set rendering to OpenGL and it all seems related to 3D figures. I did try using OpenGL, but I had no performance improvement.I'm experimenting with MATLAB 2013a 64bit and have Intel Core 2 Duo T8100 and 4 GiB of RAM.Also if there any additional information that I should provide together with this question?

author: amyk
author_rank: Super Contributor
timestamp: October 11, 2013, 01:16:56 pm
content: Quote from: AndrejaKo on October 11, 2013, 01:10:18 pmIs there heavy CPU usage when it's lagging? Check the task manager. Is there heavy hard drive activity, indicating low-RAM swapping? Check the hard drive activity light. Check available memory in task manager.

author: lgbeno
author_rank: Frequent Contributor
timestamp: October 11, 2013, 01:41:49 pm
content: You might want to more tightly control the data type that the cvs read function is writing the data too.For example if it is using double floats like matlab often does and your data is less precise, it should free up ram and be faster. With that much data you are most certainly swapping virtual mem and that is slowwwwww.

author: olsenn
author_rank: Frequent Contributor
timestamp: October 11, 2013, 01:49:52 pm
content: You could try switching to a newer (preferably Nvidia) GPU. I think Matlab uses CUDA as well, but I'm not sure on that

author: AndrejaKo
author_rank: Frequent Contributor
timestamp: October 11, 2013, 01:57:27 pm
content: Thanks for ideas!My data are actually signed 8bit ints, but from what I can see included FFT functions only work on floating point, so I'll try converting data to floats instead of default doubles. I doubt that I'd lose any precision this way.Next, on my computer, MATLAB takes with just the data from the scope loaded takes up around 1.3 GiB of RAM when idle. When I'm working on figure, usage jumps up to 1.5 GiB and once figure "settles" it drops down to 1.3 GiB. I currently have one whole GiB of RAM free. I don't have major disk activity that could be easily associated with swapping when I'm working on the figure.When It's lagging, the CPU usage reaches around 90% according to Windows task manager. Also I'm using win7, if it matters.I am using nVidia GPU (GeForce 9600M GT) with CUDA support, but I don't see any obvious way I could use CUDA to speed up figure processing. As I mentioned, I did enable OpenGL rendering, but it's not that the rendering itself is the problem. I don't know how internally the plot() function works, so I don't know if CUDA would help it. I guess I could look that up.

author: PA0PBZ
author_rank: Super Contributor
timestamp: October 11, 2013, 02:11:21 pm
content: Not sure how big your csv file is, but if you can post it somewhere together with a matlab script (.m) file I could do some testing to see what my system(s) think of it.

author: kfitch42
author_rank: Frequent Contributor
timestamp: October 11, 2013, 04:29:11 pm
content: Quote from: AndrejaKo on October 11, 2013, 01:57:27 pmCAVEAT: I haven't used MATLAB seriously in about 5 years, so I could be way out of date here ... but1) You have 2 CPU cores, right?2) Last time I used it, MATLAB was seriously single threaded, so that 90% suggests more than one thread/process is using your CPU.3) In the "processes" tab of task manager, sort by CPU usage and see if MATLAB is the only one using significant CPU time.Also, try subsampling the data and figure out at what size things start falling over. You could do it as a binary search, try 5M, then either 2.5 or 7.5.If you want to get really fancy, you could find a command line thing to do some of the same stuff you find laggy and time it with tic and toc. e.g.times = []for subsample = 1e6:1e6:10e6% load up subset of subsample data points% plot itdrawnow; % This is probably necesary for timing to be meaningfultic;axis([x1,x2,y1,y2]);drawnow; % This is probably necesary for timing to be meaningfultimes = [times,toc];endplot(1e6:1e6:10e6, times)EDIT: Added drawnow ... since most commands for manipulating figures get queued up and executed later

author: AndrejaKo
author_rank: Frequent Contributor
timestamp: October 11, 2013, 06:31:23 pm
content: Quote from: PA0PBZ on October 11, 2013, 02:11:21 pmThe file itself is huge at 77 MiB. Here's a link to the .csv file and the .m file compressed by 7-zip. The compressed version is just 6 MiB:http://www.mediafire.com/?a8vmqlt2a9wirg3On my computer, the whole M file takes around 40 seconds to execute, with some 35 spent reading the .csv file. Unfortunately, I don't know how to profile work in the figure window. Converting the doubles to singles before FFT saves around one second in execution time, but the plot is still lagging.Quote from: kfitch42 on October 11, 2013, 04:29:11 pmLooks interesting! I'll give that a try. MATLAB's probelms are definitely with a single thread. In task manager, I can see that one core is almost completely loaded and other is more or less free. Also MATLAB uses just 50% of CPU time, which is typical for single-threaded programs. I know that there's a parallel computing toolbox, but from what I've heard, it's mostly related to actual processing of data, not plotting.Quote from: Bored@Work on October 11, 2013, 04:50:14 pmLong story:The real reason is to just get some experience with MATLAB. We have a signals and systems course this semester so I'm using that as an excuse to brush up my MATLAB skills. The stuff we're currently doing at the University is a bit too basic for me, so I thought up a project that looks more interesting to me: Compare the FFT function on the scope and MATLAB's FFT results. To do that, I should first make MATLAB talk to the scope, then get it to actually send the data. After that the data is in MATLAB, it should be processed so that I get FFT. Looking at a lower layer, I should first somehow connect MATLAB to scope using Ethernet or USB. Since I know very little about USB, I went the Ethernet route. It requires using raw tcpip sockets, since my scope (an old Owon SDS7102) doesn't support any standard connection mechanisms. I managed to get the scope to send the data over Ethernet and got stuck with input buffers and how to actually get the data from them, so I decided to pause network programming for a while and concentrate a bit on what I'm going to do with the data once I get it. I used scope's software to get the longest memory depth I can and imported it into MATLAB in order to see what happens. The scope is actually connected to an FM antenna, so the signal is just radio. I do understand the wisdom behind working with a small dataset. After this, my plan is to experiment with different dataset sizes, FFT window functions and so on.TL;DR version: No specific reason, just trying out stuff.