MATLAB错误:产品:不合格的参数(OP1是131072x1,OP2 IS 128000x1)

发布于 2025-01-24 19:13:31 字数 1538 浏览 1 评论 0原文

我正在尝试在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,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:
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文