MATLAB Answers

## Signal analysis - need help with FFT

Asked by Janusz Rogalski

### Janusz Rogalski (view profile)

on 6 Jan 2019
Latest activity Commented on by dpb

### dpb (view profile)

on 7 Jan 2019
I have a signal that I'm trying to analyze using FFT and rectangular window. However I am not sure how to adjust the value of "t" and use rectangular window on this signal to perform correct analysis Can you please tell me what am I doing wrong? Thank you in advance.
clear
close all
clc
fs=2000;
T=1/fs;
t=0:T:(1-T);
y=sin(200*t.*sin(60*t));
% Plot signal
figure(1);
plot(t,y);
title('Signal');
xlabel('Time [s]');
ylabel('Amplitude');
% Spectrum
figure
widmo=(abs(fft(y)));
stem(widmo);
title('Spectrum')
grid on;
axis tight;
xlabel('Frequency [Hz]');
ylabel('Amplitude')
% Rectangular window
N = length(y);
w = window(@boxcar,fs);
okno = y.*w';
figure;
plot(t,okno);
figure;
bar(abs(fft(okno)));

dpb

### dpb (view profile)

on 6 Jan 2019
Well, being homework, we expect the student to do the work! :)
Do you understand the comment re: the rectangular window being the same as no window?
Are you sure that's really the signal you're intending? That's a most peculiar one, if so, and hardly conducive to a beginning exercise...
After you plotted it have examined its characteristics closely? (HINT: expand the x-axis markedly like w/ xlim([0 0.2]) )
Look at the example at
doc fft
for calculation of the FFT-based one-sided PSD normalized to yield the signal magnitude for a noise-free signal...there are several long threads I've written Answers to here on the forum over the last several months to year, perhaps, that expound on this subject at length.
David Goodmanson

### David Goodmanson (view profile)

on 7 Jan 2019
Hi Janusz,
It may or may not be what was intended, but certainly the spectrum of
y = sin(200*t).*sin(60*t);
is a lot easier to interpret than the spectrum of
y = sin(200*t.*sin(60*t));
dpb

### dpb (view profile)

on 7 Jan 2019
Ah! yes, a misplaced parentheis could make a big difference here! Good catch! :)

Sign in to comment.