Info

この質問は閉じられています。 編集または回答するには再度開いてください。

error in matlab code

1 回表示 (過去 30 日間)
houssem alimi
houssem alimi 2019 年 3 月 14 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
i want to add noise just in a part of signal
  3 件のコメント
KSSV
KSSV 2019 年 3 月 14 日
for t=0.4:0.01:0.5
x(t)=y+awgn(y(t,5);
end
The above code is not correct.......you need to rethink on it.
houssem alimi
houssem alimi 2019 年 3 月 14 日
my goal is to add noise in a part of signal between t1 and t2

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 3 月 14 日
編集済み: KALYAN ACHARJYA 2019 年 3 月 14 日
Replace the complete for loop by following line
x=y+awgn(y,10); % Here 10 represents SNR, change accordingly
No need of for loop for adding noise, awgn represents white Gaussian Noise
A1=1;A2=1; %amplitude of the signal
f1=1;f2=3; %frequency sinusoidal signal
Fs=100; %sampling rate
Ts=1/Fs; %sampling period
fi=0; %phase shift
t=0:Ts:1; %time vector
y=A1*sin(2*pi*f1*t+fi)+A2*sin(2*pi*f2*t+fi); %generated signal
subplot(121), plot(t(1:100),y(1:100),'k','LineWidth',2),grid on
axis([0 1 -Inf Inf])
title('Addition deterministic and random signal','FontWeight','Bold','FontSize',14)
xlabel('time t(second)','FontWeight','normal','FontSize',12)
ylabel('amplitude u(volt)','FontWeight','normal','FontSize',12)
x=y+awgn(y,10);
subplot(122),plot(t,x,'k','LineWidth',2),grid on
axis([0 1 -Inf Inf])
I didnot check the logic of the code. Hope it clered your error doubt.
The Reason of error, you use the for loop
for t=0.4:0.01:0.5
x(t)=.....,
which means x(0.4) is not allowed, array indxing should always in positive integer x(1), x(2)........
  2 件のコメント
houssem alimi
houssem alimi 2019 年 3 月 14 日
i want that the noise is only appeared in a part of signal such between t1=0.4 and t2 = 0.5
houssem alimi
houssem alimi 2019 年 3 月 14 日
can you help me

タグ

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by