Error during sine-wave pwm reconstruction
2 views (last 30 days)
Show older comments
Hey guys, I'm trying to convert a sine/cosine signal into a pwm one by comparing the current sine function with a triangular/sawtooth function. Afterwards, the created pwm signal is given to a low pass filter, which is to reconstruct the original sine wave. However, the resulting function differs from the original in sense of the amplitude, and the phase isn't shifted according to the filter order (5*90°).
By increasing the frequency of the triangular function, it also decreases in amplitude. Testing those functions via wolframalpha for instance gives the desired trajectory though.
Have you any clue what might went wrong?
clear;
%---------------------------------------------------
% generation pwm signal
%---------------------------------------------------
f_sig=2.5e3;%10; % signal frequency cosine
f_saw = 20*f_sig; % signal frequency triangular
dt=1/50000; % step width
tmax=pi/4; % simulation time
%---------------------------------------------------
%---------------------------------------------------
% filter design
%---------------------------------------------------
fa = 20*f_sig; % sampling frequency
fn = 0.5*fa; % Nyquist frequency
fg = 2.6e3;%20 % cut-off frequency
Wn = fg/fn % scaled frequency
ord = 5; % filter order
%---------------------------------------------------
%---------------------------------------------------
% signal calculations
%---------------------------------------------------
Np=floor(tmax/dt);
tp=zeros(1,Np); uSp=tp;
uPWMp=tp;uCosp=tp;
k=0; t=0; uCosTP=0;
while t< tmax
uCos=cos(f_sig*2*pi*t); % cosine
uS=2/pi*atan(tan(pi*t*f_saw));%2*(f_saw*t-floor(f_saw*t))-1; % triangular function between +-1
uPWM=sign(uCos-uS); % pwm modulated cosine signal
% store plot values
k=k+1;tp(k)=t;
uSp(k)=uS; % triangular
uCosp(k)=uCos; % cosine
uPWMp(k)=uPWM; % pwm cosine
t=t+dt;
end;
%---------------------------------------------------
%---------------------------------------------------
% filter design
[b,a] = butter(ord,Wn,'low'); % Butterworth low pass
%---------------------------------------------------
%---------------------------------------------------
% plot results
figure(1);
plot(tp,uSp,':', tp,uCosp, tp,uPWMp); grid on;
figure(2)
plot(tp,uCosp,tp,filter(b,a,uPWMp));
%---------------------------------------------------
0 Comments
Answers (0)
Communities
More Answers in the Power Electronics Control
See Also
Categories
Find more on Modulation 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!