Sine Wave in Matlab t = [ 0 : 1 : 40 ]; % Time Samples f = 500; % Input Signal Frequency fs = 8000; % Sampling Frequency x = sin(2*pi*f/fs*t); % Generate Sine Wave figure(1); stem(t,x,'r'); % View the samples figure(2); stem(t*1/fs*1000,x,'r'); % View the samples hold on; plot(t*1/fs*1000,x); % Plot Sine Wave
20
Embed
Sine Wave in Matlab - Johns Hopkins Universityclsp.jhu.edu/~sriram/lectures/matlab2.pdf · Sine Wave in Matlab t = [ 0 : 1 : 40 ]; % Time Samples f = 500; % Input Signal Frequency
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Sine Wave in Matlab
t = [ 0 : 1 : 40 ]; % Time Samplesf = 500; % Input Signal Frequencyfs = 8000; % Sampling Frequencyx = sin(2*pi*f/fs*t); % Generate Sine Wave figure(1);stem(t,x,'r'); % View the samplesfigure(2);stem(t*1/fs*1000,x,'r'); % View the sampleshold on;plot(t*1/fs*1000,x); % Plot Sine Wave
Fourier Transform
% FFT LengthfftLength = 1024; % Signal LengthsigLength = length(x); % Rectangular Windowwin = rectwin(sigLength)'; % Find the DFTy = fft(x.*win,fftLength); % Figure LengthfigLength = fftLength/2 + 1; % Plot the Magnitude Response in Linear Scaleplot([1:figLength]*fs/(2*figLength),abs(y(1:figLength)));
% Plot the Magnitude Response in Log Scaleplot([1:figLength]*fs/(2*figLength),20*log10(abs(y(1:figLength))));