How to do a phase shift of a signal

515 次查看(过去 30 天)
Hello,
I want to do a phase shift of a signal and I can't get the right method to do it. What I am doing is that first I do the FFT of the signal and then I get Phase and Magnitude. In the phase I add or subtract the value to be shifted and then I use the new phase and the old magnitude and do IFFT to get back the signal but what I get is not a shifted signal and also the signal value of the Y axis alos changed which should not be change.
Can any one guide me how to achieve successfully the phase shift without changing the value in y axis.
Thanks
  1 个评论
$$$ $$$
$$$ $$$ 2018-7-23
% % close all; % % clear all; % % x = 0:1e-6:60e-3; % bis 60 ms mit 1µs Schritte % % a = sin(2*pi*50*x); % % b = sin(2*pi*50*x-pi); % % y_rad=acos(dot(a,b)/(norm(a)*norm(b))) % % y_deg=y_rad*360/(2*pi) % % plot(x,a,x,b) % % xlabel(['Winkel in degree ist: ',num2str(y_deg)],'Color','r') % % grid on

请先登录,再进行评论。

回答(7 个)

Jan
Jan 2012-8-18
I'm not sure if I understand the question. Is FFT useful for a phase-shift? What about shifting the phase directly?
x = sin(linspace(0, 10*pi, 10000));
x_shift = zeros(1, numel(x));
x_shift(1:9000) = x(1001:10000);
But perhaps I've overlooked the complexity of the question.
  1 个评论
Yvonne Haesevoets
Yvonne Haesevoets 2021-11-15
编辑:Yvonne Haesevoets 2023-6-13
s/he is looking for fractional phase shifts for which you cannot "shift the phase directly".
For time-shifts by a non-integer number of samples, you need to use a property of the DTFT : a shift in the time-domain amounts to a modulation in the frequency domain (and vice-versa).
Here is a correct implementation (see answer #1 by Prabhan Purwar):
https://www.mathworks.com/matlabcentral/answers/483938-time-shifting-an-audio-in-a-frequency-domain?s_tid=mwa_osa_a

请先登录,再进行评论。


majid shaik
majid shaik 2015-5-14
编辑:majid shaik 2015-5-14
I wrote some code to do the same thing it does work but not sure is it right please go through this
% code
clc
clear all
close all
f1=20;
t1=1;
fc=100*f1;
samples=1000;
t=(0:samples-1)/fc;
y=sin(2*pi*f1*t);
t0=1000/fc;
f=linspace(-fc/2,fc/2,samples);
y_ff=fftshift(fft(y));
y_ff2=exp(-j*2*pi*f*t0).*y_ff;
y2=ifft(ifftshift(y_ff2));
plot(t,abs(y2))
hold on
plot(t,y,'r')
grid on

daniel mitchell
daniel mitchell 2021-11-24
Hello, This may help?
t = 0:0.01:2*pi;
x = sin(t);
Possible way 1:
k = 324; % t is of size 629 so if k=324 it corresponds to t(k)=pi approx
delta = zeros(1,length(x)); delta(k)=1;
x_ph = cconv(delta,x,length(x));
figure;
subplot(2,1,1); plot(t,x);
subplot(2,1,2); plot(t,x_ph);
Possible way 2:
X = fft(x);
w = (2*pi/length(x)) * (0:length(x)-1);
k = 324;
X_ph = X.*exp(-1i*w*k);
x_ph = ifft(X_ph);
figure;
subplot(2,1,1); plot(t,x);
subplot(2,1,2); plot(t,x_ph);
Warning: Imaginary parts of complex X and/or Y arguments ignored.
Possible way 3 (complex representation) :
x_complex = exp(1i*t);
x_complex_ph = x_complex*exp(-1i*pi);
x_ph = imag(x_complex_ph); %imag cause imag(e^it)=sin(t)
figure;
subplot(2,1,1); plot(t,x);
subplot(2,1,2); plot(t,x_ph);

$$$ $$$
$$$ $$$ 2018-7-23
% % close all; % % clear all; % % x = 0:1e-6:60e-3; % bis 60 ms mit 1µs Schritte % % a = sin(2*pi*50*x); % % b = sin(2*pi*50*x-pi); % % y_rad=acos(dot(a,b)/(norm(a)*norm(b))) % % y_deg=y_rad*360/(2*pi) % % plot(x,a,x,b) % % xlabel(['Winkel in degree ist: ',num2str(y_deg)],'Color','r') % % grid on

Malwinder Singh
Malwinder Singh 2018-7-27
编辑:Walter Roberson 2020-6-8
clc;
clear all;
close all;
IF=10e6;
FS=100e6;
TS=1/FS;
L=256;
n=1:L;
t0=0.1*(TS);%% shited by 0.1 times of sample time
x_real=cos(2*pi*(IF/FS)*n);
x_imag=sin(2*pi*(IF/FS)*n);
sig_vect=complex(x_real,x_imag);
fft_out=fft(sig_vect);
fft_shifted=exp(-2i*pi*(IF)*t0)*fft_out;
sig_time_shifted=ifft(fft_shifted);
figure(1)
plot(real(sig_vect),'r*-')
hold on
plot(real(sig_time_shifted),'g*-')
grid on;
  2 个评论
Asaf Haddad
Asaf Haddad 2020-10-26
There is no point in the fft and ifft here, since are simply multiplying with a constant phase. It doesn't matter if you multiply the signal or it transform.
Yvonne Haesevoets
Yvonne Haesevoets 2021-11-15
for fractional phase shifts, there is no other way than to do it by application of one of the DTFT's properties : time shift => modulation in frequency

请先登录,再进行评论。


Akanksha Pathak
Akanksha Pathak 2019-11-6
For a signal, π f t) with frequency f , if we want to provide phase shift of ϕ radian,
Equation 1: ϕ=2πf, where is delay in time
Equation 2: =sin(2 πft+ ϕ)
In case, we want to provide phase shift of θ degree, then
Equation 3: θ=360 f
Compute the required delay using equation 3, compute corresponding delay in radian using equation 1, and use it to generate phase shift in using equation 2.
Hope this answers

Ties
Ties 2021-12-3
I have the same question.
Only i use FT function of Matlab. If I want to have the phase shift of the signal, can I use the FFTshift function of matlab

Community Treasure Hunt

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

Start Hunting!

Translated by