1

Is there Matlab code that shows a series of numbers representing a waveform as a spectrogram?

The time interval each sample represents is the same, idearly this could also be given to use for the axis scale.

http://www.davegrossman.net/gould/media/spectrum-devocalized.jpg

For example:

spec({1 2 3 2 1 2 3 2}, 0.1 seconds)

or

spec(my_data.txt, 10 Hz)

etc...

1

2 Answers 2

4

If you have the Signal Processing Toolbox, then you can use the spectrogram() function. e.g.:

T = 0:0.001:2;
X = chirp(T,100,1,200,'q');
spectrogram(X,128,120,128,1E3); 

(Example taken from that documentation page.)

The numeric params are window length, overlap length, FFT length and sampling frequency, respectively.

Sign up to request clarification or add additional context in comments.

4 Comments

And for external data it's X = cell2mat({1 2 3 etc...}) or paste into the Workspace window.
@alan2here: What is "external data"? cell2mat seems excessive; just use square brackets if you want a normal array.
External data, you know, data that comes from somewhere else. Like a list of numbers I've downloaded from the internet instead of generating in Matlab. Also cell2mat works, using square brackets instead generates "X must be a vector (either row or column)." because X ends up being the wrong type for spectrogram.
@alan2here: X = [1 2 3 4 5 6]; spectrogram(X,...); should work fine. In general, you should cell arrays (i.e. arrays declared using {}) unless you really need them, because they screw up all sorts of things.
0

if you look on tftb toolbox, the tfrspwv is a very complex and precise spectrogram code and there is an running script example in the tfrspwv.m code online for making a spectrogram in Matlab.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.