Mean and Median Frequency
Show older comments
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 Comments
KALYAN ACHARJYA
on 2 Jan 2021
Edited: KALYAN ACHARJYA
on 2 Jan 2021
EMG_Filtered2segment ??
ZackyAs
on 2 Jan 2021
Image Analyst
on 2 Jan 2021
How are we supposed to run these lines when you're not supplying us wtih the files?
L=importdata('BRYAN 1ST HALF (1).txt');
T1_10rm_BS_2=importdata('BRYAN 2ND HALF.txt');
ZackyAs
on 2 Jan 2021
Image Analyst
on 2 Jan 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
on 2 Jan 2021
Answers (1)
Star Strider
on 2 Jan 2021
0 votes
2 Comments
ZackyAs
on 2 Jan 2021
Star Strider
on 2 Jan 2021
I only suggested them to you.
Use whatever works to do what you want.
Categories
Find more on Scopes and Data Logging in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!