フィルターのクリア

overlap save of an audio file and FIR filter

1 回表示 (過去 30 日間)
Tsvi Weiss
Tsvi Weiss 2018 年 5 月 17 日
コメント済み: Walter Roberson 2018 年 5 月 18 日
Hi
Im trying to perform a convolution by an overlap save method. I tried to use an example I found here for the overlap save: My total code:
[signal,Fs] = audioread('ex01signal.mp3'); %Load audio file
fs = Fs/5;
fivesecsignal = signal(25*Fs:30*Fs);
audiowrite('5_sec_signal.wav',fivesecsignal,fs);
clear fivesecsugnal;
[new_signal,fs] = audioread('5_sec_signal.wav');
fc = 155;
wn = (2/fs)*fc;
tubafilter = fir1(477,wn,'low');
%%%============Overlap-save of signal and filter==========================%%%
x = audiosignal; %after I used the audioread command
h = tubafilter;
L=256;
N1=length(x);
M=length(h);
lc=conv(x,h);
x=[x zeros(1,mod(-N1,L)) zeros(1,L)];
N2=length(x);
h=[h zeros(1,L-1)];
H=fft(h,L+M-1);
S=N2/L;
index=1:L;
xm=x(index); % For first stage Special Case
x1=[zeros(1,M-1) xm]; %zeros appeded at Start point
X=[];
for stage=1:S
X1=fft(x1,L+M-1);
Y=X1.*H;
Y=ifft(Y);
index2=M:M+L-1;
Y=Y(index2); %Discarding Samples
X=[X Y];
index3=(((stage)*L)-M+2):((stage+1)*L); % Selecting Sequence to process
if(index3(L+M-1)<=N2)
x1=x(index3);
end
end;
i=1:N1+M-1;
X=X(i);
similarity=corrcoef(X,lc); % Similarity between Inbuilt and Calculated conv
figure()
subplot(2,1,1)
stem(lc);
title('Convolution Using conv() function')
xlabel('n');
ylabel('y(n)');
subplot(2,1,2)
stem(X);
title('Convolution Using Overlap Save Method')
xlabel('n');
ylabel('y(n)');
if I run the program the next error appear:
Dimensions of matrices being concatenated are not consistent.
Please can someone explain to me what I need to fix here?
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 5 月 17 日
Please show the complete error message with the traceback.
Tsvi Weiss
Tsvi Weiss 2018 年 5 月 18 日
Error using horzcat Dimensions of matrices being concatenated are not consistent.
Error in Untitled (line 17) x=[x zeros(1,mod(-N1,L)) zeros(1,L)];

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 5 月 18 日
If you used audioread, then the result is going to be in columns, one column per channel. Your code assumes that your x is exactly one row
  2 件のコメント
Tsvi Weiss
Tsvi Weiss 2018 年 5 月 18 日
Hi,
In addition to your advise I tried to solve it with the buffer command and it pops error: "Error using buffer Not enough input arguments."
What is that mean and what u this should I do? Thanks
Walter Roberson
Walter Roberson 2018 年 5 月 18 日
You need to pass at least two arguments to buffer(). The first argument is the input data, and the second argument is the size of the output frame.
When buffer is used, it is also common to pass a third parameter, which controls how much overlap is to be used between frames, for the case where you want a sliding window.
Note: the input to buffer() must be a vector, so you cannot directly use buffer() with multi-channel input.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSignal Processing Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by