How can I calculate the SNR of a curve that has impulse noise added?

8 visualizzazioni (ultimi 30 giorni)
Hi all,
I have an issue where I'm not sure how to calulate the SNR of a signal that I have in MATLAB. I have a real-world signal dataset that is a curve shape (a bit like a logarithmic curve) that I import into MATLAB from a .CSV. This is my reference curve. I then add impulse noise to the curve using the alpha stable distribution. This noisy signal is then put through a rolling mean filter. I also smooth a separate instance of the noisy curve using the arithmetic mean. I want to compare the SNR of the curve signal and demonstrate how the filter has improved the noisy signal. How can I do this?
Importing the signals x100
cd 'C:blah\blah\'
z_numfiles = 100;
for k = 1:z_numfiles
myfilename = sprintf('scope_%d.csv', k);
nometal{k} = xlsread(myfilename, 'C4:C500');
end
This is two instances of the "raw" signal capture
Adding the impulse noise to the "nometal" signal and increasing the size of the dataset from x100 to x1000:
pd1 = makedist('Stable','alpha',0.5,'beta',0,'gam',0.001,'delta',0);
temp = 0;
distr_puls_nometal = cell(1000, 1);
samplesize = 497;
loop_count = 1000;
for n = 1:9
for j = 1:loop_count
temp = cell2mat(nometal(n));
for i = 1:samplesize
a = random(pd1);
temp(i) = temp(i) + a;
if temp(i) > 3
temp(i) = 3;
elseif temp(i) < 0
temp(i) = 0;
end
end
distr_puls_nometal{n+j} = temp;
end
end
Comparing a rolling mean and an arithmetic mean of the noisy "no metal" signal:
How can I calculate the SNR decrease for the "noisy" signal? How can I caculate the signal improvement by attenuating the noise? I also have a number of other noise distributions but I assume that the process will be the same. Thanks all!
  3 Commenti

Accedi per commentare.

Risposte (1)

Hornett
Hornett il 4 Set 2024
To calculate the SNR (Signal-to-Noise Ratio) of a signal in MATLAB, you can follow these steps:
% Calculate the power of the signal by squaring each sample and taking the mean:
signal_power = mean(signal.^2);
% Calculate the power of the noise by subtracting the signal from the noisy signal and taking the mean:
noise_power = mean((noisy_signal - signal).^2);
% Calculate the SNR by dividing the signal power by the noise power:
snr = 10 * log10(signal_power / noise_power);
To demonstrate the improvement in the noisy signal after applying the rolling mean filter, you can calculate the SNR before and after filtering and compare the results.
Hope this helps!

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by