merge 'develop'

This commit is contained in:
Guillaume BONABAU 2024-03-18 08:46:09 +01:00
commit 5e19f5550a
3 changed files with 18 additions and 12 deletions

View File

@ -1,4 +1,4 @@
function power = frequencySpectrum(signal, fs, resolution) function power = frequencySpectrum(signal, fs, resolution,RoI)
%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%
%function power = frequencySpectrum(signal, fs, pad) %function power = frequencySpectrum(signal, fs, pad)
% %
@ -8,6 +8,7 @@ function power = frequencySpectrum(signal, fs, resolution)
% - signal: the input signal to process % - signal: the input signal to process
% - fs: the sampling rate in Hz % - fs: the sampling rate in Hz
% - resolution: frequency resolution in Hz, signal will be padded with zeros if necessary % - resolution: frequency resolution in Hz, signal will be padded with zeros if necessary
% - RoI: region of interest
% %
% Output: % Output:
% - power: the power spectrum % - power: the power spectrum
@ -52,12 +53,14 @@ subplot(1,3,2) % linear frequency plot
f = (0:n-1)*(fs/n); % frequency range f = (0:n-1)*(fs/n); % frequency range
plot(f,power, 'b*'); hold on; plot(f,power, 'b*'); hold on;
plot(f,power, 'r'); plot(f,power, 'r');
xlim(RoI);
title("Frequency Linear "); title("Frequency Linear ");
xlabel('Frequency (Hz)') xlabel('Frequency (Hz)')
ylabel('Power (a.u.)') ylabel('Power (a.u.)')
subplot(1,3,3) % log frequency plot subplot(1,3,3) % log frequency plot
plot(f,10*log10(power/power(ind))); plot(f,10*log10(power/power(ind)));
xlim(RoI);
title("Frequency Log"); title("Frequency Log");
xlabel('Frequency (Hz)') xlabel('Frequency (Hz)')
ylabel('Power (dB)') ylabel('Power (dB)')

23
main.m
View File

@ -1,6 +1,6 @@
%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%
% UNKNOWN SIGNAL % UNKNOWN SIGNAL
% Sampling frequency: 300 Hz % Sampling frequency: 200 Hz
% Duration; 2 s % Duration; 2 s
% First second: 0.1Hz, 30 Hz, 30.5 Hz, 60 Hz, 61 Hz % First second: 0.1Hz, 30 Hz, 30.5 Hz, 60 Hz, 61 Hz
% Second second: 0.1Hz, 32 Hz, 36 Hz, 64 Hz, 72 Hz % Second second: 0.1Hz, 32 Hz, 36 Hz, 64 Hz, 72 Hz
@ -14,7 +14,7 @@ signal = csvread('unknownsignal.csv');
%%%%%SIGNAL CHARACTERISTICS%%%%% %%%%%SIGNAL CHARACTERISTICS%%%%%
% sets sampling frequency % sets sampling frequency
fps = 300; % -> freqMax of the signal should be < 150 Hz (Shannon-Nyquisit theorem), in practice freqMax < 60 Hz would be better fps = 200; % -> freqMax of the signal should be < 150 Hz (Shannon-Nyquisit theorem), in practice freqMax < 60 Hz would be better
% computes the duration of the signal % computes the duration of the signal
duration = length(signal) / fps; % in s duration = length(signal) / fps; % in s
@ -22,6 +22,9 @@ duration = length(signal) / fps; % in s
% estimates its original frequency resolution % estimates its original frequency resolution
resolution = fps / length(signal); % in Hz resolution = fps / length(signal); % in Hz
%crop the Power spectrums over the region of interest
RoI=[5,20];
%%%%%STATIONARITY%%%%% %%%%%STATIONARITY%%%%%
% temporal plot % temporal plot
figure; figure;
@ -48,14 +51,14 @@ signal_2 = signal(end/2+1:end);
%%%%%SPECTRAL ANALYSIS (RECTANGULAR WINDOW)%%%%% %%%%%SPECTRAL ANALYSIS (RECTANGULAR WINDOW)%%%%%
%plots power spectrum with rectangular window %plots power spectrum with rectangular window
% 1st part of the signal with 1 Hz resolution % 1st part of the signal with 1 Hz resolution
frequencySpectrum(signal_1, fps, 1); frequencySpectrum(signal_1, fps, 1, RoI);
% 1st part of the signal with 0.5 Hz resolution % 1st part of the signal with 0.5 Hz resolution
frequencySpectrum(signal_1, fps, 0.5); frequencySpectrum(signal_1, fps, 0.5, RoI);
% 2nd part of the signal with 1 Hz resolution % 2nd part of the signal with 1 Hz resolution
frequencySpectrum(signal_2, fps, 1); frequencySpectrum(signal_2, fps, 1, RoI);
% 2nd part of the signal with 0.5 Hz resolution % 2nd part of the signal with 0.5 Hz resolution
frequencySpectrum(signal_2, fps, 0.5); frequencySpectrum(signal_2, fps, 0.5, RoI);
@ -63,15 +66,15 @@ frequencySpectrum(signal_2, fps, 0.5);
%plots power spectrum with blackman window %plots power spectrum with blackman window
signal_1_win = blackmanWin(signal_1); signal_1_win = blackmanWin(signal_1);
% 1st part of the signal with 1 Hz resolution % 1st part of the signal with 1 Hz resolution
frequencySpectrum(signal_1_win, fps, 1); frequencySpectrum(signal_1_win, fps, 1, RoI);
% 1st part of the signal with 0.5 Hz resolution % 1st part of the signal with 0.5 Hz resolution
frequencySpectrum(signal_1_win, fps, 0.5); frequencySpectrum(signal_1_win, fps, 0.5, RoI);
signal_2_win = blackmanWin(signal_2); signal_2_win = blackmanWin(signal_2);
% 2nd part of the signal with 1 Hz resolution % 2nd part of the signal with 1 Hz resolution
frequencySpectrum(signal_2_win, fps, 1); frequencySpectrum(signal_2_win, fps, 1, RoI);
% 2nd part of the signal with 0.5 Hz resolution % 2nd part of the signal with 0.5 Hz resolution
frequencySpectrum(signal_2_win, fps, 0.5); frequencySpectrum(signal_2_win, fps, 0.5, RoI);

File diff suppressed because one or more lines are too long