added files
This commit is contained in:
parent
64fee58c84
commit
8e22a60da3
|
|
@ -0,0 +1,61 @@
|
|||
clear all
|
||||
close all
|
||||
% loads signal and its characteristics
|
||||
signal = csvread('unknownsignal.csv');
|
||||
|
||||
%%%%%SIGNAL CHARACTERISTICS%%%%%
|
||||
% sets sampling frequency
|
||||
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
|
||||
duration = length(signal) / fps; % in s
|
||||
disp(duration);
|
||||
% estimates its original frequency resolution
|
||||
resolution = fps / length(signal); % in Hz
|
||||
|
||||
|
||||
%Then we study the stationarity
|
||||
% temporal plot
|
||||
figure;
|
||||
plot(signal);
|
||||
xticks(0:0.2*fps:length(signal)*fps);
|
||||
xticklabels(0:0.2:length(signal)/fps);
|
||||
xlabel('Time (s)');
|
||||
ylabel('Amplitude (a.u.)');
|
||||
|
||||
% spectrogram
|
||||
step_size = 50; %ms
|
||||
window_size = 1000; %ms
|
||||
spectrogram(signal, fps, step_size, window_size);
|
||||
|
||||
% We conclude that the signal must be cut in 2 stationary parts
|
||||
%Thus we cut it in 2 parts of equal length
|
||||
% First part: [0 1s]
|
||||
signal_1 = signal(1:end/2);
|
||||
% Second part: [1s 2s]
|
||||
signal_2 = signal(end/2+1:end);
|
||||
|
||||
%%%%%SPECTRAL ANALYSIS (RECTANGULAR WINDOW)%%%%%
|
||||
%plots power spectrum with rectangular window
|
||||
|
||||
% 1st part of the signal with 0.5 Hz resolution
|
||||
frequencySpectrum(signal_1, fps, 0.5);
|
||||
|
||||
|
||||
% 2nd part of the signal with 0.5 Hz resolution
|
||||
frequencySpectrum(signal_2, fps, 0.5);
|
||||
|
||||
|
||||
%%%%%SPECTRAL ANALYSIS (BLACKMAN WINDOW)%%%%%
|
||||
%plots power spectrum with blackman window
|
||||
signal_1_win = blackmanWin(signal_1);
|
||||
|
||||
% 1st part of the signal with 0.5 Hz resolution
|
||||
frequencySpectrum(signal_1_win, fps, 0.5);
|
||||
|
||||
signal_2_win = blackmanWin(signal_2);
|
||||
|
||||
% 2nd part of the signal with 0.5 Hz resolution
|
||||
frequencySpectrum(signal_2_win, fps, 0.5);
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
function signal_win = blackmanWin(signal)
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%function signal_win = blackmanWin(signal)
|
||||
%
|
||||
% Inputs:
|
||||
% - signal: signal of interest
|
||||
%
|
||||
% Output:
|
||||
% - signal_win: signal of interest on which a blackman window was applied
|
||||
%
|
||||
% Author: Guillaume Gibert, guillaume.gibert@ecam.fr
|
||||
% Date: 15/03/2024
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
blackmanWin = zeros(1, length(signal));
|
||||
for l_sample=1:length(signal)
|
||||
blackmanWin(l_sample) = (0.42 - 0.5 * cos(2*pi*(l_sample)/length(signal)) + 0/08*cos(4*pi*(l_sample)/length(signal)));
|
||||
end
|
||||
|
||||
% plot Blackman window
|
||||
%~ figure;
|
||||
%~ plot(blackmanWin);
|
||||
|
||||
% apply the Blackman window
|
||||
for l_sample=1:length(signal)
|
||||
signal_win(l_sample) = signal(l_sample) * blackmanWin(l_sample);
|
||||
end
|
||||
|
||||
%~ figure;
|
||||
%~ plot(signal);
|
||||
%~ hold on;
|
||||
%~ plot(signal_win);
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
function signal = windowing(signal_freq, signal_duration, signal_phase, sampling_freq)
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%function signal = windowing(signal_freq, signal_duration, signal_phase, sampling_freq)
|
||||
% ex.: signal = windowing(10, 12, 0, 50)
|
||||
%
|
||||
% Inputs:
|
||||
% - signal_freq: frequency of the cosine function in Hz
|
||||
% - signal_duration: duration of the signal in seconds
|
||||
% - signal_phase: phase of the signal in rad
|
||||
% - sampling_freq: sampling frequency in Hz
|
||||
%
|
||||
% Output:
|
||||
% - signal: an array containing the samples of a cosine function sampled at the given sampling freq and windowed (in a.u.)
|
||||
% signal = cos(2*pi*signal_freq*t+signal_phase)
|
||||
%
|
||||
% Author: Guillaume Gibert, guillaume.gibert@ecam.fr
|
||||
% Date: 04/03/2024
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
% generates a time array
|
||||
t=-signal_duration/2:1/sampling_freq:signal_duration/2;
|
||||
|
||||
% generates a sampled signal
|
||||
signal = cos(2*pi*signal_freq*t+signal_phase);
|
||||
|
||||
% window duration is half of signal duration
|
||||
windowDuration = signal_duration/2;
|
||||
% creates rectangular time window
|
||||
rectangularWin = zeros(1, length(t));
|
||||
for l_sample=1:windowDuration*sampling_freq
|
||||
rectangularWin(l_sample+signal_duration*sampling_freq/4) = 1;
|
||||
end
|
||||
|
||||
figure;
|
||||
plot(rectangularWin);
|
||||
|
||||
for l_sample=1:signal_duration*sampling_freq
|
||||
signal_rect(l_sample) = signal(l_sample) * rectangularWin(l_sample);
|
||||
end
|
||||
|
||||
figure;
|
||||
plot(signal); hold on;
|
||||
plot(signal_rect);
|
||||
|
||||
|
||||
|
||||
% creates the Hanning time window
|
||||
|
||||
% creates the Hamming time window
|
||||
|
||||
% creates the Balckman time window
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue