spectrogram: Can I do a subtraction of the mean value in each window?

5 views (last 30 days)
I want to create a spectrogram (with the function "spectrogram") for high frequencies. But my data contains also very low frequencies. Therefore in the windows that are used for the spectrogram the values do not necessarily oscillate around 0. And that causes artefacts in my spectrogram.
Can I do a subtraction of the mean value in each window? Can I do this with the function spectrogram or do I have to use another function?
Clarification: The data is a 1D signal.

Answers (1)

Image Analyst
Image Analyst on 30 Nov 2012
Is this a 1-D signal or a 2D image? Either way, you can use conv() or conv2() respectively to subtract the mean in a window from the signal. Here's a 1D example:
windowWidth = 15;
middleElement = ceil(windowWidth/2);
kernel = -ones(1, windowWidth) / windowWidth;
kernel(middleElement) = 1 + kernel(middleElement)
filteredSignal = conv(signal, kernel, 'same');
  2 Comments
Moritz
Moritz on 30 Nov 2012
Edited: Moritz on 30 Nov 2012
It is a 1D signal. I will add that info to the description.
Thanks a lot for the quick answer. I must admit I can't really tell if this will work without applying it on the data and I won't be able to check until Wednesday.
I guess in any case the only solution will be to filter the data BEFORE I apply "spectrogram".
Moritz
Moritz on 30 Nov 2012
Edited: Moritz on 30 Nov 2012
I tried your filter on some sinus data. Generally it seems to flatten the low frequencies very well. What puzzles me is that the amplitude of the filtered signal is lower and that there seems to be a phase shift. It may still be a good solution though.
x = (0:0.01:10);
y = cos(0.3*x)+sin(x)+0.3*sin(63*x)+0.27*cos(42*x);
windowWidth = 2;
middleElement = ceil(windowWidth/2);
kernel = -ones(1, windowWidth) / windowWidth;
kernel(middleElement) = 1 + kernel(middleElement);
filteredSignal = conv(y, kernel, 'same');
figure(1)
subplot(2,1,1)
plot(x,y)
subplot(2,1,2)
plot(x,filteredSignal)

Sign in to comment.

Categories

Find more on Time-Frequency Analysis in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!