# How to obtain noise

6 views (last 30 days)
I am trying to to calculate Signal-to-noise ratio (SNR) values for an ECG signal. To estimate the SNR I need a "clean" signal and "noise" signal.
Let's say I use a filter to "clean" the signal. The filter outputs the filtered signal but not the noise signal. Is it posssible to obtain the noise that was filtered out as a signal?
I could be misunderstanding how filters work, but basically what I need is to obtain the noise signal too, not just the filtered signal.
Thank you.
##### 2 CommentsShowHide 1 older comment
ANDRES FELIX CHAVEZ on 26 Jan 2022
Since noise is the subtraction of noisy signal - clean signal, I analyzed the signal heartbeat by heartbeat, subtracting a clean heartbeat from a noisy heartbeat.

William Rose on 26 Jan 2022
I have attached a real EKG signal which I have on my computer. I don't recall where it came from, or what lead it was, nor do I recal details about the subject. It is rather strange, with no obvious P waves, and a peculiar S-T segment. Sampling rate = 1 kHz.
fs=1000; %sampling rate (Hz)
fc=100; %cutoff frequency (Hz)
[b,a]=butter(4,fc/(fs/2));
xfilt=filter(b,a,x);
noise=x-xfilt;
t=(1:length(x))/fs; %time vector
figure; subplot(211), plot(t,x,'-r',t,xfilt,'-b');
legend('raw','filtered'); title('EKG'); grid on
subplot(212), plot(t,noise,'-k');
xlabel('Time (s)'); title('Noise'); grid on The lower plot shows that the "noise", computed as the difference between the raw and filtered signal, is not random noise. The "noise" becomes large at every QRS complex, in a reproducible, non-random way.
Let's do it again, but this time, we wil use filtfilt() instead of filter(). filtfilt() has no phase lag or delay at any frequency.
xff=filtfilt(b,a,x);
noiseff=x-xff;
t=(1:length(x))/fs; %time vector
figure; subplot(211), plot(t,x,'-r',t,xff,'-b');
legend('raw','filtfilt'); title('EKG'); grid on
subplot(212), plot(t,noiseff,'-k');
xlabel('Time (s)'); title('Noise'); grid on This is a lot better: the spikes in the noise associated with the QRS complexes are a lot smaller now.
These examples illustrate that, if the filter introduces a delay, then the difference between the raw and filtered signal will be due to noise and to the delay.

R2021a

### Community Treasure Hunt

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

Start Hunting!