Anda di halaman 1dari 6

% Question 1

%% Question 1 for signal x=exp(-a*t).*sin(b*pi*t);


fs = 30;
% sampling frequency
t = 0:1/fs:3;
% resolution : 1/fs
x = exp(-2*t).*sin(2*pi*t);
% input signal
y = exp(-2*t).*sin(10*pi*t);
figure,stem(t,x,'g');
% plot the signal
hold, stem(t,y,'k');
title('x(t) = exp(-a*t).*sin(b*pi*t)');
xlabel('t');
ylabel('f(t)');
grid on;
legend('exp(-2*t).*sin(2*pi*t)','exp(-2*t).*sin(10*pi*t)');
% Question 1 for signal x=exp(-t)
fs = 10;
t = 0:1/fs:30 ;
x = exp(-t);
figure, stem(t,x,'g');
title('x(t) =exp(-t)');
xlabel('t');
ylabel('x(t)');
grid on;

%
%
%
%

sampling frequency
resolution : 1/fs
input signal
plot the signal

%
%
%
%

sampling frequency
resolution : 1/fs
input signal
plot the signal

% Question 1 for signal x=exp(-10t)


fs = 10;
t = 0:1/fs:2;
x = exp(-10*t);
hold,stem(t,x,'r');
title('x(t) =exp(-10t)');
xlabel('t');
ylabel('x(t)');
grid on;
% Question 1 for signal x=exp(-100t)
fs = 1000;
t = 0:1/fs:0.2 ;
x = exp(-100*t);
hold,stem(t,x,'k');
title('x(t) =exp(-100*t);');
xlabel('t');
ylabel('x(t)');
grid on;

% sampling frequency
% resolution : 1/fs
% input signal
% plot the signal

% Question 1 for signal x = 1-|t|


fs = 10;
t = 0:1/fs:1 ;
x = 1 - abs(t);
figure,stem(t,x,'g');

%
%
%
%

sampling frequency
resolution : 1/fs
input signal
plot the signal

title('x = 1 - |t|');
xlabel('t');
ylabel('x(t)');
grid on;
% Question 2a for Signal C
i = 1;
fs = 100;
t = 0: 1/fs : 3;
x = exp(-100*t);
[g N] = size(x);
n = 0:1:N-1; % sampling time
k = 0:1:N-1;
for k2 = k
a = exp((-1j*2*pi*k2*n)/N);
y2(i) = x*a'; % transpose of exponential
i = i + 1;
end
figure, stem(abs(y2), 'g'), title('Magnitude Spectrum of 1 - abs(t)'),
ylabel('Amplitude')
xlim([0 100]);
grid on;
legend('Fs= 100');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
%% Question 2c for Signal C
fs = 100;
for x = exp(-2*t).*sin(2*pi*t);
t = 0: 1/fs : 3;
for x = 1 -abs(t)
t = 0: 1/fs : 1;
[u i] = size(y2);
[g N] = size(x);
k = 0:1:N-1; % sampling time
n = 0:1:N-1;
for n2 = n
a = exp((-1j*2*pi*n2*k)/N);
y3(i) = (1/N)*y2*a'; % transpose of exponential
i = i - 1;
end
figure, stem(t,y3, 'r'), title('x = exp(-2t).*sin(10*pi*t)'), xlabel('Time'),
ylabel('Amplitude')

xlim([0 1]);
grid on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%
%% Question 3
i = 1; fs = 100;
t1 = 0 : 1/fs : 3; x = 1- abs(t1);
for t = t1
x(i) = 1 - abs(t);
i = i+1;
end
for t = 3.01:1/fs:6 x(i) = 0; i = i+1; end
[g N] = size(x); n = 0:1:N-1; % sampling time
k = 0:1:N-1; n2 = N:1:N-1;
b = 1;
for k2 = k
a = exp((-1j*2*pi*k2*n)/N);
y2(b) = x*a'; % transpose of exponential
b = b + 1;
end
hold, stem(abs(y2), 'r'), title('Magnitude Spectrum of 1 abs(t)'),ylabel('Amplitude'), xlim([0 60]);
legend('NPoint', '2NPoint'); grid on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Question 4
i = 1; fs = 100;
t1 = 0 : 1/fs : 3;
for t = t1 x(i) = exp(-100*t); i = i+ 1; end
y = x(1:2:end);
[g N] = size(y); n = 0:1:N-1; % sampling time
k = 0:1:N-1;
b = 1;
for k2 = k
a = exp((-1j*2*pi*k2*n)/N); y2(b) = y*a'; % transpose of exponential

b = b + 1;
end
figure, stem(abs(y2), 'r'), title('Magnitude Spectrum of exp(-100*t)'),
ylabel('Amplitude'); xlim([0 300]); legend('Fs= 100'); grid on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Question 5
i = 1;fs = 100;b = 1;j =1;
t1 = 0 : 0.01/fs : 1;
for t = t1
x(i) = 1 - abs(t);
%x(i) = exp(-1*t);
i = i+ 1;
end
y = x(1:2:end);
[g N] = size(y);
k = 0:1:N-1;
n = 0:1:N-1;
for nb = n
a = exp((-1j*2*pi*k*nb)/N);
y2(b) = y*a'; % transpose of exponential
b = b + 1;
end
[g Na] = size(y);
% total samples
N = 2*Na;
N4 = N./4;
k2 = 0:1:N-1; % sampling time
nz1 = 0:1:N4-1;
ns = N4:1:3*N4-1;
nz2 = 3*N4:1:N-1;
b = 1;
i = 1;
for na = nz1
y3(b) = y2(i); % transpose of exponential
b = b + 1; i= i+1;
end
for nb = ns
y3(b)=0;
b= b+1;
end
for nc = nz2

y3(b) = y2(i); % transpose of exponential


b = b + 1; i= i+1;
end
figure, stem(y3, 'r'), title('Padded Magnitude Spectrum of 1abs(t))'),ylabel('Amplitude');
%xlim([0 20]);
legend('Fs= 100');
grid on;
[u i] = size(y3);
[g N] = size(y3);
k = 0:1:N-1;
n = 0:1:N-1;
for n2 = n
a = exp((-1j*2*pi*n2*k)/N);
y4(i) = (1/N)*y3*a'; % transpose of exponential
i = i - 1;
end
figure, stem(abs(y4), 'r'), title('x = 1- abs(t)'), ylabel('Amplitude')
xlim([0 100]);
grid on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Question 6
fs = 30;
t = 0:1/fs:17 ;
x = exp(-t);
i = 1;

% sampling frequency
% resolution : 1/fs
% input signal

[g N] = size(x);
n = 0:1:N-1; % sampling time
k = 0:1:N-1;
for k2 = k
a = exp((-1j*2*pi*k2*n)/N);
y2(i) = x*a'; % transpose of exponential
i = i + 1;
end
figure, stem(abs(y2), 'g'), title('Magnitude Spectrum of exp(-t)'),
ylabel('Amplitude')
xlim([0 100]);
grid on;
legend('Fs= 30');
y = fft(abs(x), 512);

figure, stem(abs(y)), title('Magnitude Spectrum of exp(-t) using FFT'),


ylabel('Amplitude')
xlim([0 100]);
grid on;
legend('Fs= 30');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Anda mungkin juga menyukai