How to find the time when wave altitude rapidly changes in matlab? - matlab

I have EEG data as can be seen in the attached image.
As you can see, there is a time that wave altitude suddenly increases and then decreases after a while. I am looking for the time (horizontal axis) when the wave increase and decreases.
I have shown those areas in the attached image by Red, Green, and Purple color.
Note: I am not an expert in either signal processing or EEG data analysis. Could you explain it in a simple way?
EEG Data

The matlab function findpeaks may fit your needs. Without data, we cannot help you more than this: try help findpeaks.

You can use a picker to detect the points of sudden increase. A common approach is the short term average over long term average picker (STA/LTA) which detects (picks) when this value exceeds a threshold. This would give you the onset, if you then flip your signal in time and do the picking again you can get the end of your bursts. Here is an implementation of the STA/LTA picker
https://github.com/bpostlethwaite/Masters-Thesis/blob/master/matlab/sourceStack/stalta.m

Related

How to fit an image feature to a curve

I process a bunch 2D each having a sinusoidal feature randomly located in it:
Whereas the amplitude and the period of the sine are known in advance, the exact position is not.
I want to find an exact position of the sine in each image using MATLAB. Standard fitting techniques like Surface Fit won't work here because I only need to fit one feature, not the whole image.
The best idea that comes to my mind is to generate a reference image with a sine with a known location, and then use cross-corrrelation (xcorr2) to find the offset between the two. Maybe you could suggest any faster and simpler solution?

MATLAB - Spectrogram function

I've a wav sound file and made a spectrogram of it. My goal is to show how much frequency range a sound can cover. But I honestly do not know what the spectrogram shows and tells me.
Here's what I've got
load handel; % 'handel' is a MAT-file which is shipped with MATLAB as an example
x = y/100; % Decrease volume
player = audioplayer(x, Fs);
play(player,[1 (get(player, 'SampleRate')*10)]);
spectrogram(x);
Spectrogram(x) prints this, when x=y/100:
Spectrogram(x) prints this, when x=y/1:
My analysis:
Based on my little knowledge, I assume that the colors have something to do with the volume of the sound. The green color shows how high the volume is playing, so the more dense green lines you get, the louder the music plays. And the fewer green lines there are, the lower the music plays.
Am I wrong?
Anyone that can tell me what the spectrogram function does and shows? What does the yellow and green color mean?
I'm going to gloss over a lot of the fine details, but the basic idea is that any complicated waveform (like an audio recording) can be thought of as a combination of simpler waveforms (for example, pure sine waves at various frequencies) whose intensities vary over time. A sound that's lower in pitch (for example, a bass, or the low notes on a piano) would have most of the power in the low frequencies, while the sound of a piccolo or a snare drum hit would have a lot of power in the higher frequencies.
A spectrogram is a way of showing how the frequency content in the signal varies over time. In your example, time seems to increasing up the Y axis, while the frequency is displayed on the X axis, with higher frequencies to the right. At any given time and frequency, the color represents the amount of power at that frequency at that time, as shown in the color bar on the right side of the plot.

Filter eye tracking data in MATLAB

I have eye tracking data sampled at 2000Hz with 45000 samples of x-y pixel coordinates on a 1920x1080 plane.
The velocity (saccade) of the eye is shown in the plot below and contains high frequency noise. x-axis contains the time and y-axis is the velocity/saccade (I forgot the labels)
I want to filter out the noise in such a way that the values between the peaks are 0 and the peaks do not contain noise nor do they lose amplitude.
The latter I could probably do by locating the peaks and simply interpolating between its start position and end position since I just need the peaks and their width. However, this is not really an elegant option.
I was curious if there is a smart or elegant way of doing this. I tried a butterworth filter but that reduces peak amplitude.
It will be imposible to leave the peak amplitudes unchanged because they are also corrupted by high frequency noise. I think that you have two options to filter out the noise
Using a low pass filter
Using the smooth function
You would have to play around with both methods to determine which better suites your needs, and leave the saccade velocity amplitudes mostly unchanged.

Image Processing Q: Separate/segment an image

need some help here on image processing. I'm using Matlab and try to segment the following figure based on the two major peaks (in yellow). The color yellow means higher value and blue means low value (on z-axis, or image color from 0 to 1 for your convenience). The ideal cut is roughly the line from point (1,75) to (120,105). But I want a systematic way to derive this rather than by observation.
My intuition was to first identify the two peaks (based on this), and then classify each point/pixel on this figure to the two peaks (the metric here is to compute the shortest Euclidean distance to the edge of the two peaks).
And I end up with the following fig.
As you can see, the cut is pretty much a straight line, which I'm not quite satisfied. Maybe I can use the orientation of the peak circle and somehow tilt the line.. but I'm not sure how to do so? Any clues? Thanks.
This is an Image segmentation problem.
you can use GMM Gaussian of Mixture Model to model the image.
in your case the number of components will be 2.
after you model the image by using this mixture, you can find the probability of each pixel P(pixel x belong to the first component or the second component)
check
http://www.mathworks.com/matlabcentral/newsreader/view_thread/272162
http://www.mathworks.com/help/stats/cluster-data-from-mixture-of-gaussian-distributions.html

image focus and FFT

I am a new to Matlab and I have a project that involves image processing.
I have a number of RGB images and I need to find a way to separate the out of focus from the in focus images. I do not need to correct the focus of the out of focus ones, I just need to find which are out of focus and remove them. I have done FFT2 to the image and then used the radial average of the image of the power spectrum to see if there is a difference between the in focus or out of focus but I do not see a difference between the two.
I decided to use the gradient of the image
[gradx,grady]=gradient(image)
and then take the magnitude
new_image=sqrt((gradx.^2)+(grady.^2))
and try to do the FFT2 using the new_image now instead of the image. The power spectrum does not look like what I expect so I am not sure if I should do the FFT2 on the new_image of the gradx and grady separately. Has anyone have any thoughts about whether this is the right way to do this?
I was also thinking that instead of using the gradient to use a Sobel mask
mask=fspecial('sobel')
mask_x=imfilter(image,mask)
mask_y=imfilter(image,mask')
new_image=sqrt((mask_x.^2)+(mask_y.^2))
and then do FFT2 in the new_image but again the power spectrum is not right. I expect it to start from zero and instead it starts from the highest value and drops exponentially.
Has anyone tried to classify images using this method? Thank you for reading.
A DCT, instead of an FFT/DFT, will get rid of any high frequency discontinuities between the opposite edges of your images.