Smoothening of signal using triangular window
7 次查看(过去 30 天)
显示 更早的评论
Can you tell how to smoothen a power spectral density for a given discrete signal data set using a triangular smoothing window with a band width equal to O.4Hz.
0 个评论
回答(1 个)
BhaTTa
2024-7-16
This code will compute the PSD of your signal, create a triangular smoothing window with a bandwidth of 0.4 Hz, and apply the window to smooth the PSD
% Example signal
fs = 1000; % Sampling frequency in Hz
t = 0:1/fs:1-1/fs; % Time vector
x = sin(2*pi*50*t) + sin(2*pi*120*t) + randn(size(t)); % Example signal
% Compute the PSD using Welch's method
[pxx, f] = pwelch(x, [], [], [], fs);
% Determine the frequency resolution
freq_resolution = f(2) - f(1); % Assuming f is linearly spaced
% Calculate the number of points for the 0.4 Hz bandwidth
bandwidth = 0.4; % Bandwidth in Hz
num_points = round(bandwidth / freq_resolution);
% Create a triangular window
triangular_window = triang(2*num_points + 1);
% Normalize the triangular window
triangular_window = triangular_window / sum(triangular_window);
% Smooth the PSD using convolution
smoothed_pxx = conv(pxx, triangular_window, 'same');
% Plot the original and smoothed PSD
figure;
hold on;
plot(f, 10*log10(smoothed_pxx), 'r', 'DisplayName', 'Smoothed PSD');
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
legend;
title('Power Spectral Density with Triangular Smoothing');
grid on;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parametric Spectral Estimation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!