how to use the hanning window to smooth the photon signal

windowLength = 91;
hannWindow = hann(windowLength);
smooth_data = conv2(data, hannWindow, 'same');
is the code correct? Because when i increase the windowlength, the smooth_data will increase as well

Antworten (2)

Alexander
Alexander am 19 Feb. 2024
I can't see this effect you mentioned. smooth_data remains the same size as data (I assume data = Photoncounts1). What do you expect? I never used windowing in the manner you have done it in the code above. Usually I multiplied the data with the window (or parts of the window) in the time domain to get rid of the step function and having a clear transient effect before a fft. Just an example:
clear;
N = 1024;
x = 0:N-1;
Whann = hann(N)';
y = rand(1,N); % Create some data
subplot(211);
plot(x,y);title('Original');grid minor;
subplot(212);
plot(x,y.*Whann);title('Windowed');grid minor;

3 Kommentare

sorry, i didn't explain myself very clearly.
smooth_data = movmean(ph,5,'omitnan');
semilogy(ph);
hold on
semilogy(smooth_data);
legend('Raw','smoothed');grid on;
How can i use hanning window to smooth the signal just like a 5 point linear running mean window did?
Once again: A hann window is not made for smoothing data, but to minimize the effect of a rectangular function (start of measurement <-> end of measurement) in the time domain. If your signal is time domain data, use a filter.
The following sentences are what i found in eassys about using hanning window to smooth data:
'vertically smoothed by a running Hanning window with FWHM width of 2 or 1 km'
'smoothed by sliding a 2‐km full width at half maximum (FWHM) Hanning window in the vertical direction in the temperature retrieval process '
'The smoothing of the signal plus background is by a Hanning filter with a 2-km FWHM window'

Melden Sie sich an, um zu kommentieren.

That appears to be some sort of spectrum. I am not certain what you want to do with it, however windowing it is not likely to produce any benefit at this point.
load('photon.mat')
% whos
figure
stairs(Photoncounts1)
grid
xlabel('Bin (?) Frequency (?)')
ylabel('Counts')
title('Photons')
xlim([0 600])
If this is a Fourier transform, the time to window the data was before calculating the transform.
.

6 Kommentare

sorry, i didn't explain myself very clearly.
smooth_data = movmean(ph,5,'omitnan');
semilogy(ph);
hold on
semilogy(smooth_data);
legend('Raw','smoothed');grid on;
How can i use hanning window to smooth the signal just like a 5 point linear running mean window did?
If you want to design a windowed FIR filter, you can us it there. See the documentation on fir1 for those details.
I am not certain what the signal you are using is or represents. If you want to take the Fourier transform of it, then multiply it by the window function first (the window function must be the same length as the signal), and then calculate the fft on that result. Beyond that, I am not certain that applying a window function would serve any useful purpose.
ok, i will try, but the following sentences are what i found in eassys about using hanning window to smooth data:
'vertically smoothed by a running Hanning window with FWHM width of 2 or 1 km'
'smoothed by sliding a 2‐km full width at half maximum (FWHM) Hanning window in the vertical direction in the temperature retrieval process '
'The smoothing of the signal plus background is by a Hanning filter with a 2-km FWHM window'
i still want to know how can i achieve that.
I suppose you could simulate the Hanning window as a FIR filter, using filtfilt to do the actual filtering (providing that the lengths of the window and the signal are compatible, so it may be necessary to adjust the length of the window if it is too long), however it is not an approach that I have ever seen.
I appreciate your answers, i will try
Thank you!

Melden Sie sich an, um zu kommentieren.

Produkte

Version

R2020b

Gefragt:

am 19 Feb. 2024

Kommentiert:

am 20 Feb. 2024

Community Treasure Hunt

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

Start Hunting!

Translated by