How to Calculate dominant frequency and centroid frequency and plot them together
please help me, I would like to calculate dominant and centroid frequency and plot them tohether in one plot. Please CMIIW if i have misundertanding the basic concept. As I undertand, dominant freq is higest freq that appear in our signal. I used FFT and get the max power. And about dominant freq I am not quite sure. What makes me don’t understand is, if I take example from weighted mean as basic of centroid freq, based on example in https://en.wikipedia.org/wiki/Weighted_arithmetic_mean, after calculate weighted mean we have weighted mean of the frequencies present in the signal, meaning that is not a single value. I use spectralCentroid to calculate centroid frequency, but then i confuse, if i have single falue for dominant freq and several value from spectralCentroid, how i should plot them together?
i also attach my file, basically the code will doing looping as my file represent one day data, so my goal is plot dominant and centroid freq in one plot for 1 month. I assume my dominant freq has 30 data point, but not sure about spectralCentroid.
this is my attempt to do it.
sig=load(‘signal2023-335.txt’);
%BAND PASS FILTER long range –> can be considered as UNFILTER condition
% Define the parameters
lowcut = 1/400; % Low cutoff frequency in Hz
high1 = 40; % High cutoff frequency in Hz
high2 = 1.25; % Midrange cutoff frequency in Hz
fs = 100; % Sampling frequency in Hz
% Design the Butterworth bandpass filter (UNFILTER)
[bU, aU] = butter(2,[lowcut high1] / (fs / 2), ‘bandpass’);
sigUnfilt= filtfilt(bU,aU,sig);
% calculate FFT UNFILT
n=length(sigUnfilt);
srate=100; %sampling rate
nyq=srate/2;
fftsig=fft(sigUnfilt-mean(sigUnfilt))/n; %dataX is fft result from filtered signal
hz=linspace(0,nyq,floor(n/2)+1);
pow=2*abs(fftsig(1:length(hz)));
Iv = 1:numel(hz);
%get the maximum freq/dominant freq
[~,idx] = max(pow) ;
domfreq = hz(idx)
% Calculate centroid frequency
centroid = spectralCentroid(sigUnfilt,100)please help me, I would like to calculate dominant and centroid frequency and plot them tohether in one plot. Please CMIIW if i have misundertanding the basic concept. As I undertand, dominant freq is higest freq that appear in our signal. I used FFT and get the max power. And about dominant freq I am not quite sure. What makes me don’t understand is, if I take example from weighted mean as basic of centroid freq, based on example in https://en.wikipedia.org/wiki/Weighted_arithmetic_mean, after calculate weighted mean we have weighted mean of the frequencies present in the signal, meaning that is not a single value. I use spectralCentroid to calculate centroid frequency, but then i confuse, if i have single falue for dominant freq and several value from spectralCentroid, how i should plot them together?
i also attach my file, basically the code will doing looping as my file represent one day data, so my goal is plot dominant and centroid freq in one plot for 1 month. I assume my dominant freq has 30 data point, but not sure about spectralCentroid.
this is my attempt to do it.
sig=load(‘signal2023-335.txt’);
%BAND PASS FILTER long range –> can be considered as UNFILTER condition
% Define the parameters
lowcut = 1/400; % Low cutoff frequency in Hz
high1 = 40; % High cutoff frequency in Hz
high2 = 1.25; % Midrange cutoff frequency in Hz
fs = 100; % Sampling frequency in Hz
% Design the Butterworth bandpass filter (UNFILTER)
[bU, aU] = butter(2,[lowcut high1] / (fs / 2), ‘bandpass’);
sigUnfilt= filtfilt(bU,aU,sig);
% calculate FFT UNFILT
n=length(sigUnfilt);
srate=100; %sampling rate
nyq=srate/2;
fftsig=fft(sigUnfilt-mean(sigUnfilt))/n; %dataX is fft result from filtered signal
hz=linspace(0,nyq,floor(n/2)+1);
pow=2*abs(fftsig(1:length(hz)));
Iv = 1:numel(hz);
%get the maximum freq/dominant freq
[~,idx] = max(pow) ;
domfreq = hz(idx)
% Calculate centroid frequency
centroid = spectralCentroid(sigUnfilt,100) please help me, I would like to calculate dominant and centroid frequency and plot them tohether in one plot. Please CMIIW if i have misundertanding the basic concept. As I undertand, dominant freq is higest freq that appear in our signal. I used FFT and get the max power. And about dominant freq I am not quite sure. What makes me don’t understand is, if I take example from weighted mean as basic of centroid freq, based on example in https://en.wikipedia.org/wiki/Weighted_arithmetic_mean, after calculate weighted mean we have weighted mean of the frequencies present in the signal, meaning that is not a single value. I use spectralCentroid to calculate centroid frequency, but then i confuse, if i have single falue for dominant freq and several value from spectralCentroid, how i should plot them together?
i also attach my file, basically the code will doing looping as my file represent one day data, so my goal is plot dominant and centroid freq in one plot for 1 month. I assume my dominant freq has 30 data point, but not sure about spectralCentroid.
this is my attempt to do it.
sig=load(‘signal2023-335.txt’);
%BAND PASS FILTER long range –> can be considered as UNFILTER condition
% Define the parameters
lowcut = 1/400; % Low cutoff frequency in Hz
high1 = 40; % High cutoff frequency in Hz
high2 = 1.25; % Midrange cutoff frequency in Hz
fs = 100; % Sampling frequency in Hz
% Design the Butterworth bandpass filter (UNFILTER)
[bU, aU] = butter(2,[lowcut high1] / (fs / 2), ‘bandpass’);
sigUnfilt= filtfilt(bU,aU,sig);
% calculate FFT UNFILT
n=length(sigUnfilt);
srate=100; %sampling rate
nyq=srate/2;
fftsig=fft(sigUnfilt-mean(sigUnfilt))/n; %dataX is fft result from filtered signal
hz=linspace(0,nyq,floor(n/2)+1);
pow=2*abs(fftsig(1:length(hz)));
Iv = 1:numel(hz);
%get the maximum freq/dominant freq
[~,idx] = max(pow) ;
domfreq = hz(idx)
% Calculate centroid frequency
centroid = spectralCentroid(sigUnfilt,100) centroid frequency, fft, centroid, weighted mean MATLAB Answers — New Questions