Welch's method implementation

3 views (last 30 days)
Tu Nguyen on 3 Apr 2022
Answered: Tala on 3 Apr 2022
Hi Dears;
I want to loop through the data 256 points at a time, and 128 points overlap, However, I beleive that my function missing something to perform that because when I run the code, it returns "Unable to perform assignment because the size of the left side is 512-by-1 and the size of the
right side is 256-by-128."
How can I do loop through the data 256 points at a time and 128 points overlap?
I really appreciate for your help
clc;
close all;
clear;
load('ecg_60Hz_Noise_Fs200Hz.mat');
data = ecgn(1:1024)';
Fs = 200;
w = hamming(256);
psd = zeros(512,7);
for i = 0:6
temp = data(1+256*i:128+i*256)'.*w;
temp = fft(temp);
temp = abs(temp).^2;
psd(:,i+1) = temp;
end
psd1 = mean(psd,2);
psd1 = psd(1:257);
psd1 = psd1/(Fs*sum(w.^2));
psd1(2:end-1)= psd1(2:end-1)*2;
figure
plot(f,psd1);
0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

Accepted Answer

Tala on 3 Apr 2022
Instead of the for loop, I would reshape the array first.
temp0 = reshape(ecgn,[256,4]);
temp1=fft(temp0);
temp2=abs(temp1).^2;
psd=temp2;
then the rest of your calculations...
0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

Categories

Find more on Parametric Spectral Estimation in Help Center and File Exchange

R2021b

Community Treasure Hunt

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

Start Hunting!