repmat() introduces an unnecessary phase shift
1 view (last 30 days)
Show older comments
Hi, I used repmat command to create a periodic waveform.
However I noticed repmat() introduces a phase shift of one element in the array in each repetition.
I compared the analytical waveform (plotted in Green) with the repmat generated signal
Pls give some advice to correct.
Code:
clc;
clear all;
fc=4; %control waveform
T=1/fc;
t1=0:.001:T/6;
t2=T/6:.001:2*T/6;
t3=2*T/6:.001:3*T/6;
t4=3*T/6:.001:4*T/6;
t5=4*T/6:.001:5*T/6;
t6=5*T/6:.001:6*T/6;
%Positive limit
Ap=sqrt(3) + sin(2*pi*t1*fc - 2*pi/3);
Bp=sin(2*pi*t2*fc);
Cp=sqrt(3) + sin(2*pi*t3*fc + 2*pi/3);
Dp=sin(2*pi*t4*fc - 2*pi/3);
Ep=sqrt(3) + sin(2*pi*t5*fc + 2*pi);
Fp=sin(2*pi*t6*fc + 2*pi/3);
%Negative Limit
An=sin(2*pi*t1*fc - 2*pi/3);
Bn=-sqrt(3) + sin(2*pi*t2*fc);
Cn=sin(2*pi*t3*fc + 2*pi/3 );
Dn=-sqrt(3) + sin(2*pi*t4*fc + 4*pi/3);
En=sin(2*pi*t5*fc );
Fn=-sqrt(3) + sin(2*pi*t6*fc + 2*pi/3);
t=[t1 t2 t3 t4 t5 t6];
yp=[Ap,Bp,Cp,Dp,Ep,Fp];
yn=[An,Bn,Cn,Dn,En,Fn];
%plot(t,yp,t,yn)
m=3 ; % Repetition
n=numel(t);
tt=0:0.001:n*m*0.001-0.001;
yy_p=repmat(yp,1,m);
yy_n=repmat(yn,1,m);
max_shoothru=[yy_p;yy_n];
% analytical wave
Y1p=((1-0.5*sqrt(3)))*sin(3*4*2*pi*tt +pi) + sqrt(3)/2;
Y1n=((1-0.5*sqrt(3)))*sin(3*4*2*pi*tt +pi ) - sqrt(3)/2;
analytical=[Y1p;Y1n];
%3 phase voltage waveforms
A_ph=sin(2*pi*tt*fc);B_ph=sin((2*pi*tt*fc)+ 2*pi/3);C_ph=sin((2*pi*tt*fc)- 2*pi/3);
waves=[A_ph;B_ph;C_ph];
plot(tt,max_shoothru,tt,waves,'r',tt,analytical,'g');
grid on;
0 Comments
Answers (1)
Walter Roberson
on 10 Dec 2013
Suppose you create a periodic waveform over 0 to 1. Then when you repmat it, you get [0...1 0...1 0...1]. Note that the second 1 is not at the position that would correspond to 2, and is instead one sample later.
To correct this, what you need to repeat is the samples over 0 to 1 without the 1 itself. e.g.,
W = linspace(0, 1, 1000);
W25 = repmat(W(1:end-1), 1, 25);
If you want a final return to beginning you can,
W25 = [repmat(W(1:end-1), 1, 25), W(end)];
0 Comments
See Also
Categories
Find more on Matrices and Arrays 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!