Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

PROBLEM 1 SOLUTION CHECKED USING MATLAB

PLOT OF THE FUNCTION FOR PROBLEM 1 USING MATLAB.


PROBLEM 2 SOLUTION CHECKED USING MATLAB

PLOT OF THE FUNCTION FOR PROBLEM 2 USING MATLAB.


PROBLEM 3 SOLUTION CHECKED USING MATLAB

PLOT OF THE FUNCTION FOR PROBLEM 3 USING MATLAB.


PROBLEM 2 PROGRAM AND PLOT USING MATLAB
% Parameters:
N = 8; % Must be a power of two
T = 1; % Set sampling rate to 1
A = 1; % Sinusoidal amplitude
phi = 0; % Sinusoidal phase
f = 0.125; % Frequency (cycles/sample)
n = [0:N-1]; % Discrete time axis
x = A*cos(2*pi*n*f*T+phi); % Sampled sinusoid
X = fft(x); % Spectrum

% Plot time data:


figure(1);
subplot(3,1,1);
plot(n,x,'*k');
ni = [0:.1:N-1]; % Interpolated time axis
hold on;
plot(ni,A*cos(2*pi*ni*f*T+phi),'-k'); grid off;
title('Sinusoid at 1/4 the Sampling Rate');
xlabel('Time (samples)');
ylabel('Amplitude');
text(-8,1,'a)');
hold off;
% Plot spectral magnitude:
magX = abs(X);
fn = [0:1/N:1-1/N]; % Normalized frequency axis
subplot(3,1,2);
stem(fn,magX,'ok'); grid on;
xlabel('Normalized Frequency (cycles per sample))');
ylabel('Magnitude (Linear)');
text(-.11,40,'b)');
% Same thing on a dB scale:
spec = 20*log10(magX); % Spectral magnitude in dB
subplot(3,1,3);
plot(fn,spec,'--ok'); grid on;
axis([0 1 -350 50]);
xlabel('Normalized Frequency (cycles per sample))');
ylabel('Magnitude (dB)');
text(-.11,50,'c)');
PROBLEM 2 PROGRAM AND PLOT USING MATLAB

N = 8;
n=0:N-1;
x = (0.9).^n; % simply boxcar signal clf
subplot(2,1,1);
stem(n, x)
xlabel ('n')
ylabel ('x[n]')
axis([0 N 0 2])
M = 4;
X = fft(x);
middle = X(N/2+1)/2;
Y = M * [X(1:N/2) middle zeros(1, (M-1)*N-1) middle X(N/2+2:end)];
y = real(ifft(Y));
t = linspace(0, N, N*2*M);
xt = (0.9).^t;
subplot(2,1,2)
plot(0:length(y)-1, y, 'o', t*M, xt, '--')
legend('y[n]', 'x(t)')
xlabel ’n’, ylabel ’y[n]’
axis([0 M*N 0 2])
title ('FFT-based interpolation of x[n]')
hold on
stem(n*M, x, 'filled'),
hold off

You might also like