0% found this document useful (0 votes)
46 views

Final Project Advanced Math

The document contains MATLAB code and plots for analyzing several signal processing problems. Problem 1, 2, and 3 solutions are checked using MATLAB by plotting the relevant functions. For Problem 2, a program samples an 8 sample sinusoid at 1/4 the sampling rate and plots the time domain data, spectral magnitude, and spectral magnitude on a dB scale. A second Problem 2 program performs zero-padding FFT interpolation on a boxcar signal, plotting the original and interpolated signals.

Uploaded by

Gelvie Lagos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Final Project Advanced Math

The document contains MATLAB code and plots for analyzing several signal processing problems. Problem 1, 2, and 3 solutions are checked using MATLAB by plotting the relevant functions. For Problem 2, a program samples an 8 sample sinusoid at 1/4 the sampling rate and plots the time domain data, spectral magnitude, and spectral magnitude on a dB scale. A second Problem 2 program performs zero-padding FFT interpolation on a boxcar signal, plotting the original and interpolated signals.

Uploaded by

Gelvie Lagos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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