This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %% FFT Demo - Information | |
| % Stephen Hartzell | |
| % 5-13-2012 | |
| % Last Revised: 1-15-2012 | |
| % | |
| % DESCRIPTION | |
| % This script demonstrates the use of the discrete fourier transform (DFT) | |
| % via the Fast Fourier Transform (FFT). Note that the fft only operates on | |
| % signals with a total number of samples equal to an integer power of 2. If |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % Define parameters | |
| Fs = 10; % Sampling Frequency | |
| Ts = 1/Fs; % Sampling Period | |
| N = 32; % Total Number of Samples | |
| n = 0:N-1; % Samples | |
| t = Ts*(n); % Sampled times | |
| y = cos(2*pi*t); % Discrete signal | |
| % Plot the signal and its discrete counter-part | |
| figure |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Y = fft(y); % The fft of the signal | |
| df = 1/(N*Ts); % The frequency resolution | |
| k = n; % Frequency spectrum samples | |
| f = k*df; % Frequency values at the k samples | |
| % Plot the fft of the signal | |
| figure | |
| stem(k,abs(Y),'filled') | |
| title('Raw Fourier Transform of y') | |
| ylabel('|fft(y)|') | |
| xlabel('k') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % Plot the useful fft of the signal | |
| figure | |
| stem(f,abs(Y)./N,'filled') | |
| title('Useful Fourier Transform of y') | |
| ylabel('Scaled |fft(y)|') | |
| xlabel('frequency (Hz)') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Fs = 10; % Sampling frequency | |
| Ts = 1/Fs; % Sampling period | |
| N = 32; % Total number of samples | |
| n = 0:N-1; % Samples | |
| t = Ts*(n); % Sampled times | |
| y = cos(2*pi*t); % Discrete 1 Hz signal | |
| yp = cos(18*pi*t); % Discrete 9 Hz signal | |
| ypp = cos(20*pi*t); % Discrete 10 Hz signal | |
| % Plot the 1 Hz signal and its discrete counter-part |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % Define parameters | |
| Fs = 10; % Sampling Frequency | |
| Ts = 1/Fs; % Sampling Period | |
| N = 32; % Total Number of Samples | |
| n = 0:N-1; % Samples | |
| t = Ts*(n); % Sampled times | |
| y = cos(2*pi*t); % Discrete signal | |
| % Plot the signal and its discrete counter-part | |
| figure |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % Define parameters | |
| Fs = 16; % Sampling Frequency | |
| Ts = 1/Fs; % Sampling Period | |
| N = 64; % Total Number of Samples | |
| n = 0:N-1; % Samples | |
| t = Ts*(n); % Sampled times | |
| y = cos(2*pi*t); % Discrete signal | |
| Y = fft(y); % The fft of the signal | |
| df = 1/(N*Ts); % The frequency resolution |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % The f and g signals | |
| f = [1,-1,4,8]; | |
| g = [2,1,5]; | |
| % Convolution of f and g | |
| f_conv_g = conv(f,g); | |
| figure, stem(f_conv_g,'filled') | |
| xlim([-1,length(f_conv_g)+1]) | |
| ylim([-20,50]) | |
| title('Convolution of f and g') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % The convolution is calculated as shown in this figure | |
| f_pad = f; | |
| g_pad = [g, zeros(1,length(f)-length(g))]; | |
| g_pad = circshift(fliplr(g_pad)',1)'; | |
| MF = zeros(1,length(f_pad)); | |
| figure('Position',[100 100 850 600]) | |
| v = VideoWriter('test.avi','Uncompressed AVI'); | |
| v.FrameRate = 1; | |
| open(v) |
OlderNewer