Hi there, i just want to design and apply a 2s hanning window with 50% overlapp on my EEG signal in order to segment it , i've tried with @hann command but i couldn't get it
    16 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    alireza ghavami
 il 17 Gen 2023
  
    
    
    
    
    Commentato: alireza ghavami
 il 19 Feb 2023
            my signal is a 17-channel signal with 30721 samples totally (=17 * 30721) . i need my signal to be segmented with 2s hanning window with 50% overlapp to apply preproccessing on it for my Master thesis. sampling frequency is 256 Hz.
i have problem from A to Z designing the window and also, i dont know how to apply it on my Original Signal,
I will be grateful if you could help me design and apply this window to my signal,
thank you so much
0 Commenti
Risposta accettata
  Mathieu NOE
      
 il 23 Gen 2023
        hello 
see example below 
the signal gets splitted in 2s buffer and windowed 
see the subfunction at the bottom of the code : 
        sw = signal(start:stop).*window; % signal buffered and windowed
then we do fft on each windowed segment and when iteration process is  complete we get a time / frequency (spectrgram) plot
code : 
clearvars
% dummy signal
Fs = 256;
dt = 1/Fs;
t = 0:dt:30;                    % 2 s at 1 kHz sample rate
signal = chirp(t,0,15,50,'quadratic');             % Start at DC, cross 50 Hz at 15 s 
nfft = 2*256; % frame length = 2 seconds x Fs
overlap = 0.5; % window overlap ;  0 = 0 % , 0.5 = 50% , 1 = 100 % 
[S,F,T] = myspecgram(signal, Fs, nfft, overlap); 
figure(1); 
imagesc(T,F,20*log10(abs(S))) 
colorbar('vert');
set(gca,'YDir','Normal') 
xlabel('Time (secs)') 
ylabel('Freq (Hz)') 
title('Short-time Fourier Transform spectrum (dB Scale)')
colormap('jet');
function  [fft_specgram,freq_vector,time] = myspecgram(signal, Fs, nfft, Overlap)
% FFT peak spectrogram of signal  (example sinus amplitude 1   = 0 dB after fft).
%   signal - input signal, 
%   Fs - Sampling frequency (Hz).
%   nfft - FFT window size
%   Overlap - buffer overlap % (between 0 and 0.95)
signal = signal(:);
samples = length(signal);
% fill signal with zeros if its length is lower than nfft
if samples<nfft
    s_tmp = zeros(nfft,1);
    s_tmp((1:samples),:) = signal;
    signal = s_tmp;
    samples = nfft;
end
% window : hanning
window = hanning(nfft);
window = window(:);
%    compute fft with overlap 
 offset = fix((1-Overlap)*nfft);
 spectnum = 1+ fix((samples-nfft)/offset); % Number of windows
%     % for info is equivalent to : 
%     noverlap = Overlap*nfft;
%     spectnum = fix((samples-noverlap)/(nfft-noverlap));	% Number of windows
    % main loop
    fft_specgram = [];
    for ci=1:spectnum
        start = 1+(ci-1)*offset;
        stop = start+nfft-1;
        sw = signal(start:stop).*window; % signal buffered and windowed
        fft_specgram = [fft_specgram abs(fft(sw))*4/nfft];     % X=fft(x.*hanning(N))*4/N; % hanning only 
    end
% one sidded fft spectrum  % Select first half 
    if rem(nfft,2)    % nfft odd
        select = (1:(nfft+1)/2)';
    else
        select = (1:nfft/2+1)';
    end
fft_specgram = fft_specgram(select,:);
freq_vector = (select - 1)*Fs/nfft;
% time vector 
% time stamps are defined in the middle of the buffer
time = ((0:spectnum-1)*offset + round(nfft/2))/Fs;
end
15 Commenti
  Mathieu NOE
      
 il 6 Feb 2023
				hello 
the power spectrum plot is what I already showed you above
here again

it's coming from this fft computation in my code
[freq, spectrum_raw] = myfft_peak(signal,Fs,NFFT,OVERLAP);
but maybe your supervisor would like you to use this matlab function instead 
look at the doc and example it's fairly easy to replace my fft code with this matlab function 
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Frequency Transformations in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

