Best way to filter out frequencies in real time (frame by frame) analysis ?
6 views (last 30 days)
Show older comments
How can I filter out particular frequencies in real time frame by frame analysis of music (sound) data ?
tried a butter filter, but it doesn't transition properly between the frames (I do hear ticks). As I understand fft and ifft is not the best way to go, also, since it fails to properly transition between blocks ?
What is the best way to deal with this ?
A real code example is equal to gold to me, since I am a noob when dealing with MatLab.
4 Comments
Star Strider
on 31 Dec 2017
For real time applications, you need the DSP System Toolbox (link) or the Audio System Toolbox (link).
Answers (1)
Jan
on 2 Jan 2018
And for clarity a code example (UNTESTED CODE):
signal = rand(1, 1000);
[b, a] = butter(3, 0.5);
z = zeros(1, 3);
filtered1 = filter(b, a, signal, z); % Same as: filter(b, a, signal) if z is 0
filtered2 = NaN(size(signal));
steps = 0:100:numel(signal);
for iStep = 1:numel(steps) - 1
i1 = steps(iStep) + 1;
i2 = steps(iStep + 1);
% z is updated in each block:
[filtered2(i1:i2), z] = filter(b, a, signal(i1:i2), z);
end
max(abs(filtered1 - filtered2))
This shows, that using the final state of the filter z as initial state for the next input is equivalent to filtering the complete signal at once.
5 Comments
Jan
on 13 Mar 2019
Edited: Jan
on 13 Mar 2019
@Artem: Do the DSP System Toolbox (link) or the Audio System Toolbox (link) offer, what you need for real time filtering?
Artem Bobritsky
on 13 Mar 2019
@Jan,
Thank you for answering this!
I went through DSP System Toolbox and found Butterworth example for Simulink and nothing for Matlab.. I'll take a look with more attention.
I'm filtering EEG signals (Delta, Alpha, etc.) using band pass filters. Post processing works quite good, but it's time to move it into a microcontroller, so I have no way to collect 8 hours of data and post process it, I need to make some decitions based on the filtered signal.
I thought I could use a code gen for that... Unfortunately it's so limited and full of hardcoded constants, e.g. butter(_) needs _constants_ !!! bandpass(_) could not be used for code generation.
See Also
Categories
Find more on Audio Processing Algorithm Design 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!