Skip to content

Instantly share code, notes, and snippets.

@alastair
Last active December 15, 2015 00:09
Show Gist options
  • Save alastair/5171074 to your computer and use it in GitHub Desktop.
Save alastair/5171074 to your computer and use it in GitHub Desktop.
Matlab , upsampling sin waves
%-- 03/15/2013 04:50:02 PM --%
fs = 11025;
r = 1/fs;
x = [0:r:1];
y = sin(2 * pi * 400 * x);
NFFT = 2^nextpow2(11025);
Y = fft(y,NFFT)/11025;
f = fs/2*linspace(0,1,NFFT/2+1);
plot(f,2*abs(Y(1:NFFT/2+1)))
u2 = upsample(y, 2);
U2 = fft(u2,NFFT)/11025;
plot(f,2*abs(U2(1:NFFT/2+1)))
u4 = upsample(y, 4);
U4 = fft(u4,NFFT)/11025;
plot(f,2*abs(U4(1:NFFT/2+1)))
u8 = upsample(y, 8);
U8 = fft(u8,NFFT)/11025;
plot(f,2*abs(U8(1:NFFT/2+1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment