I want to remove 50Hz noise using fir notch filter in ECG signal
29 次查看(过去 30 天)
显示 更早的评论
I have an ECG signal downloaded by physionet.i want to generate 50hz sinusoidal noise signal and add to the above ecg signal.after i need to remove that 50hz hum noise using fir filter then get to frequency sapectrum of that ECG signal befor filtering and after filtering.please tell me how to do that in matlab
i mention what i have done so far.explain how to do the rest here
xt=linspace(0,10,4000);
plot(xt,val)
xlabel('Time(s)')
ylabel('Volt(mV)')
title('ECG Signal in time domain')
xt=linspace(0,10,4000);
x1=(length(xt));
fs=50; % Sample rate in Hz
ts=1/fs;
N=length(x1);
ls=size(x1);
xt=(0:N-1)/fs;% Time vector
tspan=0:ts:10;
tsart=tspan(1);
tend=tspan(end);
noise=randn(length(tspan),1);% Noisy waveform
plot(tspan,noise);
title('Noised currupted ECG Signal')
xlabel('Time(s)')
ylabel('Volt(mV)')
thank you,
0 个评论
回答(1 个)
Star Strider
2021-11-20
That is straightforward —
Fs = 1000; % Use Correct Sampling Frequency (Must Be Greater Than 250 Hz)
fcomb = [55 59 61 64]-10;
mags = [1 0 1];
dev = [[0.5 0.1 0.5]];
[n,Wn,beta,ftype] = kaiserord(fcomb,mags,dev,Fs);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
figure
freqz(hh, 1, 2^20, Fs)
set(subplot(2,1,1), 'XLim', [0 100]) % Zoom X-Axis
set(subplot(2,1,2), 'XLim', [0 100]) % Zoom X-Axis
Experiment with the passbands to get different results, and carefully note the value of ‘n’ and the vector length of ‘hh’ because the length of the filter must be less than three time the signal length. Use the filtfilt function to do the actual filtering.
See the documentation for the various functions to understand how the code works.
.
2 个评论
Star Strider
2021-11-20
It should work as designed. Be absolutely certain that ‘Fs’ is the sampling frequency of the EKG signal.
Fs = 250; % Use Correct Sampling Frequency (Must Be Greater Than 250 Hz)
fcomb = [55 59 61 64]-10;
mags = [1 0 1];
dev = [[0.5 0.1 0.5]];
[n,Wn,beta,ftype] = kaiserord(fcomb,mags,dev,Fs);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
figure
freqz(hh, 1, 2^20, Fs)
set(subplot(2,1,1), 'XLim', [0 100]) % Zoom X-Axis
set(subplot(2,1,2), 'XLim', [0 100]) % Zoom X-Axis
Fn = Fs/2;
N = 2^14;
t = linspace(0, 100, N);
s = randn(size(t));
s_filt = filtfilt(hh, 1, s);
FTs = fft([s(:) s_filt(:)])/N;
Fv = linspace(0, 1, N/2+1)*Fn;
Iv = 1:numel(Fv);
figure
subplot(2,2,1)
plot(t, s)
grid
xlabel('t')
title('Original (Time Domain')
subplot(2,2,2)
plot(t, s_filt)
grid
xlabel('t')
title('Filtered (Time Domain')
subplot(2,2,3)
plot(Fv, abs(FTs(Iv,1))*2)
grid
xlabel('f')
title('Original (Frequency Domain)')
xlim([0 Fn])
subplot(2,2,4)
plot(Fv, abs(FTs(Iv,2))*2)
grid
xlabel('f')
title('Filtered (Frequency Domain)')
xlim([0 Fn])
The filter works correctly, as designed.
..
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Single-Rate Filters 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!