fft of Rectangle*sin function in MATLAB

7 views (last 30 days)
Hi!
I would like to analyze the Fourier Transform of the signal that consists of multiplication of sin and rectangular functions.
I am doing it in the way representing in the code and I would expect to obtain a sinusoidal signal that is "bordered" by the rectangular one. For this purpose, I have selected the period of the rectangular signal equal to T = 0.02s and correspondingly the frequency of the sin signal 1/0.02 = 50 Hz.
The problem is that I obtain an error which forces me to use an elementwise multiplication of the signals (which apparently would not be a correct way).
In the frequency domain I would expect to obtain two sinc-functions that are shifted to the left and to the right by 50Hz/2 (Doppler effect), however the result is a straight line.
What am I doing wrong?
Thank you in advance!
Regards
Rostyslav
close all
clear
Ts = 0.01; N=2000; t=-20:Ts:(N-1)*Ts;
T = 0.02;
fs=1/Ts;
f=0:fs/N:(N-1)/N*fs;
x1 = rectpuls(t, T)*sin(2*pi*1/T*t); %error is here. Elementwise multiplication
xk=fft(x1);
figure(1); plot(t,x1);
figure(2); plot(f, 1/N*abs(xk(1:length(f))));

Accepted Answer

Paul
Paul on 1 Jan 2021
Edited: Paul on 2 Jan 2021
It appears that you want to find the Continuous Time Fourier Transform of a windowed cos wave, where the window covers an integer number of periods. Here's how to do it using symbolic math. The frequencies of the peaks in the plot will be approach w0 = +- 2*pi/T as Nperiod increases:
syms T Nperiod t w real
f(t) = cos(2*pi*t/T);
g(t) = heaviside(t+T*Nperiod/2)-heaviside(t-T*Nperiod/2); % define the window over some periods of f(t)
h(t)=f(t)*g(t);
H(w) = simplify(fourier(h(t)));
Hfun = matlabFunction(H(w));
% make a plot with actual data
wreal = -20:.01:20;
Treal = 1; % the actual period
Nperiodreal = 10; % window over 10 periods
plot(wreal,Hfun(Nperiodreal,Treal,wreal)),grid
Hfun will have a very small imaginary part due to roundoff. Someone with more symbolic expertise might be able to further simplify H(w).
Trying to do this in the discrete time domain may (will?) lead to confusion because the DFT (which is implemented by FFT) of a cosine windowed over an integer number of periods will look deceiving compared to the CTFT.
Edit: H(w) simplfies like so (assuming we really want the window over an integer number of periods):
assume(Nperiod,'integer')
H(w)=simplify(H(w))

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!