2

I am currently doing a project on sound signal processing by using MATLAB. I have a problem regarding creating the command line so that I can get a graph containing frequency by its time. But this graph is the result of an audio input. example:

x = audioread('samson.wav')

But I still can't get this kind of a result. How can I get this colour graph? Thank youthis is example of color graph that i would like to have as a result, by putting an audio as an input

Marcus Müller
  • 30,525
  • 4
  • 34
  • 58
ashley mraz
  • 21
  • 1
  • 2
  • that looks like a complex morlet wavelet scalogram. http://dsp.stackexchange.com/a/7917/29 – endolith Mar 30 '14 at 19:41
  • i think youre right... but how do i obtain this graph with an Audio input?? – ashley mraz Mar 31 '14 at 13:34
  • I don't know in Matlab. This is the python code I used to make those plots: http://www.phy.uct.ac.za/courses/python/examples/moreexamples.html#wavelet-analysis-continuous-wavelet-transform http://www.phy.uct.ac.za/courses/python/examples/Wavelets.py – endolith Mar 31 '14 at 15:36
  • Very similar question: http://dsp.stackexchange.com/q/10127/29 – endolith Mar 31 '14 at 21:47
  • It is a wonderful code. Sorry, how can we find the Power versus period and time and Global power density? –  Apr 01 '16 at 14:47
  • Please don't post comments as answers! @TeshomeDugassa – Peter K. Apr 01 '16 at 15:11

1 Answers1

6

I believe that this "color graph" you are looking for is a spectrogram (although it looks to me more like a scalogram, but you did not mentioned wavelets). Let me give you an example in MATLAB of obtaining such plot:

load handel
nfft = 512;  
noverlap = 128;
win = hamming(nfft);
spectrogram(y, win, noverlap, nfft, Fs, 'yaxis')
colormap('jet')

So first line is loading of some standard test recording, it gives you two variables: Fs (sampling frequency) and y (your signal). Next you define length of your analysis: nfft in your Short Time Fourier Transform and by how many samples you want to shift your analysis window. When defining window you can use variety of them (simply check in MATLAB help), I've used most common one: Hamming window. Last line is for setting colour representation.

Computation of spectrogram is very straightforward, please refer to help for more details: click. The last argument 'yaxis' tells MATLAB to use horizontal time axis and vertical for frequency.

Having that you can play with length of your analysis window and the overlap. You must though understand one, most important thing: better resolution in time (short window) yields poorer resolution in frequency domain and vice versa - that's a trade-off.

In the end you should get something like:

enter image description here

EDIT:

Because you would like to obtain the scalogram, here's how to do it in MATLAB. Most important thing - you must have Wavelet Toolbox installed!

% Definition of signal consisting of two sinusoids
f1 = 10;
f2 = 40;
Fs = 1000;
t  = 0:1/Fs:1;
y =  sin(2*pi*t*f1) + sin(2*pi*t*f2);

wname = 'morl'; % Choosing the wavelet
scales = 1:1:128; % Defining scales
coefs = cwt(y, scales, wname); % Get wavelet coefficients

wscalogram('image', coefs, 'scales', scales, 'ydata', y); % Get the scalogram, together with time domain signal overlayed
colormap(jet) % Set the colormap

As a result you will get something like:

enter image description here

jojeck
  • 11,107
  • 6
  • 38
  • 74
  • yeah i just realise it as spectrogram.. im searching for the command line that can give me a result of a spectrogram graph of its frequency and time of its wavelet transform.. by putting an audio input.then i will get the result of its by spectrogram. basically the pic should be like what i posted earlier. thank you – ashley mraz Mar 31 '14 at 03:57
  • so i guess i actually should get a result of scalogram? because its a wavelet transform... but input of an audio that have been recorded – ashley mraz Mar 31 '14 at 04:24
  • @ashleymraz: STFT produces spectrograms, wavelet transforms produce scalograms. With a complex Morlet wavelet, they are very similar in concept, only differing in the spacing of the bins in time-frequency space. – endolith Mar 31 '14 at 15:38
  • 1
    @ashleymraz, post updated with scalogram creation. – jojeck Mar 31 '14 at 20:26
  • That's a real Morlet wavelet, not a complex one, though. wname='cmor' would be more similar to the OP's graph – endolith Mar 31 '14 at 21:42
  • so i just use the command line of it.. then i will get that result... but how can i get a new result with a new input? like i said before an audio input. .wav. that means the result of the scalogram should be according to its input – ashley mraz Mar 31 '14 at 23:44
  • what does 'scale a' representing? frequency? – ashley mraz Mar 31 '14 at 23:45
  • @ashleymraz: Scale is connected to frequency, in fact pseudo-frequency. I suggest you to read first about wavelets and then performing any work with them. Here's good source: click. Regarding scale-frequency connection, you can obtain it by using scal2frq command in Matlab. If you want to perform reading of wav files, then simply use wavread or audioread functions. These are well documented and easy to use. – jojeck Apr 01 '14 at 08:34
  • i run those command line u gave.. but it doesnt work. – ashley mraz Apr 02 '14 at 00:11
  • @ashleymraz: Most important question: what is the error? Mind that I wrote: you must have Wavelet Toolbox installed. – jojeck Apr 02 '14 at 00:20