0
votes

I'm trying to create real signals like a sine wave or a sine sweep in MATLAB. Since I want to go deep into the theory of the discrete Fourier transform, I'm trying to create those signals through defining a vector for my frequency response and the associated phase response in the frequency domain, to retrieve the corresponding signal in time domain using a 1000 point ifft function of MATLAB. The problem is, I just can't get the phase responses right.

fa=16000;                             
n=1000;                             
t=(0:(n-1))/fa;                      
f=(0:(n-1))*fa/n;                    

%% sine
% frequency response
X=zeros(1,1000);                     
X(26)=1;                            
% Phase 
ANG=exp(-1i*pi/2);
X=X.*ANG
X=[X(1:501) conj(fliplr(X(2:500)))];       
figure;
plot(f,real(X));                          
x=ifft(X);                           

figure
stem(x);                       


%% Sweep
% amplitude
SWEEP_real=ones(1,1000);
%Phase
for n=1:1000
    ANG=exp(-1i*(pi/2)/(1000-n));
    n=n+1;
end
SWEEP=SWEEP_real*ANG;

sweep=ifft(SWEEP);

figure
stem(sweep)

For the sine wave it somehow works, even though the phase response isn't right. I know what those phase responses should look like, but I just can't recreate them. Any tips or suggestions how to recreate those phase responses would be appreciated. Maybe I'm not approaching this task right, I'm just very confused...

1

1 Answers

1
votes

Well, there is missing one basic operation in your code. You'll see:

1- Create the fourier transformed of a sine wave. enter image description here

2- Transform that with the ifft into the time domain.

3- With the ifft you now got the real signal in the time domain. What's missing now in your code is the transform of your real time signal into the analytic signal. To do this you need the hilbert transform which you can perform in Matlab with hilbert().

4- With the obtained analytic signal you can now calculate the phase response. In Matlab for example with angle().

Have a look at my code:

fa = 16e3;                             
n = 1e3;                             
t = (0:(n-1))/fa;                      
f = (0:(n-1))*fa/n;   

%% create fourier transformed of a sine wave
X = zeros(1, 1000);                     
X(26) = 1;   
ANG = -1i/2;
X = X*ANG;
X = [X(1:501) conj(fliplr(X(2:500)))];

figure(); plot(f, real(X)); title('real(X)');
figure(); plot(f, imag(X)); title('imag(X)');

%% calculate the real signal in time domain with ifft
x_real = ifft(X);
figure(); plot(t, x_real); title('x real');

%% perform the hilbert transform on your real time signal to get the analytic signal
x_analytic = hilbert(x_real);

%% calculate the phase response
phaseresponse = angle(x_analytic);
figure(); plot(t, phaseresponse); title('phase response');

For more information you may have a look at:

http://en.wikipedia.org/wiki/Analytic_signal

http://en.wikipedia.org/wiki/Hilbert_transform

Furthermore I wonder what you are doing in your for loop. Variable ANG is a scalar which will contain in the end the result of the last calculation in your loop. So there is no need for a loop in your case. You know what I mean? I am not sure what you are basically trying to calculate there.

EDIT: For the sweep/chirp it is more difficult. I think it is easier to describe a chirp signal in time: formula for chirp signal in time

(source: wikipedia)

You could transform the time signal into the frequency domain by calculating the 'true' fourier transform and then you could try to synthesize that in Matlab.

According to wikipedia the signal contains harmonics which can be described by Bessel functions:

In the frequency domain, the instantaneous frequency described by the equation f(t)=f_{0}+kt is accompanied by additional frequencies (harmonics) which exist as a fundamental consequence of frequency modulation.[citation needed] These harmonics are quantifiably described through the use of Bessel functions. However, with the aid of a frequency vs. time profile spectrogram one can readily see that the linear chirp has spectral components at harmonics of the fundamental chirp.

For me it seems quite tricky to do so. If for you it's to understand stuff like the Fourier transform I recommend to take another (more simple) signal or to approach to the chirp signal from the time domain. May you create a chirp in time and transform it similar to my calculation above into the frequency domain. Good luck