Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Spectrogram output scaling = ?

Subject: Spectrogram output scaling = ?

From: Mark Proulx

Date: 31 Mar, 2011 17:32:05

Message: 1 of 8

From the documentation for the 'spectrogram' command:

T = 0:0.001:2;
X = chirp(T,0,1,150);
[S,F,T,P] = spectrogram(X,256,250,256,1E3);

I cannot determine the relationship between the amplitude of the components of X and the magnitude of the elements of S. In the example cited, the amplitude of X is 1 at all times. The corresponding maximum magnitude of S is approximately 40. What is the relationship between S and the amplitude of the underlying signal?

Subject: Spectrogram output scaling = ?

From: Florin Neacsu

Date: 31 Mar, 2011 18:15:21

Message: 2 of 8

"Mark Proulx" <mark.p.proulx@boeing.com> wrote in message <in2dql$2do$1@fred.mathworks.com>...
> From the documentation for the 'spectrogram' command:
>
> T = 0:0.001:2;
> X = chirp(T,0,1,150);
> [S,F,T,P] = spectrogram(X,256,250,256,1E3);
>
> I cannot determine the relationship between the amplitude of the components of X and the magnitude of the elements of S. In the example cited, the amplitude of X is 1 at all times. The corresponding maximum magnitude of S is approximately 40. What is the relationship between S and the amplitude of the underlying signal?

Hi,

This is not an answer to your question, but I was wondering; aren't you suppose to give as the 4th parameter F, as a vector with at least 2 values ?

From matlab's documentation :
[S,F,T] = spectrogram(x,window,noverlap,F) uses
a vector F of frequencies in Hz. F must
be a vector with at least two elements

and :

T = 0:0.001:2;
X = chirp(T,0,1,150);
F = 0:.1:100;
[Y,F,T,P] = spectrogram(X,256,250,F,1E3,'yaxis');

Regards,
Florin

Subject: Spectrogram output scaling = ?

From: Mark Proulx

Date: 31 Mar, 2011 18:36:04

Message: 3 of 8

"Florin Neacsu" <fneacsu2@gmail.com> wrote in message <in2gbp$hsq$1@fred.mathworks.com>...
> "Mark Proulx" <mark.p.proulx@boeing.com> wrote in message <in2dql$2do$1@fred.mathworks.com>...
> > From the documentation for the 'spectrogram' command:
> >
> > T = 0:0.001:2;
> > X = chirp(T,0,1,150);
> > [S,F,T,P] = spectrogram(X,256,250,256,1E3);
> >
> > I cannot determine the relationship between the amplitude of the components of X and the magnitude of the elements of S. In the example cited, the amplitude of X is 1 at all times. The corresponding maximum magnitude of S is approximately 40. What is the relationship between S and the amplitude of the underlying signal?
>
> Hi,
>
> This is not an answer to your question, but I was wondering; aren't you suppose to give as the 4th parameter F, as a vector with at least 2 values ?
>
> From matlab's documentation :
> [S,F,T] = spectrogram(x,window,noverlap,F) uses
> a vector F of frequencies in Hz. F must
> be a vector with at least two elements
>
> and :
>
> T = 0:0.001:2;
> X = chirp(T,0,1,150);
> F = 0:.1:100;
> [Y,F,T,P] = spectrogram(X,256,250,F,1E3,'yaxis');
>
> Regards,
> Florin

Florin:

Thanks for the reply. I find the documentation on this issue confusing, in that it implies that the fourth parameter is the FFT block size, which I interpret the documentation to say provides a legitimate substitute for a vector "F." (I don't know that I'm correct in this, it's just what I think they mean ;-) )

Subject: Spectrogram output scaling = ?

From: Wayne King

Date: 31 Mar, 2011 18:49:04

Message: 4 of 8

"Mark Proulx" <mark.p.proulx@boeing.com> wrote in message <in2dql$2do$1@fred.mathworks.com>...
> From the documentation for the 'spectrogram' command:
>
> T = 0:0.001:2;
> X = chirp(T,0,1,150);
> [S,F,T,P] = spectrogram(X,256,250,256,1E3);
>
> I cannot determine the relationship between the amplitude of the components of X and the magnitude of the elements of S. In the example cited, the amplitude of X is 1 at all times. The corresponding maximum magnitude of S is approximately 40. What is the relationship between S and the amplitude of the underlying signal?

Hi Mark, In order to understand that scaling you have to take into account the effect of the window, which is by default Hamming, and the length of the segments you are inputting to spectrogram. To show you a simple example with a rectangular window (which I'm not recommending to use by the way)

t = 0:.001:1;
x = cos(2*pi*100*t);
[S,F,T,P] = spectrogram(x,ones(100,1),50,100,1E3);
plot(abs(S(:,1)));

Notice here that a unit amplitude sinusoid has mapped in absolute value to the length of the window (100) segment divided by 2.

Note that is the same as:

xdft = fft(x(1:100));
plot(abs(xdft))

Except the above shows both the negative and positive frequencies. The scaling is what I want to draw your attention to.

Now if you use the default Hamming window:

[S,F,T,P] = spectrogram(x,100,50,100,1E3);
plot(abs(S(:,1)));

That is the same as:

xdft = fft(hamming(100)'.*x(1:100));
plot(abs(xdft));

Except that again, I'm plotting both the negative and positive frequencies with fft().

The scaling on the modified periodogram estimates is different.

Hope that helps,
Wayne

P.S. Florian, You are mistaken in the syntax that Mark is using. Mark is using:
S = spectrogram(X,WINDOW,NOVERLAP,NFFT,Fs)

Subject: Spectrogram output scaling = ?

From: Florin Neacsu

Date: 31 Mar, 2011 18:53:06

Message: 5 of 8

"Mark Proulx" <mark.p.proulx@boeing.com> wrote in message <in2hik$kh6$1@fred.mathworks.com>...
> "Florin Neacsu" <fneacsu2@gmail.com> wrote in message <in2gbp$hsq$1@fred.mathworks.com>...
> > "Mark Proulx" <mark.p.proulx@boeing.com> wrote in message <in2dql$2do$1@fred.mathworks.com>...
> > > From the documentation for the 'spectrogram' command:
> > >
> > > T = 0:0.001:2;
> > > X = chirp(T,0,1,150);
> > > [S,F,T,P] = spectrogram(X,256,250,256,1E3);
> > >
> > > I cannot determine the relationship between the amplitude of the components of X and the magnitude of the elements of S. In the example cited, the amplitude of X is 1 at all times. The corresponding maximum magnitude of S is approximately 40. What is the relationship between S and the amplitude of the underlying signal?
> >
> > Hi,
> >
> > This is not an answer to your question, but I was wondering; aren't you suppose to give as the 4th parameter F, as a vector with at least 2 values ?
> >
> > From matlab's documentation :
> > [S,F,T] = spectrogram(x,window,noverlap,F) uses
> > a vector F of frequencies in Hz. F must
> > be a vector with at least two elements
> >
> > and :
> >
> > T = 0:0.001:2;
> > X = chirp(T,0,1,150);
> > F = 0:.1:100;
> > [Y,F,T,P] = spectrogram(X,256,250,F,1E3,'yaxis');
> >
> > Regards,
> > Florin
>
> Florin:
>
> Thanks for the reply. I find the documentation on this issue confusing, in that it implies that the fourth parameter is the FFT block size, which I interpret the documentation to say provides a legitimate substitute for a vector "F." (I don't know that I'm correct in this, it's just what I think they mean ;-) )

Hi,

I think there is a difference if you call spectrogram with one or 3/4 outputs :


S = spectrogram(x,window,noverlap,nfft)
[S,F,T] = spectrogram(x,window,noverlap,F)

Florin

Subject: Spectrogram output scaling = ?

From: Florin Neacsu

Date: 31 Mar, 2011 18:58:05

Message: 6 of 8

"Wayne King" <wmkingty@gmail.com> wrote in message <in2ib0$9qu$1@fred.mathworks.com>...
> "Mark Proulx" <mark.p.proulx@boeing.com> wrote in message <in2dql$2do$1@fred.mathworks.com>...
> > From the documentation for the 'spectrogram' command:
> >
> > T = 0:0.001:2;
> > X = chirp(T,0,1,150);
> > [S,F,T,P] = spectrogram(X,256,250,256,1E3);
> >
> > I cannot determine the relationship between the amplitude of the components of X and the magnitude of the elements of S. In the example cited, the amplitude of X is 1 at all times. The corresponding maximum magnitude of S is approximately 40. What is the relationship between S and the amplitude of the underlying signal?
>
> Hi Mark, In order to understand that scaling you have to take into account the effect of the window, which is by default Hamming, and the length of the segments you are inputting to spectrogram. To show you a simple example with a rectangular window (which I'm not recommending to use by the way)
>
> t = 0:.001:1;
> x = cos(2*pi*100*t);
> [S,F,T,P] = spectrogram(x,ones(100,1),50,100,1E3);
> plot(abs(S(:,1)));
>
> Notice here that a unit amplitude sinusoid has mapped in absolute value to the length of the window (100) segment divided by 2.
>
> Note that is the same as:
>
> xdft = fft(x(1:100));
> plot(abs(xdft))
>
> Except the above shows both the negative and positive frequencies. The scaling is what I want to draw your attention to.
>
> Now if you use the default Hamming window:
>
> [S,F,T,P] = spectrogram(x,100,50,100,1E3);
> plot(abs(S(:,1)));
>
> That is the same as:
>
> xdft = fft(hamming(100)'.*x(1:100));
> plot(abs(xdft));
>
> Except that again, I'm plotting both the negative and positive frequencies with fft().
>
> The scaling on the modified periodogram estimates is different.
>
> Hope that helps,
> Wayne
>
> P.S. Florian, You are mistaken in the syntax that Mark is using. Mark is using:
> S = spectrogram(X,WINDOW,NOVERLAP,NFFT,Fs)


Dear Wayne King,

Thank you for the explanation you provided. It helped me understand too.
I believe OP's initial call was
T = 0:0.001:2;
X = chirp(T,0,1,150);
[S,F,T,P] = spectrogram(X,256,250,256,1E3);

Regards,
Florin

Subject: Spectrogram output scaling = ?

From: Wayne King

Date: 31 Mar, 2011 19:45:24

Message: 7 of 8

"Florin Neacsu" <fneacsu2@gmail.com> wrote in message <in2irt$kkd$1@fred.mathworks.com>...
> "Wayne King" <wmkingty@gmail.com> wrote in message <in2ib0$9qu$1@fred.mathworks.com>...
> > "Mark Proulx" <mark.p.proulx@boeing.com> wrote in message <in2dql$2do$1@fred.mathworks.com>...
> > > From the documentation for the 'spectrogram' command:
> > >
> > > T = 0:0.001:2;
> > > X = chirp(T,0,1,150);
> > > [S,F,T,P] = spectrogram(X,256,250,256,1E3);
> > >
> > > I cannot determine the relationship between the amplitude of the components of X and the magnitude of the elements of S. In the example cited, the amplitude of X is 1 at all times. The corresponding maximum magnitude of S is approximately 40. What is the relationship between S and the amplitude of the underlying signal?
> >
> > Hi Mark, In order to understand that scaling you have to take into account the effect of the window, which is by default Hamming, and the length of the segments you are inputting to spectrogram. To show you a simple example with a rectangular window (which I'm not recommending to use by the way)
> >
> > t = 0:.001:1;
> > x = cos(2*pi*100*t);
> > [S,F,T,P] = spectrogram(x,ones(100,1),50,100,1E3);
> > plot(abs(S(:,1)));
> >
> > Notice here that a unit amplitude sinusoid has mapped in absolute value to the length of the window (100) segment divided by 2.
> >
> > Note that is the same as:
> >
> > xdft = fft(x(1:100));
> > plot(abs(xdft))
> >
> > Except the above shows both the negative and positive frequencies. The scaling is what I want to draw your attention to.
> >
> > Now if you use the default Hamming window:
> >
> > [S,F,T,P] = spectrogram(x,100,50,100,1E3);
> > plot(abs(S(:,1)));
> >
> > That is the same as:
> >
> > xdft = fft(hamming(100)'.*x(1:100));
> > plot(abs(xdft));
> >
> > Except that again, I'm plotting both the negative and positive frequencies with fft().
> >
> > The scaling on the modified periodogram estimates is different.
> >
> > Hope that helps,
> > Wayne
> >
> > P.S. Florian, You are mistaken in the syntax that Mark is using. Mark is using:
> > S = spectrogram(X,WINDOW,NOVERLAP,NFFT,Fs)
>
>
> Dear Wayne King,
>
> Thank you for the explanation you provided. It helped me understand too.
> I believe OP's initial call was
> T = 0:0.001:2;
> X = chirp(T,0,1,150);
> [S,F,T,P] = spectrogram(X,256,250,256,1E3);
>
> Regards,
> Florin

Hi Florian, Yes, that is exactly what I said. I did not bother to specify all the output arguments, I just copied the line from the help file that Mark is using. He was not specifying a frequency vector to compute the STFT.

Wayne

Subject: Spectrogram output scaling = ?

From: Mark Proulx

Date: 31 Mar, 2011 19:52:05

Message: 8 of 8

"Wayne King" <wmkingty@gmail.com> wrote in message <in2ib0$9qu$1@fred.mathworks.com>...
> "Mark Proulx" <mark.p.proulx@boeing.com> wrote in message <in2dql$2do$1@fred.mathworks.com>...
> > From the documentation for the 'spectrogram' command:
> >
> > T = 0:0.001:2;
> > X = chirp(T,0,1,150);
> > [S,F,T,P] = spectrogram(X,256,250,256,1E3);
> >
> > I cannot determine the relationship between the amplitude of the components of X and the magnitude of the elements of S. In the example cited, the amplitude of X is 1 at all times. The corresponding maximum magnitude of S is approximately 40. What is the relationship between S and the amplitude of the underlying signal?
>
> Hi Mark, In order to understand that scaling you have to take into account the effect of the window, which is by default Hamming, and the length of the segments you are inputting to spectrogram. To show you a simple example with a rectangular window (which I'm not recommending to use by the way)
>
> t = 0:.001:1;
> x = cos(2*pi*100*t);
> [S,F,T,P] = spectrogram(x,ones(100,1),50,100,1E3);
> plot(abs(S(:,1)));
>
> Notice here that a unit amplitude sinusoid has mapped in absolute value to the length of the window (100) segment divided by 2.
>
> Note that is the same as:
>
> xdft = fft(x(1:100));
> plot(abs(xdft))
>
> Except the above shows both the negative and positive frequencies. The scaling is what I want to draw your attention to.
>
> Now if you use the default Hamming window:
>
> [S,F,T,P] = spectrogram(x,100,50,100,1E3);
> plot(abs(S(:,1)));
>
> That is the same as:
>
> xdft = fft(hamming(100)'.*x(1:100));
> plot(abs(xdft));
>
> Except that again, I'm plotting both the negative and positive frequencies with fft().
>
> The scaling on the modified periodogram estimates is different.
>
> Hope that helps,
> Wayne
>
> P.S. Florian, You are mistaken in the syntax that Mark is using. Mark is using:
> S = spectrogram(X,WINDOW,NOVERLAP,NFFT,Fs)

Wayne:

Huge thanks for the reply. I totally forgot about the need to divide by the block size and correct for the window. I'm working through your example now....

Tags for this Thread

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.

Contact us