Thursday, January 9, 2014

Moving signal in frequency domain (MATLAB)

In this post, i am going to show how a moving signal (in time domain) remain unchanged in the frequency domain using MATLAB

The following codes generate a 21 moving signal with the same profile defined by sech(x)

clear all; close all; clc;

T=30;
n=512;

t2=linspace(-T/2, T/2, n+1);

t=t2(1:n);

k=(2*pi/T)*[0:n/2-1 -n/2:-1];
ks=fftshift(k);

slice=0:0.5:10;

[T, S]=meshgrid(t, slice);
[K, S]=meshgrid(ks, slice);

U=sech(T-10*sin(S));
subplot(2, 1, 1);
waterfall(T, S, U), colormap([0 0 0]), view(-15, 70);

[X,Y] = meshgrid(xgv,ygv) replicates the grid vectors xgv and ygv to produce a full grid. This grid is represented by the output coordinate arrays X and Y. The output coordinate arrays X and Y contain copies of the grid vectors xgv and ygv respectively. The sizes of the output arrays are determined by the length of the grid vectors. For grid vectors xgv and ygv of length M and N respectively, X and Y will have N rows and M columns.

U=sech(T-10*sin(S)).*exp(i*0*T) creates the 21 moving signals in time domain in a matrix of size length(slice)*length(t)

waterfall(T, S, U) plots the moving signals as shown in the figure below

Image and video hosting by TinyPic

The following MATLAB code plot the moving signals in both the time domain and frequency domain

clear all; close all; clc;

T=30;
n=512;

t2=linspace(-T/2, T/2, n+1);

t=t2(1:n);

k=(2*pi/T)*[0:n/2-1 -n/2:-1];
ks=fftshift(k);

slice=0:0.5:10;

[T, S]=meshgrid(t, slice);
[K, S]=meshgrid(ks, slice);

U=sech(T-10*sin(S));
subplot(2, 1, 1);
waterfall(T, S, U), colormap([0 0 0]), view(-15, 70);

for j=1:length(slice)
    UT(j, :)=abs(fftshift(fft(U(j, :))));
end


subplot(2, 1, 2);
waterfall(K, S, UT), colormap([0 0 0]), view(-15, 70);

The figure below shows the moving signals in both the time domain and frequency domain, it can be seen that the frequency spectrum of all the moving signals remain unchanged

Image and video hosting by TinyPic

No comments:

Post a Comment