what is difference between fft(x) & fft(x,n)

10 次查看(过去 30 天)
nag
nag 2014-2-25
评论: Kiki 2016-3-24
clc; close all; clear all;
fc=1000; fs=15000; f1=1/fs; t=[0:f1:1-f1]; x=sin(2*pi*fc*t); figure; plot(t(1:100),x(1:100)); xlabel('time'); ylabel('amplitude'); title('Sine wave of Frequency 1 KHz');
fc=2000; f1=1/fs; t=[0:f1:1-f1]; y=sin(2*pi*fc*t); figure; plot(t(1:100),y(1:100)); xlabel('time'); ylabel('amplitude'); title('Sine wave of Frequency 2 KHz');
z=x+y; figure; plot(t(1:100),z(1:100)); xlabel('time'); ylabel('amplitude'); title('Mixed signal');
z1=fft(z,4096); len=length(z1); zdft = (1/len)*z1; freq=0:(fs/len):fs/2-(fs/len); figure; plot(freq,abs(zdft(1:len/2))) xlabel('Frequency'); ylabel('amplitude'); title('Single sided Frequency Spectrum');
In this code at z1 if we use fft(x) i am getting 2Hz width at 2K frequency in frequency spectrum,But if i use fft(x,4096) i am getting width of 20-30 Hz at 2K frequency....Why is this so , Can any one explain the reason.

回答(2 个)

Dishant Arora
Dishant Arora 2014-2-25
fft(x) computes discrete fourier transform having as many samples as the original signal x whereas fft(x,n) will have n points in dft. Usually n is taken as integral power of 2 to fasten the computation. In order to recover original signal from fft, number of samples in fft must be greater than or equal to number of samples in original signal . As n increases resolution in frequency domain increases i.e the distance between two consecutive frequency bins decreases .

Rick Rosson
Rick Rosson 2014-2-25
Compare:
>> dF_1 = fs/length(z)
with:
>> dF_2 = fs/length(z1)
  1 个评论
Kiki
Kiki 2016-3-24
Hi
I had a similar question. My codes are as follows.
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 1000; % Length of signal
t = (0:L-1)*T; % Time vector
S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
n=L;
Y2 = fft(S,n);
P22 = abs(Y2/n);
P11 = P22(1:n/2+1);
P11(2:end-1) = 2*P11(2:end-1);
f2 = Fs*(0:(n/2))/n;
figure(4)
plot(f2,P11)
title('1000 Point DFT Single-Sided Amplitude Spectrum of S(t)')
xlabel('f (Hz)')
ylabel('|P11(f)|')
n=4096;
Y2 = fft(S,n);
P22 = abs(Y2/n);
P11 = P22(1:n/2+1);
P11(2:end-1) = 2*P11(2:end-1);
f2 = Fs*(0:(n/2))/n;
figure(5)
plot(f2,P11)
title('1024 Point DFT Single-Sided Amplitude Spectrum of S(t)')
xlabel('f (Hz)')
ylabel('|P11(f)|')
n=1000 gives me a perfect spectrum with narrowest main lobe and 0 side lobes, while n=1024 gives me a wider main lobe and some side lobes. I thought bigger N would give us better frequency solution, but why would it add some "noise" to it?
Thank you very much! Kiki

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by