フィルターのクリア

Adding noise to a sine wave

4 ビュー (過去 30 日間)
Aswas
Aswas 2017 年 8 月 23 日
コメント済み: Aswas 2017 年 8 月 23 日
Hi, I get error: Attempt to reference field of non-structure array. Error using + Matrix dimensions must agree.Error in (line 19), y=x+(alpha.v)
for following code please:
fs=8000;
tmax=4/360;
fangular=pi/10; % angular frequency (rad/sample).
n=1:fs*tmax;
A=1.2; % Amplitude
x=A*sin(n*fangular);
v=randn(1,64);
alpha=0.1;
noise=alpha*v;
y = x + noise;
plot(y)

回答 (1 件)

Jos (10584)
Jos (10584) 2017 年 8 月 23 日
The expression "v.alpha" is interpreted by matlab as the contents of the field "alpha" of the structure variable "v". This is probably not what you meant.
You create v as a 1-by-64 array, and alpha is a scalar. I assume you want to simply multiply all elements of v by alpha, therefore:
v .* alpha
or, since alpha is a scalar,
v * alpha
  2 件のコメント
Aswas
Aswas 2017 年 8 月 23 日
編集済み: Aswas 2017 年 8 月 23 日
Thanks Jos, but neither works, same error please: Error using + Matrix dimensions must agree.
Error in (line 20)
y = x + noise;
Aswas
Aswas 2017 年 8 月 23 日
Thanks I found answer from another question in this forum.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by