Hi how do i plot a halfwave rectifier signal in matlab? i tried the coding below and only got the fullwave

조회 수: 87 (최근 30일)
>> 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);

채택된 답변

Star Strider
Star Strider 2020년 6월 24일
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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Gerardo Antonio López Partida
Gerardo Antonio López Partida 2020년 12월 19일
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;

Community Treasure Hunt

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

Start Hunting!

Translated by