Wednesday, February 24, 2010

Visualising the Complex Exponential

 
x=-20:.1:20;y=-20:.1:20;
[X,Y] = meshgrid(x,y);
a=-0.05;b=0.75;
% Real Component :    e^(ax)cos(by)
z=exp(a*X).*cos(b*Y);
subplot(2,2,1)
mesh(X,Y,z)
zrr=exp(a*x).*cos(b*0);
hold on
plot3(x,zeros(length(x)),zrr,'r','LineWidth',3)
zir=exp(a*0).*cos(b*y);%zi=exp(j*b*y);
plot3(zeros(length(x)),y,zir,'r','LineWidth',4)
zrr=exp(a*x).*cos(b*y);%zrr.*zir;
plot3(x,y,zrr,'b','LineWidth',4)
hold off

% Imaginary Component :    je^(ax)sin(by)
z=exp(a*X).*sin(b*Y);
subplot(2,2,2)
mesh(X,Y,z)
hold on
zri=exp(a*x)*sin(0);
plot3(x,zeros(length(x)),zri,'r','LineWidth',3)
zii=exp(a*0)*sin(b*y);
plot3(zeros(length(x)),y,zii,'r','LineWidth',4)
zii=exp(a*x).*sin(b*y);
plot3(x,y,zii,'b','LineWidth',4)
hold off

subplot(2,2,3)
plot(zrr+j*zii)
 

Monday, February 22, 2010

3-D view of a waveform

I have used the DFT to decompose the waveform into its components and have used 'plot3' to display the in a 3-D image. The image can be rotated in MATLAB to examine the frequency domain as well as the time domain. The second figure shows the figure rotated.

N=128;n=0:N-1;fund=3/N;%0+.0167/2;
x=sin(2*pi*fund*n)+sin(2*3*pi*fund*n)/3+...
sin(2*pi*5*fund*n)/5+sin(2*pi*7*fund*n)/7;
%x=x.*(hamming(N))';
DFT3D_1(x)

function DFT3D_1(x)
N=length(x);
n=0:N-1;
%x=x.*(hamming(N))';
X=fft(x)*2/N;
X1=abs(X')*ones(1,N);X1=X1';
f=(0:N-1)/N; % Harmonics
[ff,nn]=meshgrid(f,n);
W=cos(2*pi*f'*n);
X1=W'.*X1;
X1(:,1)=x;
plot3(ff,nn,X1,'LineWidth',1);grid on
xlabel('frequency');
ylabel('time seconds');
axis([0 1 0 N -1.3 1.3]);
    view([37.5 30])