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.

Power spectra

Could anyone possibly point out my problem? Is the problem in the idea of convolving with a boxcar or in the MATLAB code?


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);
title('Power spectral density')
xlabel('Frequency (Hz)')

% rectangle function
rectLen = 5;
rw = ones(rectLen, 1);

% 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));
title('Power spectral density smoothed')
xlabel('Frequency (Hz)')
  • $\begingroup$ Why are you trying to smooth this? This feels like you intend to "hide" the ugliness of some observation, but by convolving the PSD with something, you're changing properties of the time signal that PSD is describing, and, um, I don't think that is what you intended to do! $\endgroup$ – Marcus Müller Nov 8 '20 at 17:40
  • $\begingroup$ @MarcusMüller You caught me trying to "hide" the ugliness :) My signals are contaminated by different noises, and I am trying to smooth the spectrum for easier QC. $\endgroup$ – sofname Nov 8 '20 at 18:01
  • $\begingroup$ yes, so in the general case, that's not OK. You're changing the signal you should be describing by doing this. $\endgroup$ – Marcus Müller Nov 8 '20 at 18:03
  • $\begingroup$ @MarcusMüller Actually, I think smoothing spectrum is a common practise. For example, in frequency-domain spiking deconvolution, before calculating minimum phase spectrum by Hilbert transform, it is recommended to smooth the power spectrum. $\endgroup$ – sofname Nov 8 '20 at 18:09
  • $\begingroup$ yes, because they have a signal model that allows for that. You don't. $\endgroup$ – Marcus Müller Nov 8 '20 at 18:24
  1. The spectrum is periodic so you need circular convoluioint, not linear convolution
  2. You are smoothing the complex linear spectrum. Due to the phase of the complex ammplitude you will get significant interference in your smoothing window. Smoothing is typically in the energy domain and the phase is discarded. Complex smoothing is fairly difficult to do.
  • $\begingroup$ Thanks a lot. I tried to convolve the power spectrum instead and it looks OK now. $\endgroup$ – sofname Nov 8 '20 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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