Multiplication of envelope function to that of sine wave

5 views (last 30 days)
Hello,
I am trying to multiply a base sine wave to that of a square wave and this square wave should act as an switch i,e if there is amplitude 1 then the sine should be present else 0,
t = 0:1e-4:0.1;
x = (1+square(4*pi*50*t)).*sin(2*pi*1000*t); %carrier frequency is 1khz and modulation frequency is 50hz
plot(t,x)
my question is I want different duration for both square function which is acting as an envelope and sine function which is the base and should be modified according to the envelope, but when I try to do it with two different durations it is giving me a matrix mismatch.
t = 0:1e-4:0.1;
ts = 0:1e-4:0.4
T = [t ts]
x = (1+square(4*pi*50*t).*sin(2*pi*1000*ts); %carrier frequency is 1khz and modulation frequency is 50hz
plot(T,x)
Thank you.

Accepted Answer

Star Strider
Star Strider on 12 May 2021
I would just use the same value (either ‘t’ or ‘ts’) for both —
t = 0:1e-4:0.1;
ts = 0:1e-4:0.4;
T = [t ts];
x = (1+square(4*pi*50*t).*sin(2*pi*1000*t)); %carrier frequency is 1khz and modulation frequency is 50hz
figure
plot(t,x)
xlim([0 0.02]) % Zoom For Detail (Optional)
It would be possible to use both, however it would then be necessary to create a matrix of them, and that could be difficult to represent, for example —
x = (1+square(4*pi*50*t.')*sin(2*pi*1000*ts)); %carrier frequency is 1khz and modulation frequency is 50hz
figure
surf(ts, t, x)
grid on
xlabel('ts')
ylabel('t')
axis([0 0.025 0 0.00025 zlim]) % Zoom For Detail (Optional)
figure
surf(ts, t, x, 'EdgeColor','none')
grid on
xlabel('ts')
ylabel('t')
.

More Answers (0)

Categories

Find more on Visualization and Data Export 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!