In: Electrical Engineering
Write a matlab code for given task
Use your ‘sin’ or ‘cos’ function to generate a sinusoid wave
having two components as
f1 = 3kHz and f2 = 5kHz and then sample it with fs = 10kHz.
Calculate its fft with zero frequency
component in the middle. Plot it on a properly scaled w-axis.
Specify if there is aliasing or not?
If there is aliasing specify which component is casing the
aliasing
MATLAB code is given below in bold letters.
clc;
close all;
clear all;
% define f1 and f2
f1 = 3e3;f2 = 5e3;
% define sampling rate
fs = 10e3; % sampling frequency
Ts = 1/fs; % sampling time
t = 0:Ts:1; % time vector
x = sin(2*pi*f1*t) + sin(2*pi*f2*t); % signal x(t) in b
% Finding FFT of x(t)
N = nextpow2(length(x));
X = fftshift(fft(x,2^N));
X = 2* X / length(x);
k = -(length(X)-1)/2:1:length(X)/2;
f = k/length(X) * fs;
figure;plot(f,abs(X));grid;
xlabel('Frequency in Hz');
ylabel('Amplitude');
title('Double sided Magnitude spectrum of x(t) = sin(2*pi*f1*t) +
sin(2*pi*f2*t)');
Spectrum is plotted below.
from the above figure, it is observed that the spectrum of the given signal contains only the 3 kHz component and the 5KHz component is not seen. This is because of the fact that the sampling frequency not being sufficient enough to represent both the frequencies. i.e. the component at 3 kHz requires a rate of greater than 6 kHz (satisfied) and the component at 5 kHz that requires greater than 10 kHz ( not satisfied).