How do i mathematically apply a window function to a signal in matlab?

Home / Uncategorized / How do i mathematically apply a window function to a signal in matlab?

Question:
I am currently trying to make a plot of a windowed signal. The plot is currently been made in latex, but can’t seem to recreate the plot generated in matlab in latex.
%% Time specifications:Fs = 8000; % samples per second
dt = 1/Fs; % seconds per sample
StopTime = 60; % seconds
t = (0:dt:StopTime-dt)’; % seconds
%% Sine wave:Fc = 60; % hertz
x = sin(0.9*pi*t) + sin(0.42*pi*t);
%x = cos(2*pi*Fc*t) + cos(2*pi*Fc*5*t)+ sin(2*pi*Fc*10*t);
% Plot the signal versus time:figure;
%plot(t,x);
%xlabel(‘time (in seconds)’);
%title(‘Signal versus Time’);
%zoom xon;
%%
window = hamming(length(t),’periodic’);
%plot(window)
windowed = x.*window;
plot(windowed)
This generates a plot like this

But when i tries to recreate the plot in matlab.. I get something way different.

What I am plotting is this :w= sin(0.9*pi*t) + sin(0.42*pi*t)*0.54 – 0.46*( cos(360*t/600))
plot(w)
First part being the signal * window = windowed signal… And what I get is this..

Why is this so different.. What am I doing wrong?


Answer:
As I see it you have two errors in your expression. First you miss parenthesis around the window function and second you have the wrong period in the cos term. Try
w = (sin(0.9*pi*t) + sin(0.42*pi*t)).*(0.54 – 0.46*( cos(2*pi*t/t(end))));
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *