# Spectrogram for created signal in Octave

I'm trying to test the specgram function located in the signal package in octave but I'm a little confused at the variables in specgram. What I would like to do is be able to get the specgram data into an array that will show the frequency and the length of time when the frequency starts and stops.

See example code below: I was trying to get the array to show that for the length of t1 will be $7 \textrm{ Hz}$, t2 will be $12\textrm{ Hz}$ and for t3 will be $2\textrm{ Hz}$. How can I go about doing this?

I'm using ubuntu 12.04 and octave 3.2.4 and the signal pacakage 1.0.11

% combines sig with spectra plot
clear all,clc,tic;
fs=1000;
t1=linspace(0,2*pi,fs/0.1); %need to round off no decimals
t2=linspace(0,2*pi,fs/0.3); %need to round off no decimals
t3=linspace(0,2*pi,fs/0.6); %need to round off no decimals

%Create signal in different arrays
y1=sin(7*t1);
y2=sin(12*t2);
y3=sin(2*t3);

%append arrays to test specgram
yt = [y1 y2 y3];

%plot(yt) %will show combined plot

%Spectrum section
yts=specgram(yt',20,500, 2,1);
plot(yts)
fprintf('\nfinally Done-elapsed time -%4.4fsec- or -%4.4fmins- or -%4.4fhours-\n',toc,toc/60,toc/3600);

• It looks like you are effectively changing the sample rate when you go from t1 to t2 to t3. Why are you doing that? – Jim Clay Aug 30 '12 at 13:29
• I tried the code above in octave, and it does not work. Also, when using 'specgram(x)' instead i does display a spectrogram, but the frequencies are not right. does anybody know how to get them right? – Michael May 11 '15 at 2:25
• Write new question! Write what is "code above", write what is "are not right" and what is "get them right". – SergV May 11 '15 at 2:41
• If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. – Matt L. May 11 '15 at 7:43

fs = 100;

I have reduced the sampling frequency because the three frequencies in your signal are quite low. In the specgram() function, I have increased the FFT size to 256 and used the default hanning(256) window with 200/256 $\approx$ 80% overlap. 