3

I am learning DSP and I couldn't write a code to calculate and plot these figures (just magnitude of Hanning and triangular windows in frequency domain.) Could anyone please help me with the code?

window frequency plots

I've read something related to online FFT, and, for example, they calculate online FFT with 1024 time steps. I don't understand what is 1024 time steps, and what are the influences of time step value to FFT analysis?

4

3 回答 3

4

I hope the following piece of code is helpful to you.

L = 10;
win1 = hanning(L);
win2 = triang(L);
nfft = 64;
S1 = fft(win1,nfft);
S2 = fft(win2,nfft);
f = 1:nfft/2+1;
plot(f,10*log10(abs(S1(1:nfft/2+1))),'.-',f,10*log10(abs(S2(1:nfft/2+1))),'o-');

Annotation:

You can put win1 and win2 as Time-series signal. L is the length of win1 or win2. nfft is the length of FFT . if L < nfft , then the function fft() will add 0 to the rest of nfft. If L > nfft, then the function fft() will interception the length of L to equal nfft.

于 2012-08-26T02:24:29.540 回答
1

The frequency of the time steps or samples (Fs), divided by the number of time steps fed the FFT (the FFT length), gives you the frequency steps of the FFT result bins (up to Fs/2).

于 2012-08-26T03:28:01.230 回答
1

Regarding the 1024 "time steps" in your question, that is simply the number of samples that are taken from the time-domain signal.

As to how the 1024 time-domain samples influence the FFT, this involves the sampling frequency that was used to obtain the samples.

Sampling frequency is typically chosen to conform with the Nyquist-Shannon sampling theorem, which basically states that you must sample the time-domain signal at a frequency higher than "2F" if you want to resolve a frequency "F" via the FFT.

As for the Hann (Hanning) and Triangular window codes, they are as follows:

Hann window:
for( i=0; i<bufLen; i++ )
   window[i] = 0.5 * ( 1 - cos( 2 * PI * i / (bufLen-1) ) )

Triangular window:
for( i=0; i<bufLen; i++ )
   window[i] = 2/bufLen * ( (bufLen)/2 - abs( i-((bufLen-1)/2) ) )

...

The plot below is the frequency response of the Triangular window, in dB magnitude.

Triangular Window Function dB magnitude

The plot below is the frequency response of the Triangular window, but now in linear magnitude.

Triangular Window Function linear magnitude

You can plot the Hann, Triangular, and many other window functions here: Plot windows functions

于 2013-02-15T22:35:32.783 回答