From: Asaf Asaf on
I am trying to perform a phase shift based on the information provided in the following URL

http://www.dsprelated.com/groups/matlab/show/5198.php

However, I am not sure if I follow the instructions precisely since I am getting 'Imaginary parts of complex X and/or Y arguments ignored' warning. I understand this error is generated when in second plot I try to plot S1 signal when its a complex number. I need to plot S1 as without it I cannot visually see if any phase shift of 90 degrees has actually been done.

Any help would greatly be appreciated.
Any information on signal co-phasing would be quite helpful.

% generate two signals of amplitude 2 and 4. Phase of each signal is 0 rad
t = 0:0.01:20;
S1 = sin(t) * 2;
S2 = sin(t) * 4;

% plot both signals
figure(1)
subplot(211)
plot(t,S1, t, S2), grid on; axis([0 20 -5 5]); legend('signal 1', 'signal 2');

% phase Shift process
% perform a phase shift of 90 degrees (i.e 1.57 rad) for one of the signals
% necessary variables defined
PhaseLag = 1.570796327; % 90 degree
PhaseShift = cos(PhaseLag) + i * sin(PhaseLag); % complex phase shift

% perform FFT and multiply S1 with complex PhaseShift variable
S11 = fft(S1);
S11 = S11 * PhaseShift;

% Afterwards take the inverse transform
S1 = ifft(S11);

subplot(212)
plot(t,S1, t, S2), grid on; axis([0 20 -5 5]); legend('signal 1', 'signal 2');
From: Greg Heath on
On Aug 2, 3:35 pm, "Asaf Asaf" <m_a...(a)yahoo.com> wrote:
> I am trying to perform a phase shift based on the information provided in the following URL
>
> http://www.dsprelated.com/groups/matlab/show/5198.php
>
> However, I am not sure if I follow the instructions precisely since I am getting 'Imaginary parts of complex X and/or Y arguments ignored' warning. I understand this error is generated when in second plot I try to plot S1 signal when its a complex number. I need to plot S1 as without it I cannot visually see if any phase shift of 90 degrees has actually been done.
>
> Any help would greatly be appreciated.
> Any information on signal co-phasing would be quite helpful.

% Generate sinusoids with 0 phase and 90 deg phase lag
clear all, close all, clc
T = 2*pi, N = 32
dt = T/N, t = (0:dt:T-dt)';
Fs = 1/dt, df = Fs/N
f0 = 2*df
s1 = cos(2*pi*f0*t);

phaselag = pi/2
s2 = cos(2*pi*f0*t-phaselag);
M0 = exp(-i*phaselag)% [6.1232e-017 - 1i]
Q = ceil((N+1)/2)
M = [ M0*ones(Q,1); conj(M0)*ones(N-Q,1)];

S1 = fft(s1);
s3 = real(ifft(M.*S1));
check = max(abs(s3-s2)) % 9.992e-016

figure(1) % figure 1
hold on
plot(t,s1)
plot(t,s2,'r')
plot(t,s3,'go')
axis([0 T -2 2]);
legend('zero phase','90 deg phase lag',...
'90 deg phase lag' );

Hope this helps.

Greg
From: Asaf Asaf on
Dear Greg,

Many thanks for the source code and it does exactly what I wanted to do initially.

To aid better understanding of the code would you please add some comments to the following lines;

M0 = exp(-i*phaselag)% [6.1232e-017 - 1i]
Q = ceil((N+1)/2)
M = [ M0*ones(Q,1); conj(M0)*ones(N-Q,1)];

S1 = fft(s1);
s3 = real(ifft(M.*S1));

Asaf
From: Asaf Asaf on
Dear Greg,

Many thanks for the source code and it does exactly what I wanted to do initially.

To aid better understanding of the code would you please add some comments to the following lines;

M0 = exp(-i*phaselag)% [6.1232e-017 - 1i]
Q = ceil((N+1)/2)
M = [ M0*ones(Q,1); conj(M0)*ones(N-Q,1)];

S1 = fft(s1);
s3 = real(ifft(M.*S1));

Asaf
From: Greg Heath on
On Aug 3, 7:36 pm, "Asaf Asaf" <m_a...(a)yahoo.com> wrote:
> Dear Greg,
>
> Many thanks for the source code and it does exactly
what I wanted to do initially.
>
> To aid better understanding of the code would you
please add some comments to the following lines;
>
> M0 = exp(-i*phaselag)% [6.1232e-017 - 1i]
> Q = ceil((N+1)/2)
> M = [ M0*ones(Q,1); conj(M0)*ones(N-Q,1)];
>
> S1 = fft(s1);
> s3 = real(ifft(M.*S1));

% Generate SINGLE FREQUENCY sinusoids with 0 phase and
% 90 deg phase lag

clear all, close all, clc
T = 2*pi, N = 32
dt = T/N, t = (0:dt:T-dt)';
Fs = 1/dt, df = Fs/N
f0 = 2*df % f0 > 0 positive frequency

w0 = 2*pi*f0
plag = pi/2 % 90 deg phase lag
s1 = cos(w0*t);
s2 = cos(w0*t-plag);

% Decompose into positive and negative frequency componnts

s1 = 0.5*(exp(i*w0*t) + exp(-i*w0*t));
s1p = 0.5*exp(i*w0*t); % positive freq component
s1n = conj(s1p); % negative freq component

M0 = exp(-i*plag) % [6.1232e-017 - 1i]; Mote roundoff

s2p = 0.5*exp(i*(w0*t-i*plag));
s2n = conj(s2p);
s2p = M0*s1p;
s2n = conj(M0*s1p);
s2n = conj(M0)*s1n;

%For MULTIPLE FREQUENCY sinusoids
%
% s = M0*sp + conj(M0)*sn;

Q = ceil((N+1)/2) % Number of positive FFT frequencies

% Multiple frequency multiplier

M = [ M0*ones(Q,1); conj(M0)*ones(N-Q,1)];

S1 = fft(s1);
s3 = real(ifft(M.*S1));
check = max(abs(s3-s2)) % 9.992e-016

return


Hope this helps.

Greg