[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: resolution in the fft
From: |
Matthias Brennwald |
Subject: |
Re: resolution in the fft |
Date: |
Wed, 10 Jun 2009 07:58:41 +0200 |
On Jun 9, 2009, at 8:46 PM, address@hidden wrote:
Message: 5
Date: Tue, 09 Jun 2009 20:34:49 +0200
From: Markus Feldmann <address@hidden>
Subject: resolution in the fft
To: address@hidden
Message-ID: <address@hidden>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Hi All,
i made a spectrum on a charge/discharge function, but i am not sure
how
to raise the xscale resoultion in my spectrum.
Any ideas ?
Here comes my function:
%Konstanten
FS=10e6
T1=1e-6;
T2=2e-6;
t1=0:1/FS:5e-6;
t2=0:0.1e-6:10e-6;
t=[t1,t2+t1(end)];
U0=10;
%charge
u1=U0*(1-exp(-t1/T1));
%discharge
u2=U0*exp(-t2/T2);
u=[u1,u2];
subplot(2,1,1)
plot(t,u,'-+o')
xlabel('Time/s');
ylabel('Voltage/V');
grid('on')
%FFT
nfft= 2^(nextpow2(length(u)))
fftu = fft(u,nfft);
NumUniquePts = ceil((nfft+1)/2)
fftu = fftu(1:NumUniquePts);
mu = abs(fftu)/length(u);
mu = mu.^2;
if rem(nfft, 2)
mu(2:end) = mu(2:end)*2;
else
mu(2:end -1) = mu(2:end -1)*2;
end
f = (0:NumUniquePts-1)*FS/nfft;
subplot(2,1,2)
plot(f,mu,'-+o')
xlabel('Frequency/Hz');
ylabel('Power');
grid('on')
axis([0,1e6])
print -deps >exponential.eps
Dear Markus
1. The short answer is: you can't increase the resolution of the fft,
because the resolution is given by the number of samples in your signal.
2. The somewhat longer answer is: you can increase the resolution of
the fft by adding more samples to your signal. You can do this either
by using a higher sampling rate (I'd recommend to do this if possible)
or by padding zeroes at the end of the signal (I'd classify this as
cheating, though).
Apart from that I believe you do not need the line "nfft=
2^(nextpow2(length(u)))". I modified your code accordingly (see below).
Matthias
---------------------------------------
FS=10e6
T1=1e-6;
T2=2e-6;
t1=0:1/FS:5e-6;
t2=0:0.1e-6:10e-6;
t=[t1,t2+t1(end)];
U0=10;
%charge
u1=U0*(1-exp(-t1/T1));
%discharge
u2=U0*exp(-t2/T2);
u=[u1,u2];
subplot(2,1,1)
plot(t,u,'-+o')
xlabel('Time/s');
ylabel('Voltage/V');
grid('on')
%FFT
% nfft= 2^(nextpow2(length(u)))
fftu = fft(u); % the fft function is smart enough to handle any non-
power-of-2 length
NumUniquePts = ceil((length(u)+1)/2)
fftu = fftu(1:NumUniquePts);
mu = abs(fftu)/length(u);
mu = mu.^2;
if rem(length(u), 2)
mu(2:end) = mu(2:end)*2;
else
mu(2:end -1) = mu(2:end -1)*2;
end
f = (0:NumUniquePts-1)*FS/nfft;
subplot(2,1,2)
plot(f,mu,'-+o')
xlabel('Frequency/Hz');
ylabel('Power');
grid('on')
axis([0,1e6])
print -deps >exponential.eps
---------------------------------------