|
From: | Rick T |
Subject: | Help improving performance of my phase shifting fft/ifft script tia sal22 |
Date: | Mon, 28 Feb 2011 07:00:21 -1000 |
Greetings All
I have a file that I perform a phase shift on a given array
and it works, but it takes about 23+ seconds to phase shift the signal 1 degree and I'm doing this 360 times. Which will take 70mins to finish 1 signal
I need to keep fs at 44100 due to the fact that it's audio thats being phase shifted
Can anyone tell me how I can improve the speed of this script? or
recommend another way of doing this to improve performace?
example file:
%speed very slow question
%Phase shift signal using fft and ifft
clc,clear,tic,clf
fs=44100;
dt=1/fs;
len=1; %view 1 sec
t=0:dt:(len-dt);
t=t';
f=2; % frequency number 2.2 doesn't work whole numbers only
y_1eq=[];y_1fft=[];
startphase=1;
incrphase=1;
endphase=180; %max freq to go to
sig=sin(2*pi*f*t);
N = length(sig); %N = length(t);
fprintf('\n building array from equation\n');
for ii=startphase:incrphase:endphase
clk=clock;
%Define a phase shift in rads
DtoR=(ii)*pi/180; %Degree to Radians
p=DtoR; %-pi/4;
num_samp = round((fs/f)*(p/(2*pi)));
%Get the FFT of the signal
z=fft(sig);
%Delay each fft component
for k=1:length(z)
w = 2*pi/N*(k-1);
spec(k)=z(k)*exp(-j*w*num_samp);
spec=spec';
end;
%Get the new signal
newsig=real((ifft(spec)));
y_1fft=[y_1fft(:,:);newsig(:,:)]; %append array of next phase change signal
fprintf('\n %3.2fdeg phase out of %6.2fdeg phase finished in -- %4.4fsec or %4.4fmins\n',ii,endphase, etime(clock, clk),etime(clock,clk)/60);
t1=etime(clock,clk);
fprintf('- time left -%4.4fsec- or -%4.4fmins- or -%4.4fhours-\n',(endphase-ii)*t1*1/incrphase,(endphase-ii)*t1*1/incrphase/60,(endphase-ii)*t1*1/incrphase/3600);
fprintf('- elapsed time -%4.4fsec- or -%4.4fmins- or -%4.4fhours-\n',toc,toc/60,toc/3600);
%plot
axis([-1 fs -1 1])
plot(newsig)
axis([-1 fs -1 1])
grid on
title(['Phase Shift is ',num2str(ii),' degrees'])
pause(.001)
end;
fprintf('- Completed in -%4.4fsec- or -%4.4fmins- or -%4.4fhours-\n',toc,toc/60,toc/3600);
tia sal22
[Prev in Thread] | Current Thread | [Next in Thread] |