Full-wave rectified sine wave with gaps

Hello everybody, can someone explain to me how to make graph like this in Mathlab?

Answers (1)

One approach —
Fs = 1000;
L = 1;
t = linspace(0, Fs*L, Fs*L+1).'/Fs;
s = abs(sin(2*pi*t));
idx8 = numel(s) / 8;
t8 = max(t) / 8;
idxv = round(idx8 * cumsum([3 1 3 1]));
tv = t8 * cumsum(([3 1 3 1]));
sv = s;
sv(idxv(1) : idxv(2)) = 0;
sv(idxv(3) : idxv(4)) = 0;
figure
plot(t, s)
grid
axis('padded')
title('Original Full-Wave Rectified Sine Wavve')
figure
plot(t, sv)
grid
axis('padded')
title('Desired Waveform')
EDIT — (25 Aprr 2025 at 18:12)
Extending this is relatively straightforward, and rrequires only minor modifications —
Fs = 1000;
L = 5;
t = linspace(0, Fs*L, Fs*L+1).'/Fs;
s = abs(sin(2*pi*t));
idx8 = numel(s) / 8;
t8 = max(t) / 8;
idxv = round(idx8 * cumsum(repmat([3 1 3 1]/L,1,L)));
tv = t8 * cumsum(repmat([3 1 3 1]/L,1,L));
sv = s;
idxm = reshape(idxv, 2, []).';
for k = 1:size(idxm,1)
sv(idxm(k,1) : idxm(k,2)) = 0;
end
figure
plot(t, s)
grid
axis('padded')
title('Original Full-Wave Rectified Sine Wavve')
figure
plot(t, sv)
grid
axis('padded')
title('Desired Waveform')
The 'L' parameter is a repitition constant.
.

Products

Release

R2018b

Asked:

on 25 Apr 2025

Edited:

on 25 Apr 2025

Community Treasure Hunt

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

Start Hunting!