Mean and Median Frequency

13 visualizzazioni (ultimi 30 giorni)
ZackyAs
ZackyAs il 2 Gen 2021
Commentato: Star Strider il 2 Gen 2021
Hi, I am a newbie in doing coding for mean and median frequency. first of all, i cut the signal before applying the fft. then i apply window hamming to fft then i create coding for mean and median frequency. i want to extract the value for mean and median but it gives output columns zero. unfortunately i couldnt detect the problem regarding my coding. can someone help me please?
b=EMG_Filtered2segment; %signal data
fs =1000; %sampling frequency
cut=1*fs; %cut signal every second
Window=hamming(cut);
L= 300
id1=1
for i = 1:length(b)/cut
slice=b(1+(i-1)*cut: i*cut);
signal(:,i)=slice;
Ls=length(slice);
Nfftslice=2^nextpow2(Ls);
signalwin=Window.*slice;
FFT=fft(signalwin);
absFFT=abs(FFT);
FFTonesided=2*absFFT(1:Ls/2+1); %double amplitude, one side
FFTonesided(1)=FFTonesided(1)/2; %DC part is not doubled
Hspec=spectrum.welch('Hamming',500,25);
hspd=psd(Hspec,slice,'NFFT',Nfftslice,'Fs',fs);
Pw = hpsd.Data;
Fw=FFTonesided;
PW=cumsum(Fw);
Pwdiv2=median(PW);
Fs=1000;
Freq= Fs*(0:(Ls/2))/Ls;
end
%MEAN AND MEDIAN%
% a=find(FFTonesided(:,1));
for t=1:length(b)/cut
meanPSD(:,i) = sum(Freq.*FFTonesided) / sum(FFTonesided);
OverHalfIdx(:,i) = find(PW>=Pwdiv2,1,'first');
UnderHalfIdx(:,i)= find(PW<=Pwdiv2,1,'last');
MedianPSD(:,i) = (Freq(OverHalfIdx(:,i))+Freq(UnderHalfIdx(:,i)))/2
end
  6 Commenti
Image Analyst
Image Analyst il 2 Gen 2021
So you have a couple of signals, and there are a bunch of frequencies, and for each frequency there is a relative power at that frequency.
What do you mean by the mean and median frequency? Do you just want the half way frequency between 0 and the maximum frequency? Or do you want the mean weighted by the power at each frequency?
ZackyAs
ZackyAs il 2 Gen 2021
Hello there. Basically, the one i am analysing is changes of muscle fatigue characteristics during driving using emg signal. so my parameters will be time domain which is RMS and also frequency domain which is Mean and Median frequency. so for emg fatigue condition, RMS will increase and Mean and median frequency decrease. to be honest, im still lacking the knowledge for mean and median frequency thats why i ask for what is missing there. can u help me and suggest me sir? i am apologise as i couldnt answer your questions sir since i have no idea about it.

Accedi per commentare.

Risposte (1)

Star Strider
Star Strider il 2 Gen 2021
If you have R2015a or later, use the medfreq and meanfreq functions.
  2 Commenti
ZackyAs
ZackyAs il 2 Gen 2021
Hello sir. you meant instead of using this meanpsd n medianpsd, use med n meanfreq functions? it change the whole coding isnt it?
meanPSD(:,i) = sum(Freq.*FFTonesided) / sum(FFTonesided);
OverHalfIdx(:,i) = find(PW>=Pwdiv2,1,'first');
UnderHalfIdx(:,i)= find(PW<=Pwdiv2,1,'last');
MedianPSD(:,i) = (Freq(OverHalfIdx(:,i))+Freq(UnderHalfIdx(:,i)))/2
Star Strider
Star Strider il 2 Gen 2021
I only suggested them to you.
Use whatever works to do what you want.

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by