Error using .* Matrix dimensions must agree.
3 次查看(过去 30 天)
显示 更早的评论
I am trying to plot spectrogram of audio signal usinf fft using the followinf codes
astft.m
function [ X ] = astft( x,wl )
disp('Overlapping of window is 50%');
disp('1 Rectangular Window, 2 Hamming Window, 3 Hanning Window');
window=input('Enter your choice - ');
L=length(x);
if L<wl
z=wl-L;
x=[x,zeros(1,z)];
end
switch window
case 1
win=ones(1,wl);
case 2
win=hamming(wl)';
case 3
win=hanning(wl)';
otherwise
win=ones(1,wl);
disp('Not a right option, By default rectangular window is taken.');
end
L=length(x);
hop=ceil(wl/2);
if hop<1
hop=wl;
end
i=1; str=1; len=wl; X=[];
while(len<=L || i<2)
if i==1
if len>L
z=len-L;
x=[x,zeros(1,z)];
i=i+1;
end
x1=x(str:len);
*X=[X;fft(x1.*win)];*
str=str+hop; len=str+wl-1;
end
end
figure,subplot(2,1,1)
imagesc(abs(X));
subplot(2,1,2)
surf(abs(X));
end
-------------------------------------------
Example.m
clear, clc, close all
% load a .wav file
[x, fs] = audioread('record.wav'); % get the samples of the .wav file
x = x(:, 1); % get the first channel
xmax = max(abs(x)); % find the maximum abs value
x = x/xmax;
wl=256;
[Y]=astft(x,wl);
Matrix dimension are same then also it is showing error.. 'record.wav' is a short duration audio and length(x)=25600
采纳的回答
Henric Rydén
2014-6-2
Transpose win
X=[X ; fft(x1.*win')]
and append x correctly:
x=[x ; zeros(z,1)];
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!