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)
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)|')'
fft(w,NFFT)'
in the computation ofYY3
. 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 withfft(w',NFFT)
and it should work. $\endgroup$