Why noise_signal does not plot correctly? There are the problems in the code to calculate SNR and MSE value .What can I do?

1 vue (au cours des 30 derniers jours)
Here is my DATASET
%%
clc;
clear
close all;
load B02T.mat;
fs=250;
% t = 0.004:1/fs:1;
eeg1 = data{1,1}.X;
channel_1= eeg1(:,1);
ch_1=channel_1(1:2000);
figure;
subplot(2,1,1);
plot(ch_1);
xlabel('Time (s)');
ylabel('Amplitude');
legend('ch1');
title("Plot channel "+1+ " for Structure 1X1");
hold on;
grid on;
eeg_signal = eeg1(1:2000); % first 2000 samples
subplot(2,1,2);
plot(eeg_signal,'black');
hold on;
grid on;
legend('EEG Signal');
title('Raw EEG Signal');
%%
[IMF, residual, info] = emd(eeg_signal);
imf_count = max(info.NumIMF);
figure;
for i=1:imf_count
subplot(6,2,i)
plot(IMF(:,i))
title("IMF"+i);
end
subplot(6,2,imf_count+1)
plot(residual)
title("Residue");
%%
thresholds = thselect(IMF, 'rigrsure'); % determine threshold for each IMF using universal thresholding
for i = 1:size(IMF, 2)
IMF(:, i) = wthresh(IMF(:, i), 's', thresholds(i));
end
% Reconstruct denoised signal from thresholded IMFs
denoised_signal = sum(IMF, 2) + residual;
clean_EEG = denoised_signal;
noise_signal = eeg_signal - clean_EEG;
% Plot results
figure;
subplot(3,1,1);
plot(eeg_signal);
title('Original signal');
subplot(3,1,2);
plot(clean_EEG);
legend( 'Denoised signal');
title('Denoised signal');
subplot(3,1,3);
plot(noise_signal);
legend( 'Noisy signal');
title('Noisy signal');
%%
original_signal = eeg_signal;
reconstructed_signal =clean_EEG;
% Calculate SNR
noise = original_signal - reconstructed_signal;
SNR = 20 * log10(norm(original_signal)/ norm(noise));
% Calculate MSE
% MSE = mean((norm(original_signal) - norm(reconstructed_signal)).^2);
MSE = immse(norm(original_signal), norm(reconstructed_signal));
disp(['SNR: ', num2str(SNR), ' dB']);
disp(['MSE: ', num2str(MSE)]);

Réponse acceptée

Cris LaPierre
Cris LaPierre le 19 Juin 2023
You variable noisy_signal is a 2000x2000 array. When you plot it, you get 2000 lines, since each column is treated as a separate data series.
Looking a little earlier in your code, I see that this is because you subtract a 2000x1 vector from a 1x2000 vector. Since the dimensions are not the same, MATLAB uses implicit expansion so that both variables are 2000x2000, and then does an elementwise subtraction.
I suggest transposing one of your variables so that they both have the same size. Something like this:
noise_signal = eeg_signal.' - clean_EEG;

Plus de réponses (0)

Catégories

En savoir plus sur EEG/MEG/ECoG dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by