Plotting a Spectrogram with data from a csv file

Hi I have some data in a csv file. The actual data has 1048576 lines and is too big to upload so I'm attaching a chunk of it which has only 10462 lines of data (trial3.csv). I would like to plot a Spectrogram using these values.
I am using the following lines to plot the data.
Array=csvread('trial3.csv');
col1 = Array(:, 1);
col2 = Array(:, 2);
plot(col1, col2)
%[S,F,T]=spectrogram(Array,32,16,32,100)
Can someone tell me how to make a spectrogram out of it please?
Thanks
Winee

 Accepted Answer

Array = csvread('trial3.csv');
dt = mean(diff(Array(:,1)));% sampling period
Fs = 1/dt;
[S,F,T,P] = spectrogram(Array(:,2),300,280,200,Fs);
surf(T,F,10*log10(abs(P)),'EdgeColor','none');
axis xy; axis tight; colormap(jet); view(0,90);
xlabel('Time (s)');
ylabel('Frequency (Hz)');
You did not answer the question about what is the lowest frequency you want to resolve. That basically defines your window length. I've just used 300 here which gets you down to about 1700 Hz.

6 Comments

How does a window length of 300 correspond to 1700Hz?
I am not sure about the frequency I need. I have just been given this data to analyse and identify changes/features. It is basically the Acoustic emission measurements to determine whether there are cracks in railway lines.
The sensor taking these values has a main resonant frequency of 450 kHz and operating Range 125–1000 kHz.
Your sampling interval is 2 microseconds which means that the sampling frequency is 500 kHz. That means your Nyquist frequency is 250 kHz, you can't resolve higher than that. If you have a window of 300 samples with a sampling interval of 2 microseconds that is a time window of 0.6 milliseconds -- that is a frequency of roughly 1.7 kHz. Actually if you wanted to get good resolution on 1.7 kHz you should make the window long enough to contain a couple periods -- not just one.
How would I know the number of periods the window is covering?
Just as I told you, you multiply the length of the window in samples by the sampling period. That gives you the length of the window in time.

Sign in to comment.

More Answers (1)

I don't see the attachment.
You have to obtain the spectrogram on a 1-D signal, not a matrix. So is col2 your data?
What is the sampling interval for this data -- time between measurements.
I doubt that 32 points is enough to get a good spectrogram, I would recommend making your window larger than that, but without more details about your data, it's hard to make a more concrete recommendation.

4 Comments

Win
Win on 4 Dec 2013
Edited: Win on 4 Dec 2013
I am really sorry I didn't click on Attach. I thought it automatically uploads the file. Please find attached the file.
Just pasting those few lines doesn't help, please provide the sampling frequency and if you can which frequency range are you especially interested in.
If you can provide that detail, I can make up and example.
The data samples are taken every 2.00E-06 second. Therefore I think that the sampling frequency can be 1/(2.00E-06).
I need to analyse the entire data range to look for special features for eg abrupt changes in the frequency, abnormally high frequencies.
I have edited my answer above and uploaded the file.

Sign in to comment.

Categories

Asked:

Win
on 4 Dec 2013

Commented:

on 4 Dec 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!