Reply by navaneetha krishnan January 21, 20042004-01-21
--- Jeff Winter <> wrote:
>
> ...
>
> One final thing to remember. Strictly speaking the
> number of points in an
> FFT calculation should be 2^n i.e. a radix 2 value.
> Any non power of two
> value is really a DFT.
> ...
>
> Jeff

Nice answer Jeff.
A small correction.
FFT uses FFTW. The transform size need not be a power
of two to get fast algorithms compared to using direct
DFT formula. See algorithm section in
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fft.shtml?BB=1
and
http://www.fftw.org/fftw-paper.pdf

Regards,
Navan __________________________________


Reply by hentronix January 20, 20042004-01-20
Fs = 400 ; % sampling rate
Nres = 0.1 ; %spectral resolution of fft
Nfft = Fs/Nres ; % number of points in fft i.e 4000
%---------
% Ok, but is better a power of 2
%
%t = (1:64)/Fs ; %length of signal in time domain

t = 0:1/Fs:64;
sig1 = sin(2*pi*t*100); %100 Hz sinousidal signal
sig2 = sin(2*pi*t*100.5) ; %100.5Hz sinousidal signal
k = sig1+sig2 ; %Adding signal together
s = fft(k,Nfft) ; %Performing Nfft point fft

% X axis in frequency
f=(0:(Nfft/2)-1)*Fs/Nfft;

plot(f,abs(s(1:Nfft/2))); ; %I should see 100 and 100.5Hz
signal as
pause %seprate but they are mixed up
figure

plot(f,abs(s(1:Nfft/2)));axis([99 102 0 2500]),xlabel('Frequency in
Hz')
ylabel('Mag.'),grid

--- In , "maria_mount" <maria_mount@y...> wrote:
> Hi,
> i generate 2 signals in matlab and when i see there
spectrum ,the
> closely space signals mixed up here what i have done
>
> Fs = 400 ; % sampling rate
> Nres = 0.1 ; %spectral resolution of fft
> Nfft = fs/Nres ; % number of points in fft i.e 4000
> t = (1:64)/fs ; %length of signal in time domain
> sig1 = sin(2*pi*t*100); %100 Hz sinousidal signal
> sig2 = sin(2*pi*t*100.5) ; %100.5Hz sinousidal signal
> k = sig1+sig2 ; %Adding signal together
>
> s = fft(k,Nfft) ; %Performing Nfft point fft
> plot(abs(s)); ; %I should see 100 and 100.5Hz signal as
> %seprate but they are mixed up
>
> I tried using different windows before doing fft like
> hamming,hanning,kaiser,blackman but no sucssess
>
> can anyone tell me why i am not getting 2 signals
>
> Cheers
> Maria Mountford


Reply by hentronix January 20, 20042004-01-20
Hi Mar:

Try with this script.

Regards

Henry

Fs = 400 ; % sampling rate
Nres = 0.1 ; %spectral resolution of fft
Nfft = Fs/Nres ; % number of points in fft i.e 4000
%---------
% Ok, but is better a power of 2
%
%t = (1:64)/Fs ; %length of signal in time domain

t = 0:1/Fs:64;
sig1 = sin(2*pi*t*100); %100 Hz sinousidal signal
sig2 = sin(2*pi*t*100.5) ; %100.5Hz sinousidal signal
k = sig1+sig2 ; %Adding signal together
s = fft(k,Nfft) ; %Performing Nfft point fft

% X axis in frequency
f=(0:(Nfft/2)-1)*Fs/Nfft;

plot(f,abs(s(1:Nfft/2))); ; %I should see 100 and 100.5Hz
signal as
pause %seprate but they are mixed up
figure

plot(f,abs(s(1:Nfft/2)));axis([99 102 0 2500]),xlabel('Frequency in
Hz')
ylabel('Mag.'),grid

--- In , "maria_mount" <maria_mount@y...> wrote:
> Hi,
> i generate 2 signals in matlab and when i see there
spectrum ,the
> closely space signals mixed up here what i have done
>
> Fs = 400 ; % sampling rate
> Nres = 0.1 ; %spectral resolution of fft
> Nfft = fs/Nres ; % number of points in fft i.e 4000
> t = (1:64)/fs ; %length of signal in time domain
> sig1 = sin(2*pi*t*100); %100 Hz sinousidal signal
> sig2 = sin(2*pi*t*100.5) ; %100.5Hz sinousidal signal
> k = sig1+sig2 ; %Adding signal together
>
> s = fft(k,Nfft) ; %Performing Nfft point fft
> plot(abs(s)); ; %I should see 100 and 100.5Hz signal as
> %seprate but they are mixed up
>
> I tried using different windows before doing fft like
> hamming,hanning,kaiser,blackman but no sucssess
>
> can anyone tell me why i am not getting 2 signals
>
> Cheers
> Maria Mountford


Reply by Jeff Winter January 20, 20042004-01-20
Hi Maria,

I have modified your code as shown below. You will now get the two peaks
you where looking for. OK, so where did it go wrong? Well, you correctly
said that to get a resolution of 0.1Hz from a sampling frequency of 400Hz
would require 4000 points. What you then forgot to do is supply 4000 points
of data i.e. you didn't sample for long enough. Here is a summary of some useful techniques and rules to remember when
calculating FFTs:

To get better frequency resolution for a fixed sampling frequency (fs),
increase the number of samples (N).

To get better frequency resolution for a fixed number of samples, decrease
the sampling frequency. (But be careful here not to let fs fall below the
Nyquist criterion limit.)

To get frequency component information at higher frequencies, increase the
sampling frequency.

To reduce leakage in the frequency spectrum, do one or more of the
following:
Increase N (at the cost of more computer time).

Decrease fs (but do not sample at such a low frequency that the Nyquist
criterion is violated).
Multiply the time signal by a windowing function prior to taking the FFT (at
the cost of throwing away a significant portion of the samples, i.e. those
near the start and finish of the sampling time).

One final thing to remember. Strictly speaking the number of points in an
FFT calculation should be 2^n i.e. a radix 2 value. Any non power of two
value is really a DFT. I hope this all helps,

Jeff
fs = 400 ; % sampling rate
Nres = 0.1 ; %spectral resolution of fft
Nfft = fs/Nres ; % number of points in fft i.e 4000

t = (0:Nfft-1)/fs ; %length of signal in time domain
sig1 = sin(2*pi*t*100); %100 Hz sinousidal signal
sig2 = sin(2*pi*t*100.5) ; %100.5Hz sinousidal signal
k = sig1+sig2 ; %Adding signal together

s = fft(k,Nfft) ; %Performing Nfft point fft

Ys(s(1:length(s)/2)); % We only need to plot the first half of the fft as
it is symmetric
f=fs*(0:(Nfft/2)-1)/Nfft; % Calculate the frequency axis
plot(f,Y)
xlim([99 102]) % Set the x-axis so we can see the peaks

--------------------------
Jeff Winter
Snr Design Engineer
Aeroflex
www.aeroflex.com -----Original Message-----
From: maria_mount [mailto:]
Sent: Tuesday, January 20, 2004 7:59 AM
To:
Subject: [matlab] fft problem Hi,
i generate 2 signals in matlab and when i see there spectrum ,the
closely space signals mixed up here what i have done

Fs = 400 ; % sampling rate
Nres = 0.1 ; %spectral resolution of fft
Nfft = fs/Nres ; % number of points in fft i.e 4000
t = (1:64)/fs ; %length of signal in time domain
sig1 = sin(2*pi*t*100); %100 Hz sinousidal signal
sig2 = sin(2*pi*t*100.5) ; %100.5Hz sinousidal signal
k = sig1+sig2 ; %Adding signal together

s = fft(k,Nfft) ; %Performing Nfft point fft
plot(abs(s)); ; %I should see 100 and 100.5Hz signal as
%seprate but they are mixed up

I tried using different windows before doing fft like
hamming,hanning,kaiser,blackman but no sucssess

can anyone tell me why i am not getting 2 signals

Cheers
Maria Mountford

_____________________________________
Note: If you do a simple "reply" with your email client, only the author of
this message will receive your answer. You need to do a "reply all" if you
want your answer to be distributed to the entire group.

_____________________________________
About this discussion group:

To Join:

To Post:

To Leave:

Archives: http://www.yahoogroups.com/group/matlab

More DSP-Related Groups: http://www.dsprelated.com/groups.php3



Reply by maria_mount January 20, 20042004-01-20
Hi,
i generate 2 signals in matlab and when i see there spectrum ,the
closely space signals mixed up here what i have done

Fs = 400 ; % sampling rate
Nres = 0.1 ; %spectral resolution of fft
Nfft = fs/Nres ; % number of points in fft i.e 4000
t = (1:64)/fs ; %length of signal in time domain
sig1 = sin(2*pi*t*100); %100 Hz sinousidal signal
sig2 = sin(2*pi*t*100.5) ; %100.5Hz sinousidal signal
k = sig1+sig2 ; %Adding signal together

s = fft(k,Nfft) ; %Performing Nfft point fft
plot(abs(s)); ; %I should see 100 and 100.5Hz signal as
%seprate but they are mixed up

I tried using different windows before doing fft like
hamming,hanning,kaiser,blackman but no sucssess

can anyone tell me why i am not getting 2 signals

Cheers
Maria Mountford