I am trying to smoothing a signal's power spectrum by convolving the spectrum with a boxcar function in frequency domain. However, the result is obviously not what I expected: original two frequency spikes become three and the frequencies are different.
Could anyone possibly point out my problem? Is the problem in the idea of convolving with a boxcar or in the MATLAB code?
Thanks...
t = 0:.001:.25;
x = sin(2*pi*50*t) + sin(2*pi*120*t);
f = 1000/251*(-floor(length(t)/2):length(t)/2);
% power spec
Fy = fftshift(fft(x,length(t)));
Pyy = Fy.*conj(Fy)/length(t);
plot(f(length(t)/2:length(t)*3/4),Pyy(length(t)/2:length(t)*3/4))
title('Power spectral density')
xlabel('Frequency (Hz)')
figure
% rectangle function
rectLen = 5;
rw = ones(rectLen, 1);
plot(rw)
% convolution in frequency domain to smooth
Fy_conv_rw = conv(Fy, rw, 'same');
Pyy_conv_rw = Fy_conv_rw.*conj(Fy_conv_rw)/length(t) / sum(abs(rw));
plot(f(length(t)/2:length(t)*3/4),Pyy_conv_rw(length(t)/2:length(t)*3/4))
title('Power spectral density smoothed')
xlabel('Frequency (Hz)')