[help] FFT & Spectrogram

febty febriani febty82 at gmail.com
Thu Jul 2 03:56:04 CDT 2009


2009/7/2 Judd Storrs <storrsjm at email.uc.edu>

> On Thu, Jul 2, 2009 at 2:01 AM, febty febriani <febty82 at gmail.com> wrote:
>
>>
>> octave <<EOF
>> Fs=1;
>> fh=fopen("result.dat","r");
>> x=fscanf(fh,"%lf");
>> x0=hanning(4096);
>> a=(x(1:4096)).*(x0);
>> b=fft(a,8192);
>> c=abs(b(1:4096));
>> c=c/max(max(c))    ;
>> d=((1:4096)/4096)*(Fs/2);
>> subplot(2,1,1);plot(d,c);
>> subplot(2,2,1);imagesc(flipud(20*log10(c)));
>> EOF
>
>
> What I suspect is happening here is when octave reaches the EOF it exits
> and doesn't draw the plots. Since there also aren't any commands to save the
> plots to a file that is why you don't see any output. You can perhaps add a
> "print" statement to get the plots to file
> http://www.network-theory.co.uk/docs/octave3/octave_163.html
>
> Or if you would rather watch the plots you can add
>
> drawnow ;
> sleep(10) ;
>
> before the EOF to pause 10 seconds before exiting. For the second subplot
> you may want "subplot(2,1,2)" instead of "subplot(2,2,1)"
>
> Hope this helps,
>
> --judd
>

thanks very much, it is very helpful for me. I fixed the script. I can see
the FFT result. For the spectrogram, I just saw blank image. From Octave
prompt, I got error like below :

GNUPLOT (plot_image):  Image grid must be at least 2 x 2.


GNUPLOT (plot_image):  Image grid must be at least 2 x 2.


my script is

###
octave <<EOF
Fs=1;
n=4096;
fh=fopen("result.dat","r");
y=fscanf(fh,"%lf");
window=hanning(n);
y1=(y(1:n)).*(window);
y2=fft(y1,n*2);
[S, f, t] = specgram(y, n, Fs, window, length(window)/2);

S=abs(y2(1:n));
S=S/max(max(S));
x=((1:n)/n)*(Fs/2);
subplot(2,1,1);plot(x,S);axis([0
0.01]);title("200901");xlabel("Frequency");ylabel("Amplitude");
subplot(2,1,2);imagesc(flipud(20*log10(S)));
print -dpng output.png;
drawnow;
sleep(10);
EOF
###

any idea why I got such error?
any help is appreciated. Thanks very much.
-- 

******
febty febriani
Indonesian Institute of Sciences
Research Center for Physics
Kompleks PUSPIPTEK
Serpong, Indonesia, 15314
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www-old.cae.wisc.edu/pipermail/help-octave/attachments/20090702/ebdfe3cf/attachment.html 


More information about the Help-octave mailing list