Error using * (dft with the input recorded voice)

11 ビュー (過去 30 日間)
LUIGEL
LUIGEL 2016 年 9 月 17 日
コメント済み: Walter Roberson 2016 年 9 月 18 日
I am making a program that plot the magnitude vs frequency for the recorded voice in WAV file.
This is my code for the DFT:
DFT:
[y, Fs] = audioread('voice.wav');
Xn = y;
n = 0:length(Xn);
N = length(Xn);
k = N';
x = Xn*exp((-1j*2*pi*k*n)/N);
But I get an error
Error using *
Inner matrix dimensions must agree.
Error in R5_Carbonel (line 9)
x = Xn*exp((-1j*2*pi*k*n)/N);
  2 件のコメント
bayran arrieta
bayran arrieta 2016 年 9 月 17 日
Why did not you use fft?
LUIGEL
LUIGEL 2016 年 9 月 17 日
Yeah, because our Prof don't want us to use an existing functions like fft(). I think the problem is in the formula but I can't figure out how to fix this one.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 9 月 18 日
Your Xn will be a column vector of variable length (if the input is mono), or possibly an array with two columns (if the input is stereo). Let that length be L, so you have either an (L x 1) or an (L x 2) array (or even more if there are more channels!)
In your expression exp((-1j*2*pi*k*n)/N), all of the items are scalars except for n . You have
n = 0:length(Xn);
Remember, length() of a non-empty array is the largest dimension, so length(Xn) is probably going to be the number of samples (called L, above), but if you have more channels than samples then it could be the number of channels instead. It is bad programming practice to leave that to chance.
Assuming your file has more samples than channels, 0:length(Xn) is going to be length(Xn)+1 long; using our notation above, that is L+1 . And you are creating a row vector so that is (1 by (L+1))
You have Xn*exp((-1j*2*pi*k*n)/N) so the dimensions for the * operation are going to be (L x 1) on the left and (1 x (L+1)) on the right if there is only one channel in the file. The 1 of the columns on the left would match the 1 of the rows on the right, and that would be valid, producing an (L x (L+1)) output matrix. That might not be what you want, but it would not be giving you the error you are seeing.
But suppose you have two channels in the file, an (L x 2) array. The 2 of the columns on the left would not match the 1 of the rows on the right of the * operation, and you would get the error message you see.
fft related operations should be applied to each channel independently.
You should also be going back to your definition of dft. fft is an infinite summation . dft is a finite summation -- but it is a summation. Where is your summation ?
  2 件のコメント
LUIGEL
LUIGEL 2016 年 9 月 18 日
I used this code in our previous activity where our input is only a finite.
x = Xn*exp((-1j*2*pi*k*n)/N);
But when I try this on the voice file it will give me an error. Thank you for answering. Should I change my formula for the summation?
So how to do that L for the length?
Walter Roberson
Walter Roberson 2016 年 9 月 18 日
You very likely have two channels on the voice file. You should loop doing the fft of each of them at a time instead of trying to do both of them together.
x = Xn*exp((-1j*2*pi*k*n)/N);
is not doing a summation. You need to figure out what it is that you need to sum.

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

カテゴリ

Help Center および File ExchangeMeasurements and Spatial Audio についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by