0
$\begingroup$

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);
$\endgroup$
  • 2
    $\begingroup$ It looks like you are effectively changing the sample rate when you go from t1 to t2 to t3. Why are you doing that? $\endgroup$ – Jim Clay Aug 30 '12 at 13:29
  • $\begingroup$ 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? $\endgroup$ – Michael May 11 '15 at 2:25
  • $\begingroup$ Write new question! Write what is "code above", write what is "are not right" and what is "get them right". $\endgroup$ – SergV May 11 '15 at 2:41
  • $\begingroup$ 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. $\endgroup$ – Matt L. May 11 '15 at 7:43
1
$\begingroup$

Try this:

fs = 100;
t = 0:1/fs:10;
x = [sin(2*pi*7*t), sin(2*pi*12*t), sin(2*pi*2*t)];
specgram(x,256,1000, [],200);

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. You can see three horizontal lines at the three frequencies of interest.

$\endgroup$

protected by jojek May 11 '15 at 7:25

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.