MATLAB real-time filtering implement
Show older comments
How can implement a real-time filter in matlab. My goal is to design a filter with 100Hz cutoff frequency and 1dB attenuation in passband. My incoming signal has the sample rate of 10kHz. The signal is coming frame by frame. One frame contain 60 sample.
I tried following code but the result is bad. I kind know the problem is I filter the data every frame, but I don't know how to address that since it will be a real-time system and I have to process data frame by frame.
clear all
% Test Seq generate %
T = 9*(1/50);
fs = 10000;
t = 0:1/fs:T-1/fs;
testSeqComb = 3 * (sin(2*pi*50*t) + 0.5*sin(2*pi*500*t) + 0.25*sin(2*pi*1000*t));
blockNum = length(testSeqComb)/60;
for i=1:blockNum
testSeq(i,:) = testSeqComb(1+(i-1)*60:i*60);
end
% Raw Data Visualize %
plot(t, testSeqComb)
hold on
% Filter %
filter1 = designfilt('lowpassiir', 'FilterOrder', 6, 'HalfPowerFrequency', 100, 'SampleRate', 10000);
for i=1:blockNum
testSeqFiltered(i,:) = filtfilt(filter1, testSeq(i,:));
end
testSeqFilteredComb = [];
for i=1:blockNum
testSeqFilteredComb = [testSeqFilteredComb testSeqFiltered(i,:)];
end
% Filtered Data Visualize %
plot(t, testSeqFilteredComb, "LineWidth", 2)
Accepted Answer
More Answers (0)
Categories
Find more on Single-Rate Filters in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
