Last active
January 9, 2016 20:58
-
-
Save dugagjin/69720f940ba7d9775784 to your computer and use it in GitHub Desktop.
aliasing
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
% Maak een sinus met f1 = 1 Hz en f2 = 9 Hz, voorzie een tijdsduur van 1 s | |
% en gebruik precies 10 punten. Plot elk van deze sinussen in een aparte | |
% figuur, en vergelijk deze met een 'continue' versie van deze sinus, het | |
% is te zeggen met veel meer punten. Plot daarna in een derde figuur, de | |
% twee traag bemonsterde sinussen over mekaar. Wat merk je op? | |
clear all; clf; | |
To = 1; | |
N = 10 | |
t = linspace (0,To-1/N,N); | |
f1 = 1; | |
x1 = sin(2*pi*f1*t); | |
f2 = 9; | |
x2 = sin(2*pi*f2*t); | |
subplot (3,1,1) | |
plot (t, x1, 'ro-'); | |
title('1 Hz'); | |
grid on; | |
subplot (3,1,2); | |
plot (t, x2, 'bo-'); | |
title('9 Hz'); | |
grid on; | |
th = linspace (0,0.9,100); | |
x1h = sin(2*pi*f1*th); | |
x2h = sin(2*pi*f2*th); | |
subplot (3,1,3) | |
plot (th, x1h,'r'); | |
title('perfect 1 Hz'); | |
hold on; | |
subplot (3,1,3); | |
plot (th, x2h,'b'); | |
title('perfect 9 Hz en 1 Hz'); | |
grid on; | |
% Door een te kleine samplefrequentie lijkt de 9 Hz dezelfde frequentie te | |
% hebben als de 1 Hz. |
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
% Maak nu een vergelijking van sinussen met frequenties 9,8,7,6 en 5 Hz, | |
% nog steeds gebruik makend van 10 punten in 1 s totale duur (wat is de | |
% bemonsteringsfrequentie?), en vergleijk met de 'continue' variant. Welk | |
% trend valt je op? Herhaal het ook eens voor een sinus van 11 Hz. | |
clear all; clf; | |
t = linspace (0,1,10); | |
th = linspace (0,1,1000); | |
f = [9 ; 8 ; 7 ; 6 ; 5; 11]; | |
figure(1); | |
for i=1:length(f) | |
subplot(length(f), 1, i); | |
stem (t, sin(2*pi*f(i)*t)); | |
hold on; | |
plot (th, sin(2*pi*f(i)*th),'r-'); | |
end | |
% De bemonsteringsfrequentie is 10 Hz aangezien men per 1 seconde 10 keer sampled. | |
% De sampleperiode is dus 0.1 seconde of zoals gezegd = 10Hz. | |
% linspace is 0.9 en niet 1 omdat periode samples - 1/aantal samples = | |
% 1-1/10 = 1-0.1 = 0.9 is. |
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
% maak een fft van een sinus met f = 3 Hz en plot de imaginaire et reeële | |
% deel van deze fft. Let op om de juist fvec en tvec te gebruiken. | |
clear all; clf; | |
Te = 1; % Seconde (tijd gesampled) | |
Fs = 10; % Samplefreqentie | |
Ts = 1/Fs; % periode | |
N = Te/Ts; % MaxTijd/periode | |
f = 3; % frequentie | |
tvec = [0:N-1]*Ts; | |
fvec = [0:N-1]/N/Ts; | |
x = sin (2*pi*f*tvec); | |
y = fft(x); | |
% stem in plaats van plot om punten te tekenen. | |
subplot(1,2,1); | |
stem (fvec,imag(y)); | |
title('imaginair'); | |
xlabel('Tijd (f)'); | |
ylabel('Sinus'); | |
subplot(1,2,2); | |
stem (fvec,real(y)); | |
title('real'); | |
xlabel('Tijd (f)'); | |
ylabel('Sinus'); | |
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
% Maak een sinus met f1 = 1 Hz en f2 = 9 Hz, voorzie een tijdsduur van 1 s | |
% en gebruik precies 10 punten. Plot elk van deze sinussen in een aparte | |
% figuur, en vergelijk deze met een 'continue' versie van deze sinus, het | |
% is te zeggen met veel meer punten. Plot daarna in een derde figuur, de | |
% twee traag bemonsterde sinussen over mekaar. Wat merk je op? | |
% voeg nu ook (doel oef4) een fft aan elk signaal. Wat merk je op? | |
clear all; clf; | |
Te = 1; | |
Fs = 10; | |
Ts = 1/Fs; | |
N = Te*Fs; | |
t = [0:N-1]*Ts; | |
f1 = 1; | |
x1 = sin(2*pi*f1*t); | |
f2 = 9; | |
x2 = sin(2*pi*f2*t); | |
subplot (3,2,1) | |
plot (t, x1, 'ro-'); | |
title('1 Hz'); | |
grid on; | |
subplot (3,2,3); | |
plot (t, x2, 'bo-'); | |
title('9 Hz'); | |
grid on; | |
% We plotten nu de fft van elk gesampled sinus: | |
fvec = [0:N-1]/N/Ts; | |
subplot (3,2,2) | |
stem(fvec, abs(fft(x1)), 'ro-'); | |
title('fft 1 Hz'); | |
grid on; | |
subplot (3,2,4); | |
stem(fvec, abs(fft(x2)), 'bo-'); | |
title('fft 9 Hz'); | |
grid on; | |
% we plotten hier de "perfecte" sinus | |
Fs = 1000; | |
Ts = 1/Fs; | |
N = Te*Fs; | |
th = [0:N-1]*Ts; | |
x1h = sin(2*pi*f1*th); | |
x2h = sin(2*pi*f2*th); | |
subplot (3,1,3) | |
plot (th, x1h,'r'); | |
title('perfect 1 Hz'); | |
hold on; | |
subplot (3,1,3); | |
plot (th, x2h,'b'); | |
title('perfect 9 Hz en 1 Hz'); | |
grid on; | |
% Door een te kleine samplefrequentie lijkt de 9 Hz dezelfde frequentie te | |
% hebben als de 1 Hz. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment