필터 지우기
필터 지우기

how to filter a signal ?

조회 수: 4 (최근 30일)
meziane madani
meziane madani 2017년 8월 30일
편집: Jan 2017년 8월 30일
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.

답변 (1개)

Jan
Jan 2017년 8월 30일
편집: Jan 2017년 8월 30일
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
meziane madani
meziane madani 2017년 8월 30일
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 2017년 8월 30일
편집: Jan 2017년 8월 30일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Signal Processing Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by