Last active
December 13, 2020 16:48
-
-
Save mattgaidica/d22948d21e33761d77187524e5e6d5ce 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
n = 1024; | |
Fs = 250; | |
t = linspace(0,(1/Fs)*n,n)'; | |
x = zeros(n,1); | |
for Fc = [5,25] | |
x = x + sin(2*pi*Fc*t); | |
end | |
L = numel(t); | |
n = (2^nextpow2(L)); | |
Y = fft(x,n); | |
f = Fs*(0:(n/2))/n; | |
P = abs(Y/n); % not squared | |
A = atan2(imag(Y),real(Y)); | |
lw = 2; | |
close all | |
figure; | |
subplot(311); | |
plot(x,'k','linewidth',lw); | |
xlim([1 numel(x)]); | |
title('Signal'); | |
set(gca,'fontsize',14); | |
subplot(312); | |
plot(P(1:n/2+1),'k','linewidth',lw); | |
title('Single-sided FFT'); | |
xlim([1 n/2]); | |
set(gca,'fontsize',14); | |
ylabel('|Y|'); | |
subplot(313); | |
plot(A(1:n/2+1),'k','linewidth',lw); | |
title('FFT Phase'); | |
xlim([1 n/2]); | |
ylabel('rad'); | |
set(gca,'fontsize',14); | |
% copy and paste this into FFTsignal.h | |
writematrix(x','FFTsignal.csv'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment