2
$\begingroup$

for some reasons I'd like to minimize the secondary lobes of the FFT transform of a rectangular signal (shwon in the upper-left side of picture below)

enter image description here so I've used window function to do that (bottom-left). However, if I want to do it directly on the complex transform of the signal (bottom-right), the values of attenuation of secondary lobe aren't the same as the temporal case.

Having the test code below, I'd like to know what is wrong with it:

pass to the EDIT

     Fs = 1000; L = 2000; t = (0:L-1)*1/Fs;  
% the signal
y = zeros(1,L);  y(500:1500) = 1;     % rectangle signal

figure; 
subplot(2,2,1);
plot(Fs*t,y); title('Temporal signal'); xlabel('time (milliseconds)')

NFFT = 6*2^nextpow2(L);
Y1 = 2*abs(fft(y,NFFT)); Y1 = Y1/max(Y1);
f = 0:Fs/NFFT:Fs/2;

% the FFT of the signal
subplot(2,2,2);
semilogy(f, Y1(1:NFFT/2+1), '.-'); axis tight; grid on;
title('Signal''s spectrum'); xlabel('Frequency (Hz)'); ylabel('|Y(f)|');

w = window(@blackman, L);
y1 = y.*w';
Y2 = 2*abs(fft(y1,NFFT)); Y2 = Y2/max(Y2);

% the FFT of the windowed signal, in time
subplot(2,2,3);
semilogy(f, Y2(1:NFFT/2+1), '.-'); axis tight; grid on;
title('FFT windowing - temporal product'); xlabel('Frequency (Hz)'); ylabel('|Y(f)|')

% the FFT of the windowed signal, in complex
Y3 = 2*abs(fftshift(conv(Y1, fft(w,NFFT), 'same'))); Y3 = Y3/max(Y3);
subplot(2,2,4);
semilogy(f, Y3(1:NFFT/2+1), '.-');  axis tight; grid on;
title('FFT windowing - spectral convolution'); xlabel('Frequency (Hz)'); ylabel('|Y(f)|')

EDIT:
I've changed the code according to @Matt's remarks, but still there is a problem to the last graph (the noise on the convolutions of the FFTs)

NFFT = 6*2^nextpow2(L);
Y1 = fft(y,NFFT);
YY1 = 2*abs(Y1); YY1 = YY1/max(YY1);
f = 0:Fs/NFFT:Fs/2;

% the FFT of the signal
subplot(2,2,2);
semilogy(f, YY1(1:NFFT/2+1), '.-'); axis tight; grid on;
title('Signal''s spectrum'); xlabel('Frequency (Hz)'); ylabel('|Y(f)|');

w = window(@blackman, L);
y1 = y.*w';
YY2 = 2*abs(fft(y1,NFFT)); YY2 = YY2/max(YY2);

% the FFT of the windowed signal, in time
subplot(2,2,3);
semilogy(f, YY2(1:NFFT/2+1), '.-'); axis tight; grid on;
title('FFT windowing - temporal product'); xlabel('Frequency (Hz)'); ylabel('|Y(f)|')

% the FFT of the windowed signal, in complex
YY3 = 2*abs(cconv(Y1, fft(w,NFFT)', NFFT)); YY3 = YY3/max(YY3);
subplot(2,2,4);
semilogy(f, YY3(1:NFFT/2+1), '.-');  axis tight; grid on;
title('FFT windowing - spectral convolution'); xlabel('Frequency (Hz)'); ylabel('|Y(f)|')'

enter image description here

$\endgroup$
2
  • $\begingroup$ The last problem is fft(w,NFFT)' in the computation of YY3. The FFT result is complex-valued, and the operator ' not only transposes but also computes the complex conjugate, which you don't want. Replace it with fft(w',NFFT) and it should work. $\endgroup$
    – Matt L.
    Commented Nov 20, 2015 at 20:51
  • $\begingroup$ Did the answer below and my comment solve your problem? If so, please accept the answer by clicking the check mark to its left, so other future users can profit from it. $\endgroup$
    – Matt L.
    Commented Nov 24, 2015 at 9:15

1 Answer 1

3
$\begingroup$

Multiplication of two time domain sequences corresponds to cyclic (circular) convolution of the DFTs of the two sequences, not to linear convolution as implemented in your code. So if $x[n]$ and $y[n]$ are two length $N$ time domain sequences, and $X[k]$ and $Y[k]$ are their respective DFTs, the following correspondence holds:

$$\text{DFT}_N\left\{x[n]\cdot y[n]\right\}[k]= \frac{1}{N}\sum_{m=0}^{N-1}X[m]Y[(k-m)_N],\quad 0\le k \le N-1$$

where

$$(k-m)_N=k-m+lN$$

with the integer $l$ chosen such that the result is in the range $[0,N-1]$.

Also take a look at this answer to a related question.

EDIT: You also can't use Y1 in the convolution because it is not the DFT but the magnitude of the DFT. You should circularly convolve fft(y) with fft(w).

$\endgroup$
2
  • $\begingroup$ Thanks a lot for your straight answer, I've done the modification in computing 'Y3' by putting 'Y3 = 2*abs(cconv(Y1, fft(w,NFFT)', NFFT))' but still doesn't help. PS: Your link goes to Mathworks Documentation. $\endgroup$ Commented Nov 20, 2015 at 12:51
  • $\begingroup$ @P.Teodor: I've corrected the link. There are several problems in your code, I'll edit my answer accordingly. $\endgroup$
    – Matt L.
    Commented Nov 20, 2015 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.