Why this message appears?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
clear all;
f1=200;
f2=250;
a1=1;
a2=1.5;
fe=10e3;
temps=0:1/fe:0.02-1/fe;
m1=a1*sin(2*pi*f1*temps);
m2=a2*sin(2*pi*f2*temps);
mt=m1*m2;
Error using *
Inner matrix dimensions must agree.
採用された回答
Star Strider
2019 年 5 月 1 日
It appears because you are multiplying two row vector using matrix mulktiplication.
You need to use element-wise array multiplication (using .* instead of *):
mt = m1 .* m2;
10 件のコメント
taher zaouali
2019 年 5 月 1 日
if i do that i have a problem with this:
spec_mt=fft(abs(mt.n));
Attempt to reference field of non-structure array.
Star Strider
2019 年 5 月 1 日
You have a ‘.n’ that makes no sense in the context of the rest of your code.
Try this instead:
spec_mt=fft(abs(mt));
however for best results, do this:
spec_mt=fft(abs(mt)) / numel(temps);
There is no ‘n’ in the code that you posted. If you defined ‘n’ but you did not post it and it is supposed to be the length of the fft, you need a comma, not a period, between ‘mt’ and ‘n’:
spec_mt=fft(abs(mt,n)) / numel(temps);
Walter Roberson
2019 年 5 月 1 日
Probably you want mt.*n but we would need to see more code to be more certain.
taher zaouali
2019 年 5 月 2 日
This is the whole code:
clear all;
f1=200;
f2=250;
a1=1;
a2=1.5;
fe=10e3;
temps=0:1/fe:0.02-1/fe;
m1=a1*sin(2*pi*f1*temps);
m2=a2*sin(2*pi*f2*temps);
mt=m1.*m2;
n=length(temps);
freqs=0:fe/n:fe-1/n;
spec_mt=fft(abs(mt.n));
figure(1)
subplot(211),plot(temps,mt);grid;
subplot(212),plot(freqs,spec_mt);grid;
fmod=3e3;
xt=mt.*cos(2*pi*fmod*temps);
spec_xt=fft(abs(xt.n));
figure(2)
plot(freqs,spec_xt);grid;
yt=xt.*cos(2*pi*fmod*temps);
spec_yt=fft(abs(yt.n));
y2=spec_yt;
figure(3)
plot(freqs,y2);grid;
y2(200:n)=zeros(1,n-200+1);
spec_y2=abs(y2);
x2=real(ifft(y2));
figure(5)
subplot(211),plot(temps,mt);grid;
subplot(212),plot(temps,x2);grid;
taher zaouali
2019 年 5 月 2 日
Star Strider,
If I use the comma an error appears:
too many arguments in "abs".
Star Strider
2019 年 5 月 2 日
Try this:
spec_yt=fft(abs(yt))/n;
taher zaouali
2019 年 5 月 2 日
it works but i got this warning:
Warning: Imaginary parts of complex X and/or Y arguments ignored
the graphs are not what i wanted.
Star Strider
2019 年 5 月 2 日
This takes the absolute values of the fft results, so the warning will not appear:
f1=200;
f2=250;
a1=1;
a2=1.5;
fe=10e3;
temps=0:1/fe:0.02-1/fe;
m1=a1*sin(2*pi*f1*temps);
m2=a2*sin(2*pi*f2*temps);
mt=m1.*m2;
n=length(temps);
freqs=0:fe/n:fe-1/n;
spec_mt=fft(abs(mt))/n;
figure(1)
subplot(211),plot(temps,mt);grid;
subplot(212),plot(freqs,abs(spec_mt));grid;
fmod=3e3;
xt=mt.*cos(2*pi*fmod*temps);
spec_xt=fft(abs(xt))/n;
figure(2)
plot(freqs,abs(spec_xt));grid;
yt=xt.*cos(2*pi*fmod*temps);
spec_yt=fft(abs(yt))/n;
y2=abs(spec_yt);
figure(3)
plot(freqs,y2);grid;
y2(200:n)=zeros(1,n-200+1);
spec_y2=abs(y2);
x2=real(ifft(y2));
figure(5)
subplot(211),plot(temps,mt);grid;
subplot(212),plot(temps,x2);grid;
You should probably shift the frequency axes so that ‘0’ is in the centre, or plot a one-sided fft. .
taher zaouali
2019 年 5 月 4 日
I've figured it out:
spec_mt=fft(mt,n);
plot(freqs,abs(spec_mt));grid;
the comma is between 2 parts of the fft not of the abs.
Thanks for the help.
Star Strider
2019 年 5 月 4 日
As always, my pleasure.
I took the ‘n’ out of the fft call entirely. I was not certain where you wanted to put the ‘n’, or what you wanted to do with it. If ‘n’ is the same as the size as the time-domain vector, using it as the size of the fft does not change anything, because the length of the time-domain vector is the default length of the fft for that vector.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Descriptive Statistics についてさらに検索
タグ
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
