Docsity

Lab 01 fft, Study notes of Digital Signal Processing

Toggle sidebar
bg1
MATLAB program to calculate FFT of a signal
clc
clear all
close all
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sample time fro the signal
L = 1000; % Length of signal
t = (0:L-1)*T; % Time vector
x = 0.9*sin(2*pi*50*t) % A 50 Hz Signal
y = x + 2*randn(size(t)); % Sinusoids plus noise
subplot(211)
plot(Fs*t,y); % Multiplying by Fs for convenience only
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('time (milliseconds)') % since we have multiplied time by Fs in the
% plot function so unit of time has to be
% mentioned here i.e. milliseconds
%% Frequency Analysis
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
% linspace(0,1,NFFT/2+1); (NFFT/2)+1=513 for this case, so there will be
% 513 points between 0 and 1, then we multiply this vector by fs/2=500,
% so that vector f contains the frequency index
%Plot single-sided amplitude spectrum.
subplot(212)
plot(f,2*abs(Y(1:NFFT/2+1))) % plotting only the single sided magnitude ofY
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')

Partial preview of the text

Download Lab 01 fft and more Study notes Digital Signal Processing in PDF only on Docsity!

MATLAB program to calculate FFT of a signal

clc clear all close all Fs = 1000; % Sampling frequency T = 1/Fs; % Sample time fro the signal L = 1000; % Length of signal t = (0:L-1)T; % Time vector x = 0.9sin(2pi50t) % A 50 Hz Signal y = x + 2randn(size(t)); % Sinusoids plus noise subplot(211) plot(Fst,y); % Multiplying by Fs for convenience only title('Signal Corrupted with Zero-Mean Random Noise') xlabel('time (milliseconds)') % since we have multiplied time by Fs in the % plot function so unit of time has to be % mentioned here i.e. milliseconds %% Frequency Analysis NFFT = 2^nextpow2(L); % Next power of 2 from length of y Y = fft(y,NFFT)/L; f = Fs/2linspace(0,1,NFFT/2+1); % linspace(0,1,NFFT/2+1); (NFFT/2)+1=513 for this case, so there will be % 513 points between 0 and 1, then we multiply this vector by fs/2=500, % so that vector f contains the frequency index %Plot single-sided amplitude spectrum. subplot(212) plot(f,2*abs(Y(1:NFFT/2+1))) % plotting only the single sided magnitude ofY title('Single-Sided Amplitude Spectrum of y(t)') xlabel('Frequency (Hz)') ylabel('|Y(f)|')