Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Curious
Posts:
2,018
Registered:
12/6/04


Re: ??? Error using ==> times !! Matrix dimensions must agree.
Posted:
Jun 20, 2013 1:47 PM


"Jolini " <jolini25jc@gmail.com> wrote in message <kpv8qk$6k8$1@newscl01ah.mathworks.com>... > I'm getting the following error message. > > ??? Error using ==> times > Matrix dimensions must agree. > > Error in ==> Untitled2 at 28 > edges =ifft(fft(song).*fft(myFilter)); > > > This is the code i used. > > [song,FS] = wavread('c scale fast.wav'); > > > P=20000/44100*FS; % length of filter > N=length(song); % length of song > t=0:1/FS:(length(song)1)/FS; % and get sampling frequency > > song=song/max(abs(song)); > > % Gaussian Filter > x = linspace( 1, 1, N); % create a vector of N values between 1 and 1 inclusive > > sigma = 0.335; % standard deviation used in Gaussian formula > > myFilter = x .* exp( (x.^2)/(2*sigma.^2));% compute first derivative, but leave constants out > > myFilter = myFilter / sum( abs( myFilter ) ); % normalize > > > % fft convolution > song = song(:); % create a column vector > > myFilter = myFilter(:); % create a coumn vector > > song(length(song)+length(myFilter)1) = 0; %zero pad song > > myFilter(length(song)+length(myFilter)1) = 0; %zero pad myFilter > > edges =ifft(fft(song).*fft(myFilter)); > > > tedges=edges(P/2:N+P/21); % shift by P/2 so peaks line up w/ edges > tedges=tedges/max(abs(tedges)); % normalize > > figure(1); > subplot(3,1,1) > plot(t,song) > title('Wave File') > ylabel('Amplitude') > xlabel('Length (in seconds)') > ylim([0 1.1]) > xlim([0 N/FS]) > > > > subplot(3,1,2) > plot([1/FS:1/FS:N/FS],tedges) > title('Song Filtered With Edge Detector') > xlabel('Time (s)') > ylabel('Amplitude') > ylim([.5 1.1]) > xlim([0 N/FS]) > > > subplot(3,1,3) > plot(myFilter) > title('Edge Detection Filter') > > Can someone please help me out with this code so that I get the plots i need and no more error messages. I can't figure out what I'm doing wrong here.
The error message means that (in your particular case) fft(song) & fft(myFilter) are of different lengths.
From the above code, I can't tell what the length of song is (its read in), but it looks like song & myFilter should be of the same length, although I'm not sure about the statements:
song(length(song)+length(myFilter)1) = 0; %zero pad song
myFilter(length(song)+length(myFilter)1) = 0; %zero pad myFilter
I would check the lengths of song & myFilter after these statements to make sure they are doing what you think they should. If you need to zero pad, you could use the form Y = fft(x,n).
Is it possible that the fft of one of those is complex? That MIGHT explain it. (I don't have MATLAB installed on this computer, so this is just a guess.)



