尝试用 OCTAVE 制作频谱

问题描述

请帮助,每当我尝试调用函数grapacion时,都会发生此错误error: horizontal dimensions mismatch (32768x32768 vs 1x1) 我真的对 Octave 一无所知,我的老师给我发了这个代码,但它不起作用,他根本不会帮忙。我需要获得音频的能量密度和频率谱

function grabacion(fmax,Amax)
%
[x,rate] = audioread('prueba.wav');   
%   
%fs=44100;             % frecuencia de muestreo [muestras/segundo]
%ts=1/rate;              % tiempo de muestreo [segundos/muestras]
nsample = size(x,1);   % [muestras]
nsample = pow2(nextpow2(nsample));  
x=[x;zeros(nsample - length(x)),1];  %genera un tamaño potencia de 2
%
%eje de frecuencias
dur = nsample / rate;  %duraci\'on [seg]
fs = 1 / rate;      %tasa de muestreo [seg]
t = 0:fs:dur;       %eje de tiempo [seg]
tam = length(t);    
f = (rate/2) * (1:tam/2) / (tam/2); %eje frecuencia [Hz]
N_min = round(nsample * 20 / rate) + 1;
N_max = round(nsample * fmax / rate) + 1;
f = f(N_min:N_max);
%
x = x .* hanning(length(x));
fftx = abs(fft(x));
fftx = fftx(N_min:N_max);
l = N_max - N_min + 1;
fft_x = 20 * log10(fftx);   %unidad en dB
%
% Espectro de densidad de energía  
figure;
subplot(2,1,1)
plot(f,fft_x','linewidth',2);
set(gca,2,'fontsize',14);
axis([20 fmax 0 Amax]);
title(['Densidad Espectral de Energía'] );
xlabel(['Frecuencia [Hz]']);
ylabel(['Amplitud [dB]']);
grid;
%size(t)
nx=size(x,1);
subplot(2,2)
plot(t(1:nx),x',14);
%axis([20 fmax 0 Amax]);
title(['función en el tiempo [seg]',] );
xlabel(['Tiempo [seg]']);
ylabel(['Amplitud [V]']);
grid;
endfunction  

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)