how to change the window length???

조회 수: 19 (최근 30일)
raj
raj 2012년 1월 26일
I am implementing an FFT over 2 sin signals which are placed at frequencies 300Hz and 380 Hz as the frequency components are very close to each other,I cant resolve then and i know if i increase the window length tbut i cannot change the window length is it possible to change window length in a normal FFT or should i consider the STFT???

채택된 답변

Wayne King
Wayne King 2012년 1월 26일
Yes in the sense that they will typically change the DFT bin in which they are located, but you have to remember that the frequency axis changes too, which you did not do above.
Fs = 1e3;
t = 0:1/Fs:(100*1/Fs)-1/Fs;
x = cos(2*pi*300*t)+cos(2*pi*310*t);
xdft = fft(x,256);
freq = 0:Fs/256:500;
stem(freq,abs(xdft(1:256/2+1)));
xlabel('Hz'); ylabel('Magnitude');

추가 답변 (5개)

Wayne King
Wayne King 2012년 1월 26일
Hi Raj, The frequency resolution depends on the length of the signal and the sampling frequency. The DFT bins are spaced as Fs/N, where Fs is the sampling frequency and N is the length of the input signal. Are you able to increase your signal length?
The STFT is surely going to worsen your frequency resolution because you will be segmenting your signal in order to have some time-frequency analysis.
  댓글 수: 2
raj
raj 2012년 1월 26일
Hallo wayne ,but does the window length has no effect over the frequency resolution and i cant vary my signal length if i have to change the window length should i apply zero padding to my signal.
raj
raj 2012년 1월 26일
IS this the correct way to apply window
x = sin(2*pi*300*t)+sin(2*pi*380*t);
y1 = fft(x,256);
win1 = hamming(256)';
xw1 = win1.*y1;

댓글을 달려면 로그인하십시오.


Wayne King
Wayne King 2012년 1월 26일
You don't tell us what the size of your t vector is. Applying a window is going to worsen frequency resolution because it broadens the main lobe.
You apply the window in the time domain, not in the frequency domain.
Fs = 100;
t = 0:1/100:1-1/100;
x = cos(2*pi*20*t)+randn(size(t));
x = x'.*hamming(length(x));
xdft = fft(x);
Perhaps your problem in resolving the peaks is because you applied a Hamming window to the DFT coefficients.
  댓글 수: 1
raj
raj 2012년 1월 26일
suppose i consider a rectangular window(or no window) and i have two frequency components(like 300Hz and 350Hz) if i want to distinguish those frequency components then how can I do it.

댓글을 달려면 로그인하십시오.


Wayne King
Wayne King 2012년 1월 26일
You need to tell me what the sampling frequency is and how many samples you have.
Assume that the sampling is 1 kHz, then if you have even a short signal, let's say 100 samples, you can easily tell them apart.
Fs = 1e3;
t = 0:1/Fs:(100*1/Fs)-1/Fs;
x = cos(2*pi*300*t)+cos(2*pi*350*t);
xdft = fft(x);
freq = 0:Fs/length(x):500;
plot(freq,abs(xdft(1:length(x)/2+1)));
xlabel('Hz'); ylabel('Magnitude');

raj
raj 2012년 1월 26일
clear all
close all
clc
f1 = 2000;
f2 = 1700;
T = 1/f1;
tmin = 0;
tmax = 5*T; % Plot 5 cycles
dt1 = 1/30000;
fs = 1/dt1;
t1 = tmin:dt1:tmax;
X = sin(2*pi*f1*t1)+ sin(2*pi*f2*t1);
nx = length(X);
y = abs(fft(X));
figure;
plot(y,'Linewidth',2)
grid on
shg
this is the corrected one
  댓글 수: 3
raj
raj 2012년 1월 26일
hallo wayne thanks a lot can you tell me an optimal values of sampling frequency and number of values
Wayne King
Wayne King 2012년 1월 26일
There are so many possibilities. You have to decide what kind of frequency resolution you want, e.g. 1 Hz, 2 Hz, 10 Hz, and what the highest frequency you want to resolve is.

댓글을 달려면 로그인하십시오.


raj
raj 2012년 1월 26일
One last question what are the effects of increasing the FFT length I tried it on the code you gave it to me and i couldnt even recognise the dominant frequencies in it, is the effects of zero padding so bad
clear all
close all
clc
Fs = 1e3;
t = 0:1/Fs:(100*1/Fs)-1/Fs;
x = cos(2*pi*300*t)+cos(2*pi*310*t);
xdft = fft(x,256);
freq = 0:Fs/length(x):500;
stem(freq,abs(xdft(1:length(x)/2+1)));
xlabel('Hz'); ylabel('Magnitude');
  댓글 수: 2
Wayne King
Wayne King 2012년 1월 26일
zero padding does not change the frequency resolution, zero padding only interpolates. You cannot use zero padding to increase your frequency resolution.
raj
raj 2012년 1월 26일
No i dont want to increase my frequency resolution with zero padding but I just wanted to know if there would be change in the placing of the frequency components

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by