Signal_Final_TikeaTE/createtemporalWindow.m

48 lines
1.6 KiB
Matlab

function win = createTemporalWindow(t, duration_signal, duration_win, sampling_freq, win_type)
%{
fuction win = createTemporalWindow(t, duration_signal, duration_win, sampling_freq, win_type)
Ex: win = createTemporalWindow(t, 6, 2, 40, 1)
Task: create the 4 types of windowing functions
Inputs:
-t: time vector of the signal
-duration_signal: duration of the signal (in s)
-duration_win: duration of the window
-sampling_freq: how many samples per second
-win_type: 1 for rectangle, 2 for hamming, 3 for hanning, 4 for blackman
Output:
win : window amplitude with the same duraion as the temporal vector
Author: Tikea TE
Date: 13/04/2025
%}
% create a vector of 0 the same length as the signal
win = zeros(1,length(t));
for I_sample = 1:duration_win * sampling_freq % nuber of samples in the window
% for rectangle
if (win_type == 1)
win(I_sample + (duration_signal - duration_win)/2 * sampling_freq ) = 1;
end
% for hanning
if (win_type == 2)
win(I_sample + (duration_signal - duration_win)/2 * sampling_freq ) = 0.5 - 0.5*cos(2*pi*I_sample/(duration_win*sampling_freq));
end
% for hamming
if (win_type == 3)
win(I_sample + (duration_signal - duration_win)/2 * sampling_freq ) = 0.54 - 0.46*cos(2*pi*I_sample/(duration_win*sampling_freq));
end
% for blackman
if (win_type == 4)
win(I_sample + (duration_signal - duration_win)/2 * sampling_freq ) = 0.42 - 0.5*cos(2*pi*I_sample/(duration_win*sampling_freq)) + 0.08*cos(4*pi*I_sample/(duration_win*sampling_freq));
end
end