Creating Sine wave with random values

Hello All,
I'm trying to introduce sine signal as false information to my system. Now presently, I have this siganl with values in array like
I= [6 16 6 16 75 1 22 6 6 6 6 22 25 25 25 25 23 5 5 16 9 9 9 9];
These are 24 values, I ploted this values and calculated the prices in such way that price for each value is determined. Now I wanted to introduce a sine wave signal as a fault signal, the problem is how to get only 24 valus like these discrete values for sine wave such that signal looks sinusidal with 24 discrete values and I dont know how to that, kindly help me out.

Antworten (1)

Philippe Lebel
Philippe Lebel am 26 Nov. 2019

1 Stimme

here is my try:
random_phase_offset = rand(1,1)*2*pi;
max_amplitude = 20;
random_amplitude = rand(1,1)*max_amplitude;
t = (0:1/23:1)*2*pi;
signal = random_amplitude * sin(t+random_phase_offset);
plot(t,signal)

5 Kommentare

shane watson
shane watson am 26 Nov. 2019
@Philippe, this close enough but is only half cycle, moreover, it starts with -ve values, how can I control these values and make it full cycle. Thanks in Advance.
the example i provided is full cycle. Do you want 2 periods?
In order to have only positive starting values, you can restrict the phase offset to be only in the interval [0,pi].
here is the modified code.
random_phase_offset = rand(1,1)*pi;
max_amplitude = 20;
random_amplitude = rand(1,1)*max_amplitude;
t = (0:1/23:1)*4*pi;
signal = random_amplitude * sin(t+random_phase_offset);
plot(t,signal)
shane watson
shane watson am 26 Nov. 2019
@Philippe Lebel, Yes, It works extactly, except one thing, though signal has 24 values (array) but the signal needs to start from 1 to 24, in this case it starts from 0 to only 14 (roughly) though I try to change "t"start value to 1, and 4 pi to other values, but didnot get exact 1 to 24 values (x axis). Thanks in Advance.
Philippe Lebel
Philippe Lebel am 27 Nov. 2019
Bearbeitet: Philippe Lebel am 27 Nov. 2019
by "start" what do you mean?
t is a list that goes from 0 to 4*pi in steps of 4*pi/23. It is written to have exactly 24 components.
Signal wouldn't have 24 values if "t" didn't have 24 values.
shane watson
shane watson am 5 Dez. 2019
I'm sorry for late response, I agreed with your comment, however, I meant to say that when looking at figure the plot start from value "0" (not "1", which is required). Secondly´, the array has 24 values which is exactly as I wanted, however, the figure shows the plot which eventully stops at value 14, the appreances of plot values should also reach to 24 as array has 24 values because I'm resembling it with 1 to 24 hours. Thanks in Advance.

Melden Sie sich an, um zu kommentieren.

Kategorien

Tags

Gefragt:

am 26 Nov. 2019

Kommentiert:

am 5 Dez. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by