# Smoothing power spectrum by convolution with boxcar function

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)')

• 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! Nov 8 '20 at 17:40
• @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. Nov 8 '20 at 18:01
• yes, so in the general case, that's not OK. You're changing the signal you should be describing by doing this. Nov 8 '20 at 18:03
• @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. Nov 8 '20 at 18:09
• yes, because they have a signal model that allows for that. You don't. Nov 8 '20 at 18:24

## 1 Answer

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.
• Thanks a lot. I tried to convolve the power spectrum instead and it looks OK now. Nov 8 '20 at 18:29