Put Zero Value randomly in wave function

1 vue (au cours des 30 derniers jours)
Rakan Akmal Musalim
Rakan Akmal Musalim le 19 Mar 2022
So i have a sin wave function and i want to put zero value number randomly into the wave function. Is that possible and how to ?
%Sine wave
freq=400;
Amp=2;
t_samp=1/8000;
T=0.01;
t=0:t_samp:T;
y=Amp*sin(2*pi*freq*t);
subplot(2,1,1);
plot(t,y)
ylabel ('Amplitude');
xlabel ('Time');
title ('Sine wave');

Réponse acceptée

Star Strider
Star Strider le 19 Mar 2022
Try something like this —
%Sine wave
freq=400;
Amp=2;
t_samp=1/8000;
T=0.01;
t=0:t_samp:T;
y=Amp*sin(2*pi*freq*t);
y(randi(numel(y))) = 0; % Random Value (Index) = 0
subplot(2,1,1);
plot(t,y)
ylabel ('Amplitude');
xlabel ('Time');
title ('Sine wave');
.

Plus de réponses (1)

Atsushi Ueno
Atsushi Ueno le 19 Mar 2022
Yes it is possible. You can put zero value by making random value index of y.
%Sine wave
freq=400;
Amp=2;
t_samp=1/8000;
T=0.01;
t=0:t_samp:T;
y=Amp*sin(2*pi*freq*t);
y(randi([1 numel(y)],1,10)) = 0; % ----- here
subplot(2,1,1);
plot(t,y)
ylabel ('Amplitude');
xlabel ('Time');
title ('Sine wave');

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by