Signal process 2
This commit is contained in:
parent
526ce9f941
commit
802c3166f2
|
|
@ -0,0 +1,45 @@
|
||||||
|
% Load the signal from the CSV file
|
||||||
|
data = csvread('unknownsignal.csv');
|
||||||
|
signal = data(:, 1);
|
||||||
|
|
||||||
|
% Set the sampling frequency
|
||||||
|
Fs = 300; % Hz
|
||||||
|
|
||||||
|
% Define the frequency range of interest
|
||||||
|
fmin = 30; % Hz
|
||||||
|
fmax = 40; % Hz
|
||||||
|
|
||||||
|
% Apply a Hanning window to the signal to reduce spectral leakage
|
||||||
|
win = hanning(length(signal));
|
||||||
|
signal_win = signal .* win;
|
||||||
|
|
||||||
|
% Calculate the power spectral density (PSD) of the signal using Welch's method
|
||||||
|
nfft = 1024;
|
||||||
|
[Pxx, f] = pwelch(signal_win, win, [], nfft, Fs);
|
||||||
|
|
||||||
|
% Find the frequency indices that correspond to the frequency range of interest
|
||||||
|
idx_min = find(f >= fmin, 1);
|
||||||
|
idx_max = find(f <= fmax, 1, 'last');
|
||||||
|
|
||||||
|
% Extract the PSD of the signal in the frequency range of interest
|
||||||
|
Pxx_interest = Pxx(idx_min:idx_max);
|
||||||
|
|
||||||
|
% Find the frequency at which the PSD is maximum in the frequency range of interest
|
||||||
|
[~, idx_max_interest] = max(Pxx_interest);
|
||||||
|
f_interest = f(idx_min+idx_max_interest-1);
|
||||||
|
|
||||||
|
% Plot the PSD of the signal and the frequency range of interest
|
||||||
|
figure;
|
||||||
|
plot(f, 10*log10(Pxx));
|
||||||
|
hold on;
|
||||||
|
plot([fmin, fmax], [0, 0], 'r', 'LineWidth', 2);
|
||||||
|
xlim([0, Fs/2]);
|
||||||
|
ylim([-100, max(10*log10(Pxx))]);
|
||||||
|
xlabel('Frequency (Hz)');
|
||||||
|
ylabel('Power/Frequency (dB/Hz)');
|
||||||
|
title(sprintf('Signal PSD with frequency range of interest [%d %d] Hz', fmin, fmax));
|
||||||
|
grid on;
|
||||||
|
legend('Signal PSD', 'Frequency range of interest');
|
||||||
|
|
||||||
|
% Print the frequency at which the PSD is maximum in the frequency range of interest
|
||||||
|
fprintf('The signal of interest is at %.2f Hz\n', f_interest);
|
||||||
Loading…
Reference in New Issue