Help plotting signal time shifted using FFT
16 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi! This is my first Matlab project and first question here, so it might be some simple syntax error I'm not getting. Yes it's a school project so I can't use built-in functions.
I'm trying to use a DFT matrix to convert a signal (rectangle function), and then multiplying it by an exponent. This, when converted back, should give me a time shifted signal. Instead, I get the original signal (unshifted). This is the code:
N = 2001; %period
middle = floor((N-1)/2);
ts = -middle:middle;
fs = -middle:middle;
dft_matrix = (1/N)*exp(-1i*2*pi*fs'*ts/N);
idft_mtx = exp(1i*2*pi*fs'*ts/N);
a = zeros(N,1);
a(middle-100:middle+100) = 1;
ak = dft_matrix*a;
bk = exp(-1i*2*pi*100/N).*ak;
b = idft_mtx * bk;
plot(ts,b)
I'd appreciate tips how to make the code better :)
Thank you!
0 Commenti
Risposta accettata
Umar
il 7 Lug 2024
Hi Guilhermo,
Based on your description, it seems like you are attempting to perform a Discrete Fourier Transform (DFT) operation on a rectangular signal and then apply a time shift by multiplying it with an exponential function.
However, you are encountering an issue where the resulting signal is not shifted as expected. Upon reviewing your code, it appears that the problem lies in the way you are calculating the time shift. The line `bk = exp(-1i*2*pi*100/N).*ak;` is where the error might be occurring. The multiplication by `exp(-1i*2*pi*100/N)` introduces a phase shift of -100, which does not correspond to a time shift in the signal domain.
To correct this issue and achieve the desired time shift, you should modify the calculation of `bk` to correctly incorporate the time shift. Instead of applying a fixed phase shift, you should multiply `ak` by an appropriate phase term based on the desired time shift value. For example, if you want to shift the signal by 100 samples, you can modify the line as follows: `bk = exp(-1i*2*pi*100/N.*fs).*ak;`.
By adjusting this part of your code to account for the correct time shift, you should be able to generate the shifted signal as intended.
Additionally, consider verifying your implementation by comparing the results with known analytical solutions or using test cases with simpler signals to validate the correctness of your code.
If you encounter any further challenges or need additional guidance on optimizing your code, feel free to provide more details or specific questions for further assistance.
Good luck with your Matlab project!
Più risposte (1)
Umar
il 8 Lug 2024
Hi Guilhermo,
I am pleased to hear that the solution provided worked for you. If you have any further questions or need assistance in the future, please do not hesitate to reach out.
0 Commenti
Vedere anche
Categorie
Scopri di più su Time-Frequency Analysis in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!