Data Aquisition and plotting simultaneously on Matlab - multithreading

I have a loop of reading Voltages from Arduino (with a specific sampling rate and clock Frequency).
When I read data without plotting (loop include only the fread/fscanf and i++), the data appears without any problems.
Once I add rolling plot to display the acquired data, the signal will be lost at a sudden and the program stops. Any clarification for that?
If there exist a sample code for multi-threading to plot and perform data acquisition in the same time, I would be very grateful.
Thank you!

I am not sure whether it works for you, but I had the same problem and I used pause(t) before the end of the loop.

Related

EEGLAB preprocessing for sleep EEG data

I have 29-channel EEG data from overnight sleep recordings (~8 hours of EEG data). The EEG data is not continuous as I have paused it if the subject needed a loo break (~5-10 minutes) or to check the impedance (~2 minutes). This inserts a ‘boundary event’ in my EEG data. On some occasions, I have also reapplied a couple of electrodes if the impedance was high. In addition, sometimes I have had to stop the EEG recording and start again due to some technical reasons, because of which I have two EEG files for the same subject during the same night i.e. same session.
In my experiment, I have 15-20 events overnight and plan to use 1-2 minute data before each event for preprocessing and analyses. I would like to use ICA to correct for artifacts but before I do that, I would like to know if I need to split the data at each ‘boundary event’ and process them as separate EEG files? Or can I just consider the EEG recording from each subject as a single EEG recording and perform ICA (I can append the EEG files in cases where I have two EEG files per subject in the same session)? Any suggestions will be highly appreciated as I am very new to EEG and MATLAB.
You can find a detailed comment on your issue here
https://sccn.ucsd.edu/pipermail/eeglablist/2014/007380.html
Changing the impedance of the electrode introduce non-stationarity of the signal, that could affect ICA. However, ICA seems robust to this kind of violation, so you could concatenate all the sessions and run the ICA.
Rather, an issue could be if the electrodes moved during the breaks (ICA is a spatial filter, so spatial releationship are very important. see also here https://sccn.ucsd.edu/pipermail/eeglablist/2016/011878.html).
As a personal comment, I would use an "empirical" approach, to get a better grasp on the data and on the problem. In EEGLAB you could easily write a script and perform two parallel analysis, keeping all equal but the ICA decomposition (one on the concatenated data, one on the data separated for sessions). Then you can compare the difference on the data at the last step. In this way you can appreciate how the different strategy affected your results, and if this is really relevant.

Measuring Multiple Voltages in LabView w/USB 6001

I'm trying to set up my LabView VI + my USB 6001 I/O box to be able to read multiple independent voltages at once, while also outputting a single constant voltage.
I've successfully gotten my USB box to output the voltage I want while reading back a single voltage, but so far I've been unable to read back more than one voltage (and if I do, the two voltages seem to be co-dependent on one another in some way).
Here's a screenshot of my VI:
Everything to the right of the screenshot window should be unimportant to the question.
If anyone is curious, this is to drive multiple LVDT's and read back their respective voltages.
Thank you all for your help!
Look at your DAQ's manual, especially the pages I noted below.
http://www.ni.com/pdf/manuals/374259a.pdf
Page 11
All the AI channels get multiplexed, and the low-side reference can be switched (RSE vs. differential). So the two channels you're sampling require both of those to switch. It might be a settling issue where the ADC is taking a sample before the input value is stable.
To verify this, try using using the same low side (differential or RSE) on both channels. Also try slowing down your sample rate (but your 1 kHz should already be slow enough...).
Page 14
Check this to make sure you have everything connected and grounded correctly.
Page 18
Check this for more details about switching between 2 sources quickly.
Perhaps you could try it using the Daqmx express VIs:
http://www.ni.com/tutorial/2744/en/

Arduino AnalogRead returns 0 every a couple samples

I am using Teensy3.1 to record audio with 50KHz sample rate. I use the function AnalogRead to sample the analog pin. The reading value should fall into the range between 0 to 1024.
However, after recording the data, I found there is a small reading(E.g. 0.019) every 100 samples . What might be the possible reason for that? Am I sampling it too fast?
Any feedback is very much appreciated.
I figured out that problem, which rasing another problem to be solved.
Earlier problem was caused by usage of Buffer while reading serial port in Java via RXTX. I set the buffer size to be 1024. Therefore, each time the data stream was broken at the end of each buffer and the start of the next buffer. E.g. 449.00 was broken into three lines with 4 ,49 , .00 .
One easy solution is to increase the buffer size and throw the data at the end and start of each buffer. Is there any better way to solve that?
Thanks.

NI Reaktor Audio Input Vertical Line

I recently restartet patching in Reaktor and found something strange. In one of my Primary structures there is an input pin switching its icon to vertical line every now and then when I edit the structure. It somehow depends on the audio processing sequence.
Unfortunately I cannot post an image of the structure, because this needs more reputation... however, does anyone know what is the point with this port? It feels spooky. Thanks!
sounds to me like a audio loop indicator.
It appears if the signal flow is feed back so that it can't processed at the same time. In this case the feedback signal gets feed in one audio clock later.
What means that this port has a delay of 1 sample.
In order to determine yourself where this delay applies you may insert the Unit Delay what does the same job (1 sample delay) but at the place you want.

Overlap add in audio analysis-synthesis

I wrote some code that takes an audio signal (currently a sine wave) as an input and does the following:
Take frames of n (1024) samples
Apply FFT
Apply iFFT
Play output
With this process the output signal is basically the same as the input signal.
Now, in a second attempt I do:
Take overlapping frames from the input
Apply a window function
FFT
iFFT
Overlap the output frames
In step 1, if I take overlapping frames using a hop size (number of samples to jump to take next frame) of a power of 2 (4, 8, 256...) the output sound is smooth and resembles the original input sound, but with any other hop size, the sound starts to crack down. This happens for any frequency of the input signal. Question 1. Why is the sound smooth only if the hop size is 2^n?.
Currently I use a Hanning window. When the hop size is large (e.g. 512) the output sound has a lower volume than when the hop size is small (e.g.64). This seems an expected behavior, because a small hop-size implies that a sample is reconstructed with more frames, so more signals are added. Question 2. Is there a way to properly scale the output signal so that the volume resembles the original signal?
Thank you!
This should not be happening, Overlap-add method can reconstruct your signal without the problems described, we not know exactly what are you doing, I did it some time ago and its works for any hop size and window size, a small secret is apply zeros after and before your signal to ensure a continuous signal, if you look calmly will realize that your window function works like a fade-in/fade-out if you just concatenate the frames you will notice some clicks or the output signal will look like a vibrato, gets a little tricky to tell where your problem actually find !
Just for Debug, skip the FFT and iFFT steps and see if your signal was correctly constructed, if yes your overlap-add process works, and your problem can be in your FFT/iFFT ...
Overlap-add is normally done without using a non-rectangular window function. Zero-pad instead.
If you do use a window function, then you have to make sure that all the offset window functions sum to a constant level, which for a Von Hann window happens with certain offsets (except at the very beginning or end of the series sum). As
2 - (cos(x)+cos(x+Pi)) == 2
Sum more windows into a result without any scaling, and of course the level of the sum will increase.

Resources