Sinyal Harmonik (Sin & Cos) : Function
Sinyal Harmonik (Sin & Cos) : Function
% Sampling
fs = 1000;
% Sampling rate [Hz]
Ts = 1/fs;
% Sampling period [s]
fNy = fs / 2; % Nyquist frequency [Hz]
duration = 10; % Duration [s]
t = 0 : Ts : duration-Ts; % Time vector
noSamples = length(t);
% Number of samples
% Original signal
x = 220.*sin(2 .* pi .* 50 .* t);
% Harmonics
x1 = 100.*sin(2 .* pi .* 100 .* t);
x2 = 100.*sin(2 .* pi .* 200 .* t);
x3 = 100.*sin(2 .* pi .* 300 .* t);
% Contaminated signal
xn = x + x1 + x2 + x3;
% Frequency analysis
f = 0 : fs/noSamples : fs - fs/noSamples; % Frequency vector
% FFT
x_fft = abs(fft(x));
xn_fft = abs(fft(xn));
% Plot
figure(1);
subplot(2,2,1);
plot(t, x);
subplot(2,2,2);
plot(t, xn);
subplot(2,2,3);
plot(f,x_fft);
xlim([0 fNy]);
subplot(2,2,4);
plot(f,xn_fft);
xlim([0 fNy]);
UNIT FUNCTION
STEP FUNCTION
IMPULSE
function y = dd1(n)
% Our default value is 0
y = 0;
% The function is 1 only if the input is 0
if n == 0
y = 1;
end
Lets find the appropriate output for this vector:
n = -2 : 2
We use our function above (dd1) like this:
for i = 1 : length(n)
f(i) = dd1(n(i));
end
stem(n, f)
axis([-3 3 -.5 1.5])
xlabel('n')
ylabel('Impulse Function')
COMB FUNCTION
clc
clear all
low=-10;
high=10;
step=0.01;
t=low:step:high;
Fs=2;
T=1/Fs;
L=length(t);
comb=zeros(1,L);
comb(mod(t,T)==0)=1;
stem(t,comb);
title('time');
NFFT=2^nextpow2(L);
Y=fft(comb,NFFT)/L;
f=Fs/2*linspace(0,1,NFFT/2+1);
figure
plot(f,2*abs(Y(1:NFFT/2+1)))
title('Frequency');