Error using * (dft with the input recorded voice)

8 visualizzazioni (ultimi 30 giorni)
LUIGEL
LUIGEL il 17 Set 2016
Commentato: Walter Roberson il 18 Set 2016
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 Commenti
LUIGEL
LUIGEL il 17 Set 2016
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.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 18 Set 2016
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 Commenti
LUIGEL
LUIGEL il 18 Set 2016
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 il 18 Set 2016
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.

Accedi per commentare.

Categorie

Scopri di più su Measurements and Spatial Audio in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by