MATLAB - Spectrogram function - matlab

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.

Related

Convert B/W image to signal for Fourier Transform (DFT)

I am pretty new to signal and image processing.
I attached a picture of what I am supposed to do from a paper (https://iopscience.iop.org/article/10.1088/1361-6501/ab7f79/meta).
Basically, an interferogram is recorded by a CMOS sensor in B/W, then each vertical and horizontal pixel line is taken singularly and "associated" with a signal representing the intensity of light reaching the sensor. Then, the signals are Fourier-transformed to extract information about frequency and phase (to unwrap using).
I have understood the final passage for the DFT of the signal, but I am stuck when I have to take the pixel line and the signal associated with it.
Ideally, in Matlab the workflow would be:
extract each pixel line
assign a "colormap" to the line (white = 1, black = 0, all the other shades in between?)
build my signal interpolating the values of the pixels
DFT the signal to extract frequency and phase
Is there a compact way to do so?
So far I managed to do this:
I imported the image of the interferogram (248x320 pixels, just a snapshot from the paper) and for the 124th horizontal line I obtained the signal, frequency and phase.

How to find the time when wave altitude rapidly changes in 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

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.

Fix fluorescent flickering from video using matlab

I have several video sequences exhibiting light intensity flickering (under fluorescent light sources).
This is due to the shutter speed and/or sampling rate not being a whole multiple of the electrical frequency. For example - shooting video at 1/50 second shutter speeds with 60Hz electrical frequency.
In general - I need to solve this without knowing the sampling rate, electrical frequency, video frame rate. I just see the flickering and need to fix them.
The video scenes include moving objects as well (some move slow, some as fast as the rapid change in intensity due to the flickering).
Is there a well known method of dealing with such flickering?
Thanks!
The common method for removing flickering is along the following lines. Looking at the difference image between consecutive frames, the flickering should appear as a strong periodic signal along the vertical axis of the image. Therefore, it should have a strong coefficient in the frequency domain. Thus, the flickering can be detected and removed by finding the coefficients in frequency domain that represent the flickering in the difference image, nullifying them and transforming back to space domain.
In pseudocode this algorithm looks like this:
imDiff = I_{t+1} - I_t (Compute the difference between subsequent video frames)
imDiff = FilterImDiff(imDiff)
imDiffRowSum = RowSum(imDiff) (summing the rows of the diff image)
dctCoef = DiscreteCosineTransform(imDiffRowSum)
flickeringDctCoef = SomeHeuristicToFindFlickeringCoef(dctCoef)
flickeringIm = CloneColumn(InverseDiscreteCosineTransform(fixedDctCoef), numCols)
fixedimDiff = imDiff - flickeringIm
fixedI_{t+1} = I_{t+1} + fixedimDiff
where:
RowSum(x) takes an m x n image as input and returns a column vector of size m x 1 where element i contains the sum of the i'th row in the image x.
CloneColumn(x, n) takes a column vector x of size m and clones it n times in order to create an m x n matrix.
numCols is the number of columns in the input image.
a simple algorithm for SomeHeuristicToNullifyFlickeringCoef can be choosing the first couple of largest coefficients, if they are greater than a certain threshold.
FilterImDiff should discard stuff from the difference image that doesn't contain flickering, such as movement of foreground objects. For example, pixels that have a temporal difference that is greater than the maximal magnitude of flickering. Also, pixels that are too bright or too dark usually don't have flickering in them.

how to segment sky & water part in a picture

I'm trying to segment the sky and water part in this image.
Link of the Picture
I've tried so many methods like k-means, threshold, multi threshold etc. BUt unfortunately nothing worked so well.
Here is an example of my code(Matlab):
img=imread('1.jpg');
im_gray=rgb2gray(img);
b=imadjust(im_gray);
imshow(b);
bw_remove_small=imopen(b,strel('square',5));
imshow(bw_remove_small); %after 1st iteration
m3=medfilt2(bw_remove_small,[18,16]);
imshow(m3);
m3=medfilt2(bw_remove_small,20,20]);
m3=medfilt2(bw_remove_small,[20,20]);
imshow(m3);
I1=m3;
I2=rgb2gray(I1);
I=double(I2);
figure
subplot(1,3,1)
imshow(I1)
subplot(1,3,2)
imshow(I2)
g=kmeans(I(:),4);
J = reshape(g,size(I));
subplot(1,3,3)
imshow(J,[]);
Can any one help me?please
The picture's two regions are different in hue, texture, and gray level brightness.
The horizon is the best line in the image from our point of view and can be seen by the distinct change in brightness. The brightness will not work with a single threshold because the image brightness is not flat, so use brightness a model of the distribution to flatten out the sky or the water. This implies knowledge of the objective but there are two things that can give you an approximate answer: texture and/or hue.
The hue with a threshold of 120 (derived from the hue histogram) will give you the two regions but will not be divided cleanly and will have overlapping sections. Though using these two sections a model of the brightness can be found.
The same with texture. Using a small fft of the image, subtracting the dc out, then averaging or just summing up the non dc parts will result in a histogram with two peaks that may not be as distinct as the hue's is but is enough to find a threshold and two areas that will allow a model of the brightness to be found.
The key fact is if the sky is modeled properly as a gray surface then you can subtract it out of the image and use a simple threshold to pull it out.
Edge detection is very noisy in this image to be able to easily see the line but if you can pull out the image lines without losing shape then look for a straight and long contour it may take less code/work.
Hope this helps some! I used this to find mountains in the distance when there was not a big difference between the sky and the mountains. Plus I just tried this on your pic and almost got a good answer without a good model of the sky.