Thread Subject: Problem with using movie function

Subject: Problem with using movie function

From: Clement Lim

Date: 30 Sep, 2009 13:43:03

Message: 1 of 6

Hi All,
I had the following code. I wish to use the movie function to animate my histogram but I had tried various way and the below code still cannot perform correctly. Can anyone help me? Tks

[filename, pathname] = uigetfile('*.*', 'Pick any file');
[y, fs, nbits] = wavread(filename);

[S,S,T,P]=spectrogram(y);%returns the spectrogram of the signal specified by vector y in the matrix S(1st S),vector of frequencies S(2nd S), vector of times T, P is the PSD
subplot(2,1,1);
spectrogram(y);
title('Spectrogram');
subplot(2,1,2);
for k = 1:16
    plot(Y)
    axis equal
    M(k) = getframe;
end
arg={S,T,10*log10(abs([P.'])+eps)};
waterfall(arg{:});
colormap(jet(256));
movie(M,10)
title('Waterfall Plot');

Subject: Problem with using movie function

From: Ashish Uthama

Date: 30 Sep, 2009 13:55:11

Message: 2 of 6

On Wed, 30 Sep 2009 09:43:03 -0400, Clement Lim
<clementlim@singnet.com.sg> wrote:

> Hi All,
> I had the following code. I wish to use the movie function to animate my
> histogram but I had tried various way and the below code still cannot
> perform correctly. Can anyone help me? Tks
>
> [filename, pathname] = uigetfile('*.*', 'Pick any file');
> [y, fs, nbits] = wavread(filename);
>
> [S,S,T,P]=spectrogram(y);%returns the spectrogram of the signal
> specified by vector y in the matrix S(1st S),vector of frequencies S(2nd
> S), vector of times T, P is the PSD
> subplot(2,1,1);
> spectrogram(y);
> title('Spectrogram');
> subplot(2,1,2);
> for k = 1:16
> plot(Y)
> axis equal
> M(k) = getframe;
> end
> arg={S,T,10*log10(abs([P.'])+eps)};
> waterfall(arg{:});
> colormap(jet(256));
> movie(M,10)
> title('Waterfall Plot');

What is 'Y' in the call to PLOT? You use 'y' elsewhere.

The PLOT does not appear to change inside the FOR loop, wouldn't you
expect M(k) to be the same for all values of k ?

Subject: Problem with using movie function

From: Arnaud Miege

Date: 30 Sep, 2009 14:03:58

Message: 3 of 6


"Ashish Uthama" <first.last@mathworks.com> wrote in message
news:op.u02ox9l7a5ziv5@uthamaa.dhcp.mathworks.com...
> On Wed, 30 Sep 2009 09:43:03 -0400, Clement Lim
> <clementlim@singnet.com.sg> wrote:
>
>> Hi All,
>> I had the following code. I wish to use the movie function to animate my
>> histogram but I had tried various way and the below code still cannot
>> perform correctly. Can anyone help me? Tks
>>
>> [filename, pathname] = uigetfile('*.*', 'Pick any file');
>> [y, fs, nbits] = wavread(filename);
>>
>> [S,S,T,P]=spectrogram(y);%returns the spectrogram of the signal
>> specified by vector y in the matrix S(1st S),vector of frequencies S(2nd
>> S), vector of times T, P is the PSD
>> subplot(2,1,1);
>> spectrogram(y);
>> title('Spectrogram');
>> subplot(2,1,2);
>> for k = 1:16
>> plot(Y)
>> axis equal
>> M(k) = getframe;
>> end
>> arg={S,T,10*log10(abs([P.'])+eps)};
>> waterfall(arg{:});
>> colormap(jet(256));
>> movie(M,10)
>> title('Waterfall Plot');
>
> What is 'Y' in the call to PLOT? You use 'y' elsewhere.
>
> The PLOT does not appear to change inside the FOR loop, wouldn't you
> expect M(k) to be the same for all values of k ?
>
>
also, for it to work correctly, you need to include the pathname when
calling wavread, something like:
[y, fs, nbits] = wavread([pathname filename]);

I have tried this with a wav file provided by Windows and y is of dimension
two (presumably because it's in stereo), and you can only call spectogram
with a vector signal, so you need to do something like:
[S,S,T,P]=spectrogram(y(:,1)); or [S,S,T,P]=spectrogram(y(:,2));

and then again when plotting:
spectrogram(y(:,1)); or spectrogram(y(:,2));

HTH.

Arnaud

Subject: Problem with using movie function

From: Clement Lim

Date: 30 Sep, 2009 15:24:02

Message: 4 of 6

Hi,

I realized that i accidentally deleted off the line Y = fft(y). I wanted to use the movie function to create an animation effect in the waterfall plot and spectrogram from a music wav file. I wish to create a visual effect such that the waterfall plot and spectrogram will "move" while the music is being play. However, the below code done by me is simply unable to do so. When the program is run, it first show 2 plots, with the below plot showing some meaningless data. The next 2 plots show stationary spectrogram and waterfall plot.

Hope you can assist. Tks alot


[filename, pathname] = uigetfile('*.*', 'Pick any file');
[y, fs, nbits] = wavread(filename);
disp('Playing at the original sample rate.');
sound(y, fs);
disp(fs);
subplot(311)
spectrogram(y);

Y = fft(y);
[S,S,T,P]=spectrogram(y(:,1));
 subplot(2,1,1);
 spectrogram(y(:,1));
 title('Spectrogram');
 subplot(2,1,2);
 for k = 1:16
 plot(Y)
axis equal
 M(k) = getframe;
 end
 arg={S,T,10*log10(abs([P.'])+eps)};
waterfall(arg{:});
 colormap(jet(256));
 title('Waterfall Plot');

Subject: Problem with using movie function

From: Clement Lim

Date: 1 Oct, 2009 01:15:06

Message: 5 of 6

Hope u can assist. tks a million

Subject: Problem with using movie function

From: Ashish Uthama

Date: 1 Oct, 2009 12:35:32

Message: 6 of 6

On Wed, 30 Sep 2009 11:24:02 -0400, Clement Lim
<clementlim@singnet.com.sg> wrote:

> Hi,
>
> I realized that i accidentally deleted off the line Y = fft(y). I wanted
> to use the movie function to create an animation effect in the waterfall
> plot and spectrogram from a music wav file. I wish to create a visual
> effect such that the waterfall plot and spectrogram will "move" while
> the music is being play. However, the below code done by me is simply
> unable to do so. When the program is run, it first show 2 plots, with
> the below plot showing some meaningless data. The next 2 plots show
> stationary spectrogram and waterfall plot.
>
> Hope you can assist. Tks alot
>
>
> [filename, pathname] = uigetfile('*.*', 'Pick any file');
> [y, fs, nbits] = wavread(filename);
> disp('Playing at the original sample rate.');
> sound(y, fs);
> disp(fs);
> subplot(311)
> spectrogram(y);
>
> Y = fft(y);
> [S,S,T,P]=spectrogram(y(:,1));
> subplot(2,1,1);
> spectrogram(y(:,1));
> title('Spectrogram');
> subplot(2,1,2);
> for k = 1:16
> plot(Y)
> axis equal
> M(k) = getframe;
> end
> arg={S,T,10*log10(abs([P.'])+eps)};
> waterfall(arg{:});
> colormap(jet(256));
> title('Waterfall Plot');


Did you think about this:

> The PLOT does not appear to change inside the FOR loop, wouldn't you
> expect M(k) to be the same for all values of k ?

What is k supposed to loop over? Since nothing changes within your FOR
loop, the frames you collect will look exactly the same as you observed.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
movie function Sprinceana 1 Oct, 2009 02:46:46
spectrogram Sprinceana 1 Oct, 2009 02:46:46
wavread Sprinceana 1 Oct, 2009 02:46:46
code Sprinceana 1 Oct, 2009 02:46:46
reference Sprinceana 1 Oct, 2009 02:46:46
rssFeed for this Thread

Contact us at files@mathworks.com