The document contains several examples of generating signals composed of summed sinusoids at different frequencies, sampling rates, and lengths. It then performs a Fast Fourier Transform (FFT) on each signal to analyze its frequency content and plots the magnitude spectrum. The examples demonstrate how varying the sampling rate, length of the signal, and component frequencies affects the frequency resolution of the FFT.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
54 views
Signal Generator
The document contains several examples of generating signals composed of summed sinusoids at different frequencies, sampling rates, and lengths. It then performs a Fast Fourier Transform (FFT) on each signal to analyze its frequency content and plots the magnitude spectrum. The examples demonstrate how varying the sampling rate, length of the signal, and component frequencies affects the frequency resolution of the FFT.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9
%---------------- Signal Generator ------------------------------------
Fsampling = 4000; % Sampling frequency
T = 1/Fsampling; % Sampling period L = 1500; % Length of signal t = (0:L-1)*T; % Time vector x = sin(2*pi*1000*t)+sin(2*pi*2000*t)+sin(2*pi*3000*t); % figure; plot(t,x); title ('Original Signal'); %-----------------Fast Fourier Transform (FFT) ------------------------- n = 2^nextpow2(L); Yfft = fft(x,n); P2 = abs(Yfft/L); P1 = P2(1:n/2+1); P1(1:end-1) = 2*P1(1:end-1); figure; plot(0:(Fsampling/n):(Fsampling/2-Fsampling/n),P1(1:n/2)); title ('Frequency of the signal');
%---------------- Signal Generator ------------------------------------
Fsampling = 4000; % Sampling frequency T = 1/Fsampling; % Sampling period L = 1500; % Length of signal t = (0:L-1)*T; % Time vector x = sin(2*pi*1000*t)+sin(2*pi*5000*t)+sin(2*pi*10000*t); % figure; plot(t,x); title ('Original Signal'); %-----------------Fast Fourier Transform (FFT) ------------------------- n = 2^nextpow2(L); Yfft = fft(x,n); P2 = abs(Yfft/L); P1 = P2(1:n/2+1); P1(1:end-1) = 2*P1(1:end-1); figure; plot(0:(Fsampling/n):(Fsampling/2-Fsampling/n),P1(1:n/2)); title ('Frequency of the signal');
%---------------- Signal Generator ------------------------------------
Fsampling = 22000; % Sampling frequency T = 1/Fsampling; % Sampling period L = 1500; % Length of signal t = (0:L-1)*T; % Time vector x = sin(2*pi*1000*t)+sin(2*pi*5000*t)+sin(2*pi*10000*t); % figure; plot(t,x); title ('Original Signal'); %-----------------Fast Fourier Transform (FFT) ------------------------- n = 2^nextpow2(L); Yfft = fft(x,n); P2 = abs(Yfft/L); P1 = P2(1:n/2+1); P1(1:end-1) = 2*P1(1:end-1); figure; plot(0:(Fsampling/n):(Fsampling/2-Fsampling/n),P1(1:n/2)); title ('Frequency of the signal'); %---------------- Signal Generator ------------------------------------ Fsampling = 22000; % Sampling frequency T = 1/Fsampling; % Sampling period L = 500; % Length of signal t = (0:L-1)*T; % Time vector x = sin(2*pi*1000*t)+sin(2*pi*5000*t)+sin(2*pi*10000*t); % figure; plot(t,x); title ('Original Signal'); %-----------------Fast Fourier Transform (FFT) ------------------------- n = 2^nextpow2(L); Yfft = fft(x,n); P2 = abs(Yfft/L); P1 = P2(1:n/2+1); P1(1:end-1) = 2*P1(1:end-1); figure; plot(0:(Fsampling/n):(Fsampling/2-Fsampling/n),P1(1:n/2)); title ('Frequency of the signal'); %---------------- Signal Generator ------------------------------------ Fsampling = 4200; % Sampling frequency T = 1/Fsampling; % Sampling period L = 500; % Length of signal t = (0:L-1)*T; % Time vector x = sin(2*pi*5*t)+sin(2*pi*20*t)+sin(2*pi*500*t)+sin(2*pi*2000*t); % figure; plot(t,x); title ('Original Signal'); %-----------------Fast Fourier Transform (FFT) ------------------------- n = 2^nextpow2(L); Yfft = fft(x,n); P2 = abs(Yfft/L); P1 = P2(1:n/2+1); P1(1:end-1) = 2*P1(1:end-1); figure; plot(0:(Fsampling/n):(Fsampling/2-Fsampling/n),P1(1:n/2)); title ('Frequency of the signal'); %---------------- Signal Generator ------------------------------------ Fsampling = 4200; % Sampling frequency T = 1/Fsampling; % Sampling period L = 100; % Length of signal t = (0:L-1)*T; % Time vector x = sin(2*pi*5*t)+sin(2*pi*20*t)+sin(2*pi*500*t)+sin(2*pi*2000*t); % figure; plot(t,x); title ('Original Signal'); %-----------------Fast Fourier Transform (FFT) ------------------------- n = 2^nextpow2(L); Yfft = fft(x,n); P2 = abs(Yfft/L); P1 = P2(1:n/2+1); P1(1:end-1) = 2*P1(1:end-1); figure; plot(0:(Fsampling/n):(Fsampling/2-Fsampling/n),P1(1:n/2)); title ('Frequency of the signal'); Fsampling = 2000; % Sampling frequency T = 1/Fsampling; T = 1/Fsampling; % Sampling period L = 1500; % Length of signal t = (0:L-1)*T; % Time vector x = sin(2*pi*20*t)+sin(2*pi*1000*t)+sin(2*pi*5000*t); % First row wave figure; plot(t,x); title ('Original Signal'); Fsampling = 4000; % Sampling frequency T = 1/Fsampling; % Sampling period L = 500; % Length of signal t = (0:L-1)*T; % Time vector x = sin(2*pi*20*t)+sin(2*pi*100*t)+sin(2*pi*1000*t); % First row wave figure; plot(t,x); title ('Original Signal');
Fsampling = 3000; % Sampling frequency
T = 1/Fsampling; % Sampling period L = 1500; % Length of signal t = (0:L-1)*T; % Time vector x = sin(2*pi*20*t)+sin(2*pi*100*t)+sin(2*pi*1000*t); % figure; plot(t,x); title ('Original Signal'); %-----------------Fast Fourier Transform (FFT) ------------------------- n = 2^nextpow2(L); Yfft = fft(x,n); P2 = abs(Yfft/L); P1 = P2(1:n/2+1); P1(1:end-1) = 2*P1(1:end-1); figure; plot(0:(Fsampling/n):(Fsampling/2-Fsampling/n),P1(1:n/2)); title ('Frequency of the signal'); %---------------- Signal Generator ------------------------------------ Fsampling = 1000; % Sampling frequency T = 1/Fsampling; % Sampling period L = 1500; % Length of signal t = (0:L-1)*T; % Time vector x = sin(2*pi*20*t)+sin(2*pi*100*t)+sin(2*pi*1000*t); % figure; plot(t,x); title ('Original Signal'); %-----------------Fast Fourier Transform (FFT) ------------------------- n = 2^nextpow2(L); Yfft = fft(x,n); P2 = abs(Yfft/L); P1 = P2(1:n/2+1); P1(1:end-1) = 2*P1(1:end-1); figure; plot(0:(Fsampling/n):(Fsampling/2-Fsampling/n),P1(1:n/2)); title ('Frequency of the signal');