أخذ العينات وتحويل فورييه السريع
clc; clear all; close all;
tfinal = 0.05;
t = 0:0.00005:tfinal;
f = input('Enter the analogy frequency f = ');
xt = cos(2*pi*f*t);
%Under sampling plot
fs1 = 1.3*f;
n1 = 0:1/fs1:tfinal;
xn = cos(2*pi*f*n1);
subplot(3,1,1); plot(t,xt,'b',n1,xn,'r*-');
title('under sampling'); xlabel('time'); ylabel('amplitude');
%Nyquist plot
fs2=2*f;
n2 = 0:1/fs2:tfinal;
xn = cos(2*pi*f*n2);
subplot(3,1,2); plot(t,xt,'b',n2,xn,'r*-');
title('nyquist sampling'); xlabel('time'); ylabel('amplitude');
%Over sampling plot
fs3 = 5*f;
n3 = 0:1/fs3:tfinal;
xn = cos(2*pi*f*n3);
subplot(3,1,3); plot(t,xt,'b',n3,xn,'r*-');
title('over sampling'); xlabel('time'); ylabel('amplitude');
clc; clear all; close all;
f1 = input('Enter the first sine wave frequency f1 = ');
f2 = input('Enter the second sine wave frequency f2 = ');
fn = 2*max(f1,f2);
fs = 0.5*fn;
t = [0:1/fs:0.1];
x = cos(2*pi*f1*t)+cos(2*pi*f2*t);
xk = fft(x);
f = [0:length(xk)-1]*fs/length(xk);
figure, plot(f,abs(xk));
xlabel('frequency'); ylabel('amplitude'); title('Under Sampling');
grid;
fs = fn;
t = 0:1/fs:0.1;
x = cos(2*pi*f1*t)+cos(2*pi*f2*t);
xk = fft(x);
f = [0:length(xk)-1]*fs/length(xk);
figure; plot(f,abs(xk));
xlabel('frequency');ylabel('amplitude');title('Nyquist Rate Sampling');
grid;
fs = 5*fn;
t = 0:1/fs:0.1;
x = cos(2*pi*f1*t)+cos(2*pi*f2*t);
xk = fft(x);
f = [0:length(xk)-1]*fs/length(xk);
figure; plot(f,abs(xk));
xlabel('freq'); ylabel('Amplitude');title('Over Sampling');
grid;