Hi how do i plot a halfwave rectifier signal in matlab? i tried the coding below and only got the fullwave
57 views (last 30 days)
Show older comments
zahrah S
on 24 Jun 2020
Answered: Gerardo Antonio López Partida
on 19 Dec 2020
>> f=50
f =
50
>> T=//f
T=//f
|
Error: Unexpected MATLAB operator.
>> T=1/f
T =
0.0200
>> l=linespace(0,10,100);
Undefined function or variable 'linespace'.
Did you mean:
>> l=linspace(0,10,100);
>> t=1:100;
>> sig=sin(2*pi*f*l*(t));
Error using *
Inner matrix dimensions must agree.
>> sig=sin(2*pi*f*l(t));
>> plot(t,sig);
0 Comments
Accepted Answer
Star Strider
on 24 Jun 2020
To rectify it, use logical indexing to eliminate the parts of the signal that are less than 0:
f=50;
t=linspace(0,30,500);
sig=sin(2*pi*f*t);
rect_sig = sig > 0; % Half-Wave Rectification
figure
plot(t(rect_sig), sig(rect_sig));
For full-wave rectification, use the abs() function.
4 Comments
More Answers (1)
Gerardo Antonio López Partida
on 19 Dec 2020
clc
clear all
close all
T=2*pi;%here you can change de period
t=0:T/1000:T;
f_t=sin(t).*(square(t,50));
plot(t,f_t,'r','linewidth',3);grid on;
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!