Plotting a Spectrogram with data from a csv file

17 次查看(过去 30 天)
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

采纳的回答

Wayne King
Wayne King 2013-12-4
编辑:Wayne King 2013-12-4
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 个评论
Win
Win 2013-12-4
How would I know the number of periods the window is covering?
Wayne King
Wayne King 2013-12-4
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.

请先登录,再进行评论。

更多回答(1 个)

Wayne King
Wayne King 2013-12-4
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 个评论
Win
Win 2013-12-4
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.
Win
Win 2013-12-4
I have edited my answer above and uploaded the file.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Time-Frequency Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by