how to calculate fast Fourier transform with a 128-point window on these data with non-uniform sampling frequency

Hi everyone
I have provided you with my MATLAB code and data. These samples were recorded at a non-uniform sampling frequency, so I used the NUFFT command to convert the Fourier.
Now, if I want to use fast Fourier transform with a 128-point window on these data with non-uniform sampling frequency to calculate the power spectrum, and then divide the frequency range of all power spectra into eight equal parts and divide the area under the 8-channel curve. What calculator code should I use to calculate?THANKS SO MUCH
This is my code:
%% load Data
DATA3 = [];DATA4 = [];FFT3 =[];M7=[];
for j =1:13
data3 = load(strcat(strcat('als',num2str(j)),'.ts'));
DATA3 = [DATA3;data3];
t3 = data3(:,1); f3 = (length(data3)/300))*(0:(length(t3)-1))/length(t3);
fft3 = nufft(data3(:,2:13),t3,f3);FFT3 = [FFT3;fft3]; M6 = abs(fft3);M7 = [M7;M6];
end
FFT4=[];M9=[];
for j = 1:16
data4 = load(strcat(strcat('control',num2str(j)),'.ts'));
DATA4 = [DATA4;data4];
t4 = data4(:,1); f4 = (length(data4)/300))*(0:(length(t4)-1))/length(t4);
fft4 = nufft(data4(:,2:13),t4,f4);FFT4 = [FFT4;fft4]; M8 = abs(fft4);M9 =[M9;M8];
% f4 = (0.8167/2)*(0:(length(DATA4)-1))/length(DATA4);
end

 Akzeptierte Antwort

hello
see my suggestion below
the result is in Area
clc
clearvars
load('DATA3.mat');
t3 = data3(:,1);
%% uniform resampling of data on 128 samples
nfft = 128; % fft length
newt3 = linspace(min(t3),max(t3),nfft); % equally spaced time vector
dt = mean(diff(newt3)); % new time increment
Fs = 1/dt; % sampling frequency
newdata3_2_13 = interp1(t3,data3(:,2:13),newt3,'linear');
%% fft
fft_spectrum = abs(fft(newdata3_2_13))/nfft;
% 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_spectrum = fft_spectrum(select,:);
freq_vector = (select - 1)*Fs/nfft;
figure,semilogy(freq_vector,fft_spectrum);
%% divide the frequency range of all power spectra into eight equal parts
freq_points = linspace(min(freq_vector),max(freq_vector),8+1); % equally spaced freq vector
for cj = 1:numel(freq_points)-1
start = freq_points(cj);
stop = freq_points(cj+1);
ind = find(freq_vector>=start & freq_vector<=stop);
Area(cj,:) = trapz(freq_vector(ind),fft_spectrum(ind,:)); % Area under curve :
% rows = 8 (as many as parts) , cols = 12 , as many as signals
end

9 Kommentare

Hello Dearthanks for your suggestion but for this data should use a nonuniform fft like nufft,because has a different sampling frequency .Doesn't the MATLAB code of FFT make a difference? because your code matlab is about uniform resampling and this code matlab use for uniform frequency While we don't have anything like that here.Thank you for your advice again
hello
sure the original data has a non uniform time vector , but why wouldn't we resample the data (interp1) at a fixed sampled rate and use the regular fft ?
If you plot the original and resampled data you will see perfect match
hello dear ...
how?
I do not understand you,These are the data registered by the Physinet site, and I did not register, so I cannot make any changes in it, and I want to perform this operation on this data.
hello again
what is your issue ? there is nothing special to do on the original data.
I simply suggested to resample the data into a uniform spacing so you can easily use the regular fft
see :
%% uniform resampling of data on 128 samples
nfft = 128; % fft length
newt3 = linspace(min(t3),max(t3),nfft); % equally spaced time vector
dt = mean(diff(newt3)); % new time increment
Fs = 1/dt; % sampling frequency
newdata3_2_13 = interp1(t3,data3(:,2:13),newt3,'linear');
hello again dear.
You are absolutely right. I thought there is a way to go the same way with nufft non-uniform sampling method. Now with your method, the data and the label to enter the neural network do not match, I don't know what changes should I make in the code? Thank you for your help.
this is my code and workspace matlab
clc,clear all,close all;
Area3=[];
for j =1:16
data3 = load(strcat(strcat('control',num2str(j)),'.ts'));
t3 = data3(:,1);
%% uniform resampling of data on 128 samples
nfft = 128; % fft length
newt3 = linspace(min(t3),max(t3),nfft); % equally spaced time vector
dt = mean(diff(newt3)); % new time increment
Fs = 1/dt; % sampling frequency
newdata3_2_5 = interp1(t3,data3(:,2:5),newt3,'linear');
%% fft
fft_spectrum = abs(fft(newdata3_2_5))/nfft;
% 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_spectrum = fft_spectrum(select,:);
freq_vector = (select - 1)*Fs/nfft;
% figure,semilogy(freq_vector,fft_spectrum);
%% divide the frequency range of all power spectra into eight equal parts
freq_points = linspace(min(freq_vector),max(freq_vector),8+1); % equally spaced freq vector
for cj = 1:numel(freq_points)-1
start = freq_points(cj);
stop = freq_points(cj+1);
ind = find(freq_vector>=start & freq_vector<=stop);
area3(cj,:) = trapz(freq_vector(ind),fft_spectrum(ind,:)); % Area under curve :
% rows = 8 (as many as parts) , cols = 12 , as many as signals
end
Area3=[Area3;area3];
end
Area4=[];
for j =1:13
data4 = load(strcat(strcat('als',num2str(j)),'.ts'));
t4 = data4(:,1);
%% uniform resampling of data on 128 samples
nfft = 128; % fft length
newt4 = linspace(min(t4),max(t4),nfft); % equally spaced time vector
dt = mean(diff(newt3)); % new time increment
Fs = 1/dt; % sampling frequency
newdata4_2_5 = interp1(t4,data4(:,2:5),newt4,'linear');
%% fft
fft_spectrum = abs(fft(newdata4_2_5))/nfft;
% 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_spectrum4 = fft_spectrum(select,:);
freq_vector4 = (select - 1)*Fs/nfft;
figure,semilogy(freq_vector4,fft_spectrum4);
%% divide the frequency range of all power spectra into eight equal parts
freq_points = linspace(min(freq_vector4),max(freq_vector4),8+1); % equally spaced freq vector
for cj = 1:numel(freq_points)-1
start = freq_points(cj);
stop = freq_points(cj+1);
ind = find(freq_vector4>=start & freq_vector4<=stop);
area4(cj,:) = trapz(freq_vector4(ind),fft_spectrum4(ind,:)); % Area under curve :
% rows = 8 (as many as parts) , cols = 12 , as many as signals
end
Area4=[Area4;area4];
end
data = [Area3',Area4']';
label=[3*ones(1,13)';4*ones(1,16)'];
% % % creat simple perceptron
net = perceptron('hardlim','learnp')
net.trainparam.epochs = 200;
net = train(net, data,label);
view(net)
Y = net(data);
hello again
sure, I can clearly see that data and label are not same size +
but I do not understand why you created label this way and how the dimensions (1,13) and (1,16) are related to size(data) = 232 x4 ?
label=[3*ones(1,13)';4*ones(1,16)'];
Hi ...
My purpose of area calculation is to extract the feature from the power spectrum and then feed it to the neural network. I scored the levels based on two classes, sick and healthy, for example, class 1 and 2 or class 3 and 4.(label=[3*ones(1,13)';4*ones(1,16)'];)
In your opinion, what should I do so that the size of the two will be similar and I will be closer to my goal?
hmmm
I am not really the expert here for the neural training - tried to figure out the issue by reading the doc for function train but it's quite outside my area of expertise - sorry !!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Signal Processing Toolbox finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2021b

Gefragt:

am 30 Jun. 2022

Kommentiert:

am 19 Jul. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by