我正在尝试在 matlab 代码中将两个向量相乘。但在这一行中,
fHatNoisy = indices.*fHat
它说错误,
error: product: non-conformant arguments (op1 is 131072x1, op2 is 128000x1)
尽管我尝试添加运算符“.”我仍然收到错误..
知道为什么会出现此错误吗?
总代码:
[samples,samplingRate] = audioread('car.wav')
dt=1/samplingRate
sampleLength=length(samples)
duration = sampleLength/samplingRate
time = 0:dt:duration #time vector
n=length(time)
%disp("sampling Rate"+Fs)
fHat = fft(samples, n)
%psd = periodogram (fHat)
PSD = periodogram (fHat)
indices = PSD<0.01 #Find all freqs with large power
PSDClean1 = PSD.*indices #find out all others(While there are 0s, PSDs which are there will be 0 from indices vector)
fHatNoisy = fHat.*indices #Zero out small Fourier coeffs. in Y
更新:这是因为两个数组,fHat和索引的长度不相等,这就是我怀疑发生错误的原因。试图找出为什么 fft() 返回的数组大小与 PSD = fHat * conj(fHat)/n (即 PSD = periodogram (fHat))不同的数组大小
[解答]更新 2,计算 DFT/FFT 的 PSD:
pkg load signal;
[samples,samplingRate] = audioread('car.wav')
dt=1/samplingRate
sampleLength=length(samples)
n = length(samples); % number of samples
frequencyRange = (0:n-1)*(samplingRate/n); % frequency range
fHat = fft(samples)
power = abs(fHat).^2/n; % power of the DFT
plot(frequencyRange,power)
xlabel('Frequency')
ylabel('Power')