Effacer les filtres
Effacer les filtres

how to filter a signal ?

4 vues (au cours des 30 derniers jours)
meziane madani
meziane madani le 30 Août 2017
Modifié(e) : Jan le 30 Août 2017
hello; The filtering of a complete signal x using the filter function in matlab (filter(b,1,x)) will give the same results if done block by block this is an example
[y,Fs] = audioread ('Rock.wav');
t_bit_in_samples =6125;
k1 = [zeros(d1,1);-1;1]*0.3;
k1= [1;k1];
out1 = filter(k1,1,y);
for(index=1:t_bit_in_samples:legth(y))
out(index:(index+t_bit_in_samples-1))=filter (k1,1,s(index:(index+t_bit_in_samples-1)));
end;
so my question is how to obtain the same result of out1 using block by block thank you for your answer.

Réponses (1)

Jan
Jan le 30 Août 2017
Modifié(e) : Jan le 30 Août 2017
Please care for posting valid code. No parentheses around the argument of for and "legth" is assumed to be "length" and "s" to be "y". I guess that d1 is 7. I stop the loop at length(y) - tb + 1 instead of length(y). It is tedious to fix such details.
[y, Fs] = audioread('Rock.wav');
tb = 6125;
k1 = [1; zeros(d1, 1); -0.3; 0.3];
% Filter in one step
out1 = filter(k1, 1, y);
% Filter blockwise:
z = zeros(1, d1 + 2);
out = zeros(size(y));
for k = 1:tb:length(y) - tb + 1
kf = k + tb - 1;
[out(k:kf), z] = filter (k1, 1, y(k:kf), z);
end
% Last chunk:
out(kf + 1:end) = filter (k1, 1, y(kf+1:end), z);
For filtering in blocks, you have to keep the current state of the filter z and provide it for the next block.
  2 commentaires
meziane madani
meziane madani le 30 Août 2017
thank you for you answer. I understand what you have put here. But my problem is that the size of my signal is unknown, because I need to implement this in real time, do you have any idea how to do it in this case?
Jan
Jan le 30 Août 2017
Modifié(e) : Jan le 30 Août 2017
What is the problem exactly? Filtering in chunks is not faster, but slower than doing it at once. It would be useful if you explain the problem in detail.
Do you want to accelerate the filtering? This should be easy with a hard coded implementation, because most elements of the filter parameter b are zeros.
Is d1 fixed? Then I could provide a C-Mex function. Do you have a C compiler installed?
Did you see that it took me some time to fix the typos in your code? It is a good idea to reduce the work required for answer as much as possible.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Signal Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by