- 'fft' function: https://www.mathworks.com/help/matlab/ref/fft.html
- 'Discrete Fourier Transforms: https://www.mathworks.com/help/signal/ug/discrete-fourier-transform.html
Checking the linearity of the DFT. The questions is posted below with the code .
51 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
% A. Checking the linearity of the DFT
clear; clc;
N=100;
fs=100;
t=0:1/fs:(N-1)/fs;
f1=10; d1=3*sin(2*pi*f1*t);
f2=20; d2=2*sin(2*pi*f2*t);
f=fs*(0:length(d1)-1)/length(d1);
% Additivity
D1=fft(d1);
D2=fft(d2);
WiSu= fft(d1+d2); % complete (spectrum of sum of signals)
SuWi= D1+D2; % complete (sum of signal spectra)
subplot(4,1,1); stem(f,(2/N)*abs(D1));xlabel('f [Hz]');grid;
subplot(4,1,2); stem(f,(2/N)*abs(D2));grid;
subplot(4,1,3); stem(f,(2/N)*abs(WiSu));title('Spectrum of sum of signals ');grid;
subplot(4,1,4); stem(f,(2/N)*abs(SuWi));title('Sum of signal spectra');xlabel('f [Hz]');grid;
% Homogeneity - do it yourself by modifying the code above
0 comentarios
Respuestas (2)
Balavignesh
el 4 de Dic. de 2023
Editada: Balavignesh
el 4 de Dic. de 2023
Hello Mohammod,
I understand that you are interested in examining the linearity of the Discrete Fourier Transform (DFT) using MATLAB. To confirm linearity, it's important to assess both additivity and homogeneity properties. The provided code showcases the additivity property of the DFT.
To validate the homogeneity property, you can enhance the existing code by scaling one of the signals before their addition. Subsequently, you could compare the DFT of the scaled signal with the scaled original DFT signal to confirm their equality. Below is an example code that may assist you in this process:
% A. Checking the linearity and homogeneity of the DFT
clear; clc;
N = 100;
fs = 100;
t = 0:1/fs:(N-1)/fs;
f1 = 10; d1 = 3*sin(2*pi*f1*t);
f2 = 20; d2 = 2*sin(2*pi*f2*t);
f = fs*(0:length(d1)-1)/length(d1);
% Additivity
D1 = fft(d1);
D2 = fft(d2);
WiSu = fft(d1 + d2); % Spectrum of the sum of signals
SuWi = D1 + D2; % Sum of signal spectra
% Homogeneity
alpha = 2; % Scaling factor
HomogeneityCheck = fft(alpha * d1); % Apply scaling to d1 and take the DFT
% Plotting
subplot(3,1,1); stem(f, (2/N)*abs(D1)); xlabel('f [Hz]'); title('D1 Spectrum'); grid;
% subplot(3,1,..); stem(f, (2/N)*abs(D2)); xlabel('f [Hz]'); title('D2 Spectrum'); grid;
% Verifying Additivity
% subplot(3,1,..); stem(f, (2/N)*abs(WiSu)); xlabel('f [Hz]'); title('Spectrum of Sum of Signals'); grid;
% subplot(3,1,..); stem(f, (2/N)*abs(SuWi)); xlabel('f [Hz]'); title('Sum of Signal Spectra'); grid;
% Verifying Homogeneity
subplot(3,1,2); stem(f, (2/N)*alpha*abs(D1)); xlabel('f [Hz]'); title('Scaling D1 spectrum'); grid;
subplot(3,1,3); stem(f, (2/N)*abs(HomogeneityCheck)); xlabel('f [Hz]'); title('Spectrum of scaled signal'); grid;
The equivalence between the plots 2 (Scaling D1 spectrum) and 3 (Spectrum of scaled signal) confirms homogeneity, thereby establishing the verification of the linearity property.
Kindly refer to the following documentation links to have more information on:
Hope that helps!
Balavignesh
0 comentarios
mohamed
el 15 de Dic. de 2023
اصف %Periodicity property الى clc; clear all; close all; A = 1; % Amplitude f = 5; % Frequency in Hz alpha = 0.5; % Damping factor Fs = 100; % Sampling frequency T = 1/Fs; % Sampling period L = 1000; % Length of signal % Time vector t = (0:L-1)*T; % Generate the signal x1 = A * sin(2*pi*f*t).* exp(-alpha*t); % Compute the DFTs % 4-point DFT N_4 = 4; X_4 = fft(x1(1:N_4)); % 8-point DFT N_8 = 8; X_8 = fft(x1(1:N_8)); % 16-point DFT N_16 = 16; X_16 = fft(x1(1:N_16)); % Displaying the results for DFT without Zero Padding % 4-point DFT subplot(3, 2, 1); stem((0:N_4-1) * Fs / N_4, abs(X_4)); title('Magnitude Spectrum (4-point DFT)'); xlabel('Frequency (Hz)'); ylabel('Magnitude'); % 8-point DFT subplot(3, 2, 3); stem((0:N_8-1) * Fs / N_8, abs(X_8)); title('Magnitude Spectrum (8-point DFT)'); xlabel('Frequency (Hz)'); ylabel('Magnitude'); % 16-point DFT subplot(3, 2, 5); stem((0:N_16-1) * Fs / N_16, abs(X_16)); title('Magnitude Spectrum (16-point DFT)'); xlabel('Frequency (Hz)'); ylabel('Magnitude'); % Compute the DFTs with Zero Padding % 4-point DFT with Zero padding N_4_zero_pad = 16; x1_4_zero_pad = [x1(1:N_4), zeros(1, N_4_zero_pad - N_4)]; X_4_zero_pad = fft(x1_4_zero_pad); % 8-point DFT with Zero padding N_8_zero_pad = 16; x1_8_zero_pad = [x1(1:N_8), zeros(1, N_8_zero_pad - N_8)]; X_8_zero_pad = fft(x1_8_zero_pad); % 16-point DFT with Zero padding N_16_zero_pad = 16; x1_16_zero_pad = [x1(1:N_16), zeros(1, N_16_zero_pad - N_16)]; X_16_zero_pad = fft(x1_16_zero_pad); % Displaying the results for DFT with Zero Padding % 4-point DFT with Zero padding subplot(3, 2, 2); stem((0:N_4_zero_pad-1) * Fs / N_4_zero_pad, abs(X_4_zero_pad)); title('Magnitude Spectrum (4-point DFT with Zero padding)'); xlabel('Frequency (Hz)'); ylabel('Magnitude'); % 8-point DFT with Zero padding subplot(3, 2, 4); stem((0:N_8_zero_pad-1) * Fs / N_8_zero_pad, abs(X_8_zero_pad)); title('Magnitude Spectrum (8-point DFT with Zero padding)'); xlabel('Frequency (Hz)'); ylabel('Magnitude'); % 16-point DFT with Zero padding subplot(3, 2, 6); stem((0:N_16_zero_pad-1) * Fs / N_16_zero_pad, abs(X_16_zero_pad)); title('Magnitude Spectrum (16-point DFT with Zero padding)'); xlabel('Frequency (Hz)'); ylabel('Magnitude'); i want to add %Periodicity property
0 comentarios
Ver también
Categorías
Más información sobre Spectral Measurements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!