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:
Realtion between output amplitude of spectrogram and fft?

Subject: Realtion between output amplitude of spectrogram and fft?

From: Sebastian Gatzka

Date: 16 Dec, 2011 10:27:08

Message: 1 of 4

Hello World.

I'm trying to create a spectrogram which output amplitude is identical to the output of the classical fourier transformation.

I don't need the PSD (which I'm not familiar with) but tried to manipluate the short time fourier ouput.

If I do a FFT I divide the output of the fft with the length of the original signal to get the correct amplitude I will find in the signal.

With the spectrogram I'm not sure how to do this because it's not clear to me how to dertermine how many samples are actually contained in the spectrogram output when using short-time windowing and overlap.

My FFT looks like this:

fs = 100e3; % sampling frequency
m = size(signal,2);
n = 2^nextpow2(m);
y = fft(signal-mean(signal),n);
y = y/m;
a = abs(y);
f = (0:n/2-1)*(fs/n);
plot(f,2*a(1:n/2));

and the spectorgam like this (so far):

[S,F,T,P] = spectrogram(signal-mean(signal),hamming(hammingWindowSize),hammingWindowSize*0.5,[],fs);

So again: How do I have to mainipulate the matrix S to contain elements which do have the same amplitude as the elements in 2*a from the FFT?

Hope anyone can help.
Sebastian

Subject: Realtion between output amplitude of spectrogram and fft?

From: TideMan

Date: 16 Dec, 2011 20:11:43

Message: 2 of 4

On Dec 16, 11:27 pm, "Sebastian Gatzka"
<sebastian.gatzka.NOS...@stud.tu-darmstadt.de> wrote:
> Hello World.
>
> I'm trying to create a spectrogram which output amplitude is identical to the output of the classical fourier transformation.
>
> I don't need the PSD (which I'm not familiar with) but tried to manipluate the short time fourier ouput.
>
> If I do a FFT I divide the output of the fft with the length of the original signal to get the correct amplitude I will find in the signal.
>
> With the spectrogram I'm not sure how to do this because it's not clear to me how to dertermine how many samples are actually contained in the spectrogram output when using short-time windowing and overlap.
>
> My FFT looks like this:
>
> fs = 100e3; % sampling frequency
> m = size(signal,2);
> n = 2^nextpow2(m);
> y = fft(signal-mean(signal),n);
> y = y/m;
> a = abs(y);
> f = (0:n/2-1)*(fs/n);
> plot(f,2*a(1:n/2));
>
> and the spectorgam like this (so far):
>
> [S,F,T,P] = spectrogram(signal-mean(signal),hamming(hammingWindowSize),hammingWindowSize*0.5,[],fs);
>
> So again: How do I have to mainipulate the matrix S to contain elements which do have the same amplitude as the elements in 2*a from the FFT?
>
> Hope anyone can help.
> Sebastian

I think this line:
 y = y/m;
should be:
 y = y/n;
because FFT knows nothing about the length of your signal, only the
length you enter into fft.
And, BTW, you don't need to use dyadic numbers, so you can dispense
with nextpow2 and just use m in the fft.

But in any case, you can check using Parseval's Theorem which says
that the variance of the signal i.e. var(signal padded with zeros if
necessary) must equal the sum of squares of the amplitudes sum(a.^2)

Subject: Realtion between output amplitude of spectrogram and fft?

From: Greg Heath

Date: 17 Dec, 2011 07:57:33

Message: 3 of 4

On Dec 16, 5:27 am, "Sebastian Gatzka"
<sebastian.gatzka.NOS...@stud.tu-darmstadt.de> wrote:
> Hello World.
>
> I'm trying to create a spectrogram which output amplitude is identical to the output of the classical fourier transformation.
>
> I don't need the PSD (which I'm not familiar with) but tried to manipluate the short time fourier ouput.
>
> If I do a FFT I divide the output of the fft with the length of the original signal to get the correct amplitude I will find in the signal.
>
> With the spectrogram I'm not sure how to do this because it's not clear to me how to dertermine how many samples are actually contained in the spectrogram output when using short-time windowing and overlap.
>
> My FFT looks like this:
>
> fs = 100e3; % sampling frequency
> m = size(signal,2);
> n = 2^nextpow2(m);

Your computer is so fast that zero-padding is unnecessary
unless m is huge.

> y = fft(signal-mean(signal),n);
> y = y/m;

Never a good practice to use the same variable on both
sides of an assignment statement.

> a = abs(y);
> f = (0:n/2-1)*(fs/n);
> plot(f,2*a(1:n/2));

 f = (0:n-1)*(fs/n); % Original double-
sided
fss = (0:n/2)*fs/n ; % Single-sided; n even
ass = [a(1) 2*a(2:n/2) a(n/2+1)]; % DC and Nyquist not doubled.
plot(fss(1:n/2+1), ass );

However, I'm not sure of the rest (unfamiliarity of spectrogram).

> and the spectorgam like this (so far):
>
> [S,F,T,P] = spectrogram(signal-mean(signal),hamming(hammingWindowSize),hammingWindowSiz­e*0.5,[],fs);
>
> So again: How do I have to mainipulate the matrix S to contain elements which do have the same amplitude as the elements in 2*a from >the FFT?

Hope this helps.

Greg

Subject: Realtion between output amplitude of spectrogram and fft?

From: Sebastian Gatzka

Date: 18 Dec, 2011 16:25:08

Message: 4 of 4

Thanks for your replies and the discussion about FFT, which I have taken into account.

But as a matter of fact I'm more interested in how to manipulate the output of the spectogram to have an amplitude equal to the FFT.

Any ideas on this topic?

Thanks! sega

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