apply notch filter on periodic noise in matlab

To apply a notch filter on periodic noise in Matlab, you can follow these steps:

  1. Load the signal
main.m
load('noisy_signal.mat'); % replace with your signal filename
62 chars
2 lines
  1. Compute the power spectrum of the signal using fft
main.m
Pxx = abs(fft(noisy_signal)).^2;
33 chars
2 lines
  1. Plot the power spectrum to visualize the frequency components
main.m
Fs = 1000; % replace with your sampling frequency
f = linspace(0, Fs/2, numel(Pxx)/2+1);
plot(f, Pxx(1:numel(Pxx)/2+1));
xlabel('Frequency (Hz)');
ylabel('Power');
164 chars
6 lines
  1. Identify the frequency of the periodic noise and design a notch filter to remove it
main.m
notch_freq = 60; % replace with your noise frequency
Q = 30; % quality factor
wo = notch_freq/(Fs/2);
bw = wo/Q;
[b,a] = iirnotch(wo,bw);
138 chars
6 lines
  1. Apply the notch filter to the signal using filtfilt
main.m
filtered_signal = filtfilt(b,a,noisy_signal);
46 chars
2 lines
  1. Plot the original and filtered signals
main.m
plot(t, noisy_signal);
hold on;
plot(t, filtered_signal);
xlabel('Time (s)');
ylabel('Amplitude');
legend('Original', 'Filtered');
131 chars
7 lines

This should result in a plot with two signals, one showing the original noisy signal and the other showing the signal after applying the notch filter to remove the periodic noise.

related categories

gistlibby LogSnag