Created
July 26, 2017 03:30
-
-
Save stephenHartzell/2d4cafcb389770cae636568176e60433 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fs = 10; % Sampling frequency | |
Ts = 1/Fs; % Sampling period | |
N = 32; % Total number of samples | |
n = 0:N-1; % Samples | |
t = Ts*(n); % Sampled times | |
y = cos(2*pi*t); % Discrete signal | |
N = length(y); % The new total number of samples | |
Y = fft(y); % The fft of the signal | |
df = 1/(N*Ts); % The frequency resolution | |
k = 0:N-1; % Frequency spectrum samples | |
f = k*df; % Frequency values at the k samples | |
% Now lets make y length 64 by padding y with zeros | |
% p = "prime" | |
yp = y; | |
yp(length(y)+1:length(y)+32) = zeros(1,32); | |
Np = length(yp); % The new total number of samples | |
Yp = fft(yp); % The fft of the signal | |
dfp = 1/(Np*Ts); % The frequency resolution | |
kp = 0:Np-1; % Frequency spectrum samples | |
fp = kp*dfp; % Frequency values at the k samples | |
% Plot the fft of the signal | |
figure | |
subplot(2,1,1), stem(fp,abs(Yp),'filled') | |
title('Spectrum of Zero-Padded Signal') | |
ylabel('|fft(y)|') | |
xlabel('Frequency (Hz)') | |
subplot(2,1,2), stem(f,abs(Y),'filled') | |
title('Spectrum of non Zero-Padded Signal') | |
ylabel('|fft(y)|') | |
xlabel('Frequency (Hz)') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment