0% found this document useful (0 votes)
29 views

Sinyal Harmonik (Sin & Cos) : Function

The document discusses harmonic signals and various unit functions. It contains code to: 1) Generate a 50 Hz sinusoidal signal contaminated with added 100 Hz, 200 Hz, and 300 Hz harmonics. FFT is used to analyze the original and contaminated signals. 2) Define an impulse (unit sample) function that returns 1 only when the input is 0. 3) Generate a comb function that returns 1 at intervals of 1/Fs (sampling frequency) and 0 elsewhere. FFT shows the comb function contains frequencies that are integer multiples of the sampling frequency.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Sinyal Harmonik (Sin & Cos) : Function

The document discusses harmonic signals and various unit functions. It contains code to: 1) Generate a 50 Hz sinusoidal signal contaminated with added 100 Hz, 200 Hz, and 300 Hz harmonics. FFT is used to analyze the original and contaminated signals. 2) Define an impulse (unit sample) function that returns 1 only when the input is 0. 3) Generate a comb function that returns 1 at intervals of 1/Fs (sampling frequency) and 0 elsewhere. FFT shows the comb function contains frequencies that are integer multiples of the sampling frequency.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SINYAL HARMONIK (SIN & COS)

% 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');

You might also like