Hanning Window Energy Density Value
이전 댓글 표시
Good afternoon (code below figure),
I am processing some velocity data for a turbulent flow and want to determine the energy spectra to determine the shedding frequency (the picture below is from a test section that does not have a peak at 1.35Hz). I want to get rid off the noise. Format of the input data is:
time = 0, 0.05, 0.1, 0.15.
data = 1,1.2,1.04,0.95, ...
My colleague created a code that looks like this (fs = 200) and results in the "noisy" data plot at about 10^-2. Here data input has 4 coloms for 4 different velocity measurements.
len = length(data);
psd = (abs(fft(data(:,:),len)).^2)/(len*fs); % Fourier transform (2nd argument = vector length, such that the DFT returns n-points). Amplitude squared for PSD estimate, as this equals power
psd = 2.*psd(2:len/2+1,:); % single-sided spectrum. (1:N/2+1) takes only one half of the spectrum; the other half is its reflection
f = fs/2*linspace(0,1,len/2+1).'; % Nyquist frequency of the signal = fs/2
f = f(2:end); % remove zero Hz component
When I try and create the same with a hanning window; the magnitude is way off. Even multiplying it with 2 for amplitude correction does not help. Am I not seeing something?
Or how can I add the window to the code above? Is there a simple way?

Current code:
figure(1)
ylabel('Power Density Spectrum')
xlabel('Frequency (Hz)');
u_velocity=u_i(:,1); %Colum 1 is for u-velocity
mean_u = mean(u_velocity);
data = u_velocity-mean_u; %Velocity fluctuations around mean
chunk_size = 5000; % Size of each processing chunk
num_chunks = length(data) / chunk_size;
psd_combined = zeros(1, chunk_size / 2);
for i = 1:num_chunks
chunk_start = (i - 1) * chunk_size + 1;
chunk_end = i * chunk_size;
% Extract the current chunk of data
chunk = data(chunk_start:chunk_end);
% Apply the Hanning window
window = hanning(length(chunk));
windowed_data = chunk .* window';
% Perform FFT
fft_result = fft(windowed_data);
% Calculate Power Spectral Density (PSD) for this chunk
psd_chunk = abs(fft_result).^2;
% Combine the PSD results
psd_combined = psd_combined + psd_chunk(1:length(psd_chunk)/2);
end
psd_combined = psd_combined*10;%Correct Window
% Frequency axis
sample_rate = 200; % Adjust the sample rate accordingly
frequencies = linspace(0, sample_rate/2, length(psd_combined));
% Plot the PSD
semilogy(frequencies, psd_combined);
grid on;
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Spectral Estimation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



