How do I perform zero phase filtering in Matlab?
Afficher commentaires plus anciens
Hello All,
I am a student working on a tremor suppression project for those with parkinsons and I would really appreciate your expertise in Matlab in performing FFT's and applying filters.
What we need to do is filter out frequencies with a butterworth bandpass from 3-9 Hz and apply a phase shift to that data that will be sent to our neuro-stimulator.
I have code that properly filters our data between 3-9 Hz and I can use the FFT to verify that our filter is working, but I am having trouble getting usable phase information from our post-filtered data. I have used the filtfilt function in matlab, but for some reason our phase data is still not perfect to the original. I understand the nature of filters to change phase but we need some way to do this so that we can apply a phase shift to the data later.
I have attached my code here:
fs = 100;
% fs is Sampling frequency in hz
% Time vector - use colon operator to generate integer vector of sample
% numbers
t = 1:.01:7.01; %7 seconds of sampling
f1 = 6; %6 Hz freq
f2 = 40; %40 Hz freq
f3 = 45; %45 Hz freq
signal = 3*cos(2*pi*f1*t + 2) + 1*cos(2*pi*f2*t + 1) + 1*cos(2*pi*f3*t + 3);
fs=100; % sample frequency
fc1=2; %cutoff frequency low
fc2=15; %cutoff frequency high
[B,A]=butter(3,[fc1/(fs/2) fc2/(fs/2)] ,'bandpass');
filtered_signal=filtfilt(B,A,signal);
plot(signal)
hold on
plot(filtered_signal, 'r')
figure
X = fft(signal);
Z = fft(filtered_signal);
n=length(X);
X_mag = abs(X);
X_phase = angle(X);
w = fs/(length(t)-1);
binHzConv = ((fs)/(n) +.000001);
freq = 0:binHzConv:100;
p = unwrap(angle(X));
g = unwrap(angle(Z));
Any help at all would be much appreciated! Thank you.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Digital Filtering dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!