# I have to create a rectangular signal with a different period and amplitude at every run, but I don t know how to chnage the aplitude

3 views (last 30 days)
Stefan on 9 Dec 2022
Commented: Stefan on 9 Dec 2022
clc
close all
clear all
format long
Fs1=1000;
Fs2=1000;
Ts1=1/Fs1;
Ts2=1/Fs2;
A1=1;
A2=2;
t1 =-2 : Ts1 : 2;
t2=-2 : Ts2 :2;
x1=rectpuls(t1,rand);
x2=rectpuls(t2,rand);
figure
plot(t1,x1,t2,x2)
grid

Askic V on 9 Dec 2022
Edited: Askic V on 9 Dec 2022
Just play with randn (normal/gauss distrbution):
clc
close all
clear all
format long
Fs1=1000;
Fs2=1000;
Ts1=1/Fs1;
Ts2=1/Fs2;
A1=1;
A2=2;
t1 =-2 : Ts1 : 2;
t2=-2 : Ts2 :2;
width1 = 1+0.5*randn; % Signal width is 1 with std deviation +-0.5
width2 = 1+2*randn; % Signal width is 1 with std deviation +-0.5
amp1 = 3 + 2*randn; % amp1 is 3 with deviation of +-2
amp2 = 2 + 0.5*randn;
x1 = amp1*rectpuls(t1,width1);
x2 = amp2*rectpuls(t2,width2);
figure
plot(t1,x1,t2,x2)
grid
##### 1 CommentShowHide None
Stefan on 9 Dec 2022
It works now, thank you!

### Categories

Find more on Spectral Measurements in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!