MATLAB错误:产品:不合格的参数(OP1是131072x1,OP2 IS 128000x1)
我正在尝试在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
[答案]更新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')
I'm trying to multiply two vectors in my matlab code. But in this line,
fHatNoisy = indices.*fHat
It says the error,
error: product: non-conformant arguments (op1 is 131072x1, op2 is 128000x1)
Even-though I've tried adding the operator '.' i still get the error..
Got any idea why this error occurs?
The total piece of code:
[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
UPDATE: It was because the two arrays, fHat and indices are not equal length, that is the reason why i suspect the error occurs. Trying to figure out why fft() returns a different size of an array than the PSD = fHat * conj(fHat)/n
More Information about PSD, N, their lengths etc:
[ANSWER]Update 2, Calculating PSD for DFT/FFT:
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')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论