Thread Subject: Effect of sampling frequency for FFT

Subject: Effect of sampling frequency for FFT

From: juho salminen

Date: 30 Oct, 2009 15:01:04

Message: 1 of 12

Hi,

I have done some tests with artificial sinusoidial data with white noise added on it. It seems, that the higher sampling frequency I have, the better is signal to noise ratio in FFT. With this I mean, that I take FFT with constant window length, let's say 500 samples. Signal itself is kept constant, let's say 30Hz.
Highter sampling frequency then, of course, reduces the time window size.
This should simulate measurements of some sinusoid with different sampling frequencies

Do you know what would cause better SNG values, when sampling frequency increases?

Thanks already for answers,

-Juho

Subject: Effect of sampling frequency for FFT

From: juho salminen

Date: 30 Oct, 2009 15:11:01

Message: 2 of 12

"juho salminen" <jssalmi3@cc.hut.fi> wrote in message <hcev3g$lej$1@fred.mathworks.com>...
> Hi,
>
> I have done some tests with artificial sinusoidial data with white noise added on it. It seems, that the higher sampling frequency I have, the better is signal to noise ratio in FFT. With this I mean, that I take FFT with constant window length, let's say 500 samples. Signal itself is kept constant, let's say 30Hz.
> Highter sampling frequency then, of course, reduces the time window size.
> This should simulate measurements of some sinusoid with different sampling frequencies
>
> Do you know what would cause better SNG values, when sampling frequency increases?
>
> Thanks already for answers,
>
> -Juho

Note: I am talking about SNR (!) for detecting amplitde of signal. Amplitudes seem to be always closer to right value, when sampling frequency is increased

Subject: Effect of sampling frequency for FFT

From: Matt

Date: 30 Oct, 2009 15:25:20

Message: 3 of 12

"juho salminen" <jssalmi3@cc.hut.fi> wrote in message <hcev3g$lej$1@fred.mathworks.com>...

> Highter sampling frequency then, of course, reduces the time window size.

By time-frequency duality, windowing in the time domain is equivalent to low-pass filtering the frequency spectrum. By decreasing the window-size you are applying a low pass filter to your spectral data of lower and lower cut-offs and hence greater and greater smoothing.

Subject: Effect of sampling frequency for FFT

From: juho salminen

Date: 30 Oct, 2009 22:19:05

Message: 4 of 12

"Matt " <xys@whatever.com> wrote in message <hcf0h0$kqk$1@fred.mathworks.com>...
> "juho salminen" <jssalmi3@cc.hut.fi> wrote in message <hcev3g$lej$1@fred.mathworks.com>...
>
> > Highter sampling frequency then, of course, reduces the time window size.
>
> By time-frequency duality, windowing in the time domain is equivalent to low-pass filtering the frequency spectrum. By decreasing the window-size you are applying a low pass filter to your spectral data of lower and lower cut-offs and hence greater and greater smoothing.

Sorry for inconvenience, what I meaned was, that actual FFT window size is always the same, let's say 500 points. But, when I sample artificial signal with highter sampling frequency, Amplitude of sine wave in FFT is much more accurate than with lower sampling frequency.

For example, 1. I sample some artificial noisy sine wave with 50Hz, and I collect 5000samples, 2. I sample some artificial sine wave with 200Hz, and I collect 5000samples, the second case gives more accurate amplitude results in FFT

Subject: Effect of sampling frequency for FFT

From: dpb

Date: 30 Oct, 2009 22:39:04

Message: 5 of 12

juho salminen wrote:
...

> For example, 1. I sample some artificial noisy sine wave with 50Hz,
> and I collect 5000samples, 2. I sample some artificial sine wave with
> 200Hz, and I collect 5000samples, the second case gives more accurate
> amplitude results in FFT

That is, in essence, the same effect as fitting any function--you've got
more information to work with that defines the resolution of the shape
of the curve more distinctly.

--

Subject: Effect of sampling frequency for FFT

From: Greg Heath

Date: 1 Nov, 2009 06:27:46

Message: 6 of 12

On Oct 30, 11:01 am, "juho salminen" <jssal...@cc.hut.fi> wrote:
> Hi,
>
> I have done some tests with artificial sinusoidial data with white noise added on it. It seems, that the higher sampling frequency I have, the better is signal to noise ratio in FFT. With this I mean, that I take FFT with constant window length, let's say 500 samples. Signal itself is kept constant, let's say 30Hz.
> Highter sampling frequency then, of course, reduces the time window size.
> This should simulate measurements of some sinusoid with  different sampling frequencies
>
> Do you know what would cause better SNG values, when sampling frequency increases?

SNR is independent of Fs.

close all, clear all, clc

f0 = 30
N = 500
S = 5
Ps = 5^2/2 % = 12.5 Signal Power
N0 = 1
Pn = 1 % = 1 Noise Power
SNR0 = Ps/Pn % 12.5
M = 30 % No. of trials

rand('state',0)
randn('state',0)

for i = 1:M

    Fs(i) = f0*i; % Sampling Frequency
    dt = 1/Fs(i)
    t = dt*(0:N-1);
    s = S*cos(2*pi*(f0*t+rand(1,N)));
    n = N0*randn(1,N);

    vars(i) = var(s);
    varn(i) = var(n);
    SNR(i) = var(s)/var(n);

end

summary = [Fs' vars' varn' SNR']
meansummary = mean(summary(:,2:4))
stdsummary = std(summary(:,2:4))
meanSNR = meansummary(3)
stdSNR = stdsummary(3)

figure,hold on
plot(Fs,SNR0*ones(1,M),'k')
plot(Fs,meanSNR*ones(1,M),'r')
plot(Fs,(meanSNR-stdSNR)*ones(1,M),'r--')
plot(Fs,(meanSNR+stdSNR)*ones(1,M),'r--')
plot(Fs,SNR)
axis([0 M*f0 0 20])
xlabel('Sampling Frequency (Hz)')
ylabel('Signal-to-Noise Ratio')
title('SNR Estimate vs Sampling Frequency')

Subject: Effect of sampling frequency for FFT

From: Greg Heath

Date: 1 Nov, 2009 06:36:22

Message: 7 of 12

On Nov 1, 2:27 am, Greg Heath <he...@alumni.brown.edu> wrote:
> On Oct 30, 11:01 am, "juho salminen" <jssal...@cc.hut.fi> wrote:
>
> > Hi,
>
> > I have done some tests with artificial sinusoidial data with white noise added on it. It seems, that the higher sampling frequency I have, the better is signal to noise ratio in FFT. With this I mean, that I take FFT with constant window length, let's say 500 samples. Signal itself is kept constant, let's say 30Hz.
> > Highter sampling frequency then, of course, reduces the time window size.
> > This should simulate measurements of some sinusoid with  different sampling frequencies
>
> > Do you know what would cause better SNG values, when sampling frequency increases?
>
> SNR is independent of Fs.
-----SNIP

Whoops. You mean SNR of the FFT.
I'll look at that now.
Greg

Subject: Effect of sampling frequency for FFT

From: Greg Heath

Date: 2 Nov, 2009 05:06:34

Message: 8 of 12


On Nov 1, 2:27 am, Greg Heath <he...@alumni.brown.edu> wrote:
> On Oct 30, 11:01 am, "juho salminen" <jssal...@cc.hut.fi> wrote:
>
> > Hi,
>
> > I have done some tests with artificial sinusoidial data with white noise added on it. It seems, that the higher sampling frequency I have, the better is signal to noise ratio in FFT. With this I mean, that I take FFT with constant window length, let's say 500 samples. Signal itself is kept constant, let's say 30Hz.
> > Highter sampling frequency then, of course, reduces the time window size.
> > This should simulate measurements of some sinusoid with different sampling frequencies
>
> > Do you know what would cause better SNG values, when sampling frequency increases?
>
> SNR is independent of Fs.
>
> close all, clear all, clc
>
> f0 = 30
> N = 500
> S = 5
> Ps = 5^2/2 % = 12.5 Signal Power
> N0 = 1
> Pn = 1 % = 1 Noise Power
> SNR0 = Ps/Pn % 12.5
> M = 30 % No. of trials
>
> rand('state',0)
> randn('state',0)
>
> for i = 1:M
>
> Fs(i) = f0*i; % Sampling Frequency
> dt = 1/Fs(i)
> t = dt*(0:N-1);
> s = S*cos(2*pi*(f0*t+rand(1,N)));

      s = S*cos(2*pi*(f0*t+rand));

> n = N0*randn(1,N);
>
> vars(i) = var(s);
> varn(i) = var(n);
> SNR(i) = var(s)/var(n);
>
> end
>
> summary = [Fs' vars' varn' SNR']
-----SNIP

% Exclude cases Fs < = 2*f0
meansummary = mean(summary(3:M,2:4))
stdsummary = std(summary(3:M,,2:4))
> meanSNR = meansummary(3)
> stdSNR = stdsummary(3)
-----SNIP

 % Restricting to Fs > 2*f0.

Fs1 = Fs(3:M);
M1 = M-2

figure,hold on
plot(Fs1,SNR0*ones(1,M1),'k')
plot(Fs1,meanSNR*ones(1,M1),'r')
plot(Fs1,(meanSNR-stdSNR)*ones(1,M1),'r--')
plot(Fs1,(meanSNR+stdSNR)*ones(1,M1),'r--')
plot(Fs1,SNR(3:M))

> axis([0 M*f0 0 20])
> xlabel('Sampling Frequency (Hz)')
> ylabel('Signal-to-Noise Ratio')
> title('SNR Estimate vs Sampling Frequency')

Hope this helps.

Greg

Subject: Effect of sampling frequency for FFT

From: juho salminen

Date: 2 Nov, 2009 07:51:02

Message: 9 of 12

Greg Heath <heath@alumni.brown.edu> wrote in message <d65291df-9d35-4375-abf6-1915e52fc5c6@m1g2000vbi.googlegroups.com>...
>
> On Nov 1, 2:27 am, Greg Heath <he...@alumni.brown.edu> wrote:
> > On Oct 30, 11:01 am, "juho salminen" <jssal...@cc.hut.fi> wrote:
> >
> > > Hi,
> >
> > > I have done some tests with artificial sinusoidial data with white noise added on it. It seems, that the higher sampling frequency I have, the better is signal to noise ratio in FFT. With this I mean, that I take FFT with constant window length, let's say 500 samples. Signal itself is kept constant, let's say 30Hz.
> > > Highter sampling frequency then, of course, reduces the time window size.
> > > This should simulate measurements of some sinusoid with different sampling frequencies
> >
> > > Do you know what would cause better SNG values, when sampling frequency increases?
> >
> > SNR is independent of Fs.
> >
> > close all, clear all, clc
> >
> > f0 = 30
> > N = 500
> > S = 5
> > Ps = 5^2/2 % = 12.5 Signal Power
> > N0 = 1
> > Pn = 1 % = 1 Noise Power
> > SNR0 = Ps/Pn % 12.5
> > M = 30 % No. of trials
> >
> > rand('state',0)
> > randn('state',0)
> >
> > for i = 1:M
> >
> > Fs(i) = f0*i; % Sampling Frequency
> > dt = 1/Fs(i)
> > t = dt*(0:N-1);
> > s = S*cos(2*pi*(f0*t+rand(1,N)));
>
> s = S*cos(2*pi*(f0*t+rand));
>
> > n = N0*randn(1,N);
> >
> > vars(i) = var(s);
> > varn(i) = var(n);
> > SNR(i) = var(s)/var(n);
> >
> > end
> >
> > summary = [Fs' vars' varn' SNR']
> -----SNIP
>
> % Exclude cases Fs < = 2*f0
> meansummary = mean(summary(3:M,2:4))
> stdsummary = std(summary(3:M,,2:4))
> > meanSNR = meansummary(3)
> > stdSNR = stdsummary(3)
> -----SNIP
>
> % Restricting to Fs > 2*f0.
>
> Fs1 = Fs(3:M);
> M1 = M-2
>
> figure,hold on
> plot(Fs1,SNR0*ones(1,M1),'k')
> plot(Fs1,meanSNR*ones(1,M1),'r')
> plot(Fs1,(meanSNR-stdSNR)*ones(1,M1),'r--')
> plot(Fs1,(meanSNR+stdSNR)*ones(1,M1),'r--')
> plot(Fs1,SNR(3:M))
>
> > axis([0 M*f0 0 20])
> > xlabel('Sampling Frequency (Hz)')
> > ylabel('Signal-to-Noise Ratio')
> > title('SNR Estimate vs Sampling Frequency')
>
> Hope this helps.
>
> Greg


Hi,

doesn't this basically mean, that there is no SNR improvement, when sampling frequency is increased?

-Juho

Subject: Effect of sampling frequency for FFT

From: juho salminen

Date: 2 Nov, 2009 07:59:04

Message: 10 of 12

Btw, thanks for all the effort!

Subject: Effect of sampling frequency for FFT

From: Greg Heath

Date: 2 Nov, 2009 12:01:10

Message: 11 of 12


On Nov 2, 3:51 am, "juho salminen" <jssal...@cc.hut.fi> wrote:
> Greg Heath <he...@alumni.brown.edu> wrote in message <d65291df-9d35-4375-abf6-1915e52fc...@m1g2000vbi.googlegroups.com>...
>
> > On Nov 1, 2:27 am, Greg Heath <he...@alumni.brown.edu> wrote:
> > > On Oct 30, 11:01 am, "juho salminen" <jssal...@cc.hut.fi> wrote:
>
> > > > Hi,
>
> > > > I have done some tests with artificial sinusoidial data with white noise added on it. It seems, that the higher sampling frequency I have, the better is signal to noise ratio in FFT. With this I mean, that I take FFT with constant window length, let's say 500 samples. Signal itself is kept constant, let's say 30Hz.
> > > > Highter sampling frequency then, of course, reduces the time window size.
> > > > This should simulate measurements of some sinusoid with different sampling frequencies
>
> > > > Do you know what would cause better SNG values, when sampling frequency increases?
>
> > > SNR is independent of Fs.

-----SNIP (Revised code below)

close all, clear all, clc

f0 = 30
N = 500
S0 = 5 % Sinusoidal amplitude
SNR0 = 15 % Signal-to-Noise Ratio
M = 100 % No. of trials

Ps = S0^2/2 % 12.5 Signal Power
Pn = Ps/SNR0 % 0.8333 Noise Power
N0 = sqrt(Pn) % S0/sqrt(2*SNR0) = 0.9129

rand('state',0)
randn('state',0)

for i = 1:M

    Fs(i) = f0*i; % Sampling Frequency
    dt = 1/Fs(i);
    t = dt*(0:N-1);
    s = S0*cos(2*pi*(f0*t+rand));
    n = N0*randn(1,N);

    vars(i) = var(s);
    varn(i) = var(n);
    SNR(i) = var(s)/var(n);

end

summary = [Fs' vars' varn' SNR'];

% Restricting to Fs > 2*f0.

meansummary = mean(summary(3:M,2:4))
% 12.5174 0.8428 14.9103

stdsummary = std(summary(3:M,2:4))
% 0.1117 0.0519 0.9746

meanSNR = meansummary(3)
stdSNR = stdsummary(3)
Fs1 = Fs(3:M);
M1 = M-2

figure,hold on
plot(Fs1,SNR0*ones(1,M1),'k')
plot(Fs1,SNR(3:M))
plot(Fs1,meanSNR*ones(1,M1),'r')
plot(Fs1,(meanSNR-stdSNR)*ones(1,M1),'r--')
plot(Fs1,(meanSNR+stdSNR)*ones(1,M1),'r--')
legend('True SNR','SNR Estimate',...
       ['meanSNR = ',num2str(meanSNR)], ...
       ['stdSNR = ',num2str(stdSNR)],4)
axis([0 M*f0 0 20])
xlabel('Sampling Frequency (Hz)')
ylabel('Signal-to-Noise Ratio')
title('SNR Estimate vs Sampling Frequency')

Hope this helps.

Greg

> Hi,
>
> doesn't this basically mean, that there is no SNR improvement, when sampling
> frequency is increased?

Yes. I repeat:

"SNR is independent of Fs"

The example indicates that Power based estimates of SNR are ~14.9103
+/- 0.9746
independently of Fs, when the true value is SNR = 15.

However, although your OP posed the question in terms of estimating
SNR vs Fs, your
followup post indicated that you are really interested in using the
FFT to estimate the
amplitude of a sine wave corrupted by noise.

In the latter case the simulation in my next post shows that peak-
picking FFT estimates
of both the frequency and amplitude degrade as Fs increases.

The basic reason appears to be that the FFT frequency spacing df = Fs/
N increases
as Fs increases with N = constant.

Hope this helps.

Greg

Subject: Effect of sampling frequency for FFT

From: Greg Heath

Date: 2 Nov, 2009 12:06:57

Message: 12 of 12

On Nov 1, 2:36 am, Greg Heath <he...@alumni.brown.edu> wrote:
> On Nov 1, 2:27 am, Greg Heath <he...@alumni.brown.edu> wrote:> On Oct 30, 11:01 am, "juho salminen" <jssal...@cc.hut.fi> wrote:
>
> > > Hi,
>
> > > I have done some tests with artificial sinusoidial data with white noise added on it. It seems, that the higher sampling frequency I have, the better is signal to noise ratio in FFT. With this I mean, that I take FFT with constant window length, let's say 500 samples. Signal itself is kept constant, let's say 30Hz.
> > > Highter sampling frequency then, of course, reduces the time window size.
> > > This should simulate measurements of some sinusoid with  different sampling frequencies
>
> > > Do you know what would cause better SNG values, when sampling frequency increases?
>
> > SNR is independent of Fs.
>
> -----SNIP
>
> Whoops. You mean SNR of the FFT.
> I'll look at that now.

Although your OP posed the question in terms of estimating SNR vs Fs,
I
interpret your above comments to mean that you are really interested
in
using the FFT to estimate the amplitude of a sine wave corrupted by
noise.

In the latter case the simulation below shows that peak-picking FFT
estimates
of both the frequency and amplitude degrade as Fs increases.

The basic reason appears to be the FFT frequency spacing df = Fs/N
increases
as Fs increases with N = constant.

close all, clear all, clc, k = 0

f0 = 30
N = 500
S0 = 5 % Sinusoidal amplitude
SNR0 = 15 % Signal-to-Noise Ratio
M = 100 % No. of trials

Ps = S0^2/2 % 12.5 Signal Power
Pn = Ps/SNR0 % 0.8333 Noise Power
N0 = sqrt(Pn) % S0/sqrt(2*SNR0) = 0.9129

rand('state',0)
randn('state',0)

for i = 1:M

    i = i
    Fs(i) = f0*i; % Sampling Frequency
    dt = 1/Fs(i);
    t = dt*(0:N-1);
    s = S0*cos(2*pi*(f0*t+rand));
    n = N0*randn(1,N);
    z = s+n;
    meanz = mean(z)
    check1 = meanz - mean(n)
    z = z - mean(z); % Exclude DC

% k = k+1,figure(k),hold on
% plot(t,s)
% plot(t,n,'g')
% plot(t,z,'r')
% xlabel('Time')
% ylabel('Signal and Noise')

    df = Fs(i)/N; % Frequency Resolution
    Q = ceil((N+1)/2); % No. unique points
    f = df*(0:Q-1); % One-sided spectrum
    Z = fft(z-mean(z))/N ; % Aliased for Fs <= 2*f0
    absZ = abs(Z);
    PSD = N*(absZ.^2);
    check2 = sum(PSD)-sumsqr(z)

    absZ1 = [absZ(1),sqrt(2)*absZ(2:Q-1),absZ(Q)];%Single Sided
    check2 = max(abs(sum(absZ1.^2)-sum(absZ.^2)))

    [S(i) I(i)] = max(sqrt(2)*absZ1); %Dominant Amplitude
    fmax(i) = f(I(i));

    if(i==1),k=k+1; figure(k), end

    plot(f(1:Q),sqrt(2)*absZ1),hold on
    plot(fmax(i),S(i),'or'),hold off
    xlim([0 60])
    xlabel('Frequency')
    ylabel('Amplitude')
    title(['Dominant Peak Estimate for Fs = ',num2str(Fs(i))])
 end

k=k+1; figure(k)
subplot(2,1,1)
plot(Fs(3:M),fmax(3:M))
ylabel('Dominant Frequency')
subplot(2,1,2)
plot(Fs(3:M),S(3:M))
xlabel('Sampling Frequency')
ylabel('Peak Amplitude')

Hope this helps.

Greg

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
fft juho 30 Oct, 2009 11:04:02
sampling frequency juho 30 Oct, 2009 11:04:02
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com