How to use the window functions on a signal in MATLAB?

Click For Summary
SUMMARY

This discussion focuses on applying window functions in MATLAB to compare the Fast Fourier Transform (FFT) of a sampled signal with and without windowing. The user encountered issues with the output of the triangle window function, specifically that the built-in function returned an Nx1 matrix while the signal was 1xN. The solution involved reshaping the output of the window function to match the signal dimensions, thereby resolving the unexpected results in the FFT plots.

PREREQUISITES
  • Understanding of Fast Fourier Transform (FFT) in MATLAB
  • Familiarity with window functions, specifically the triangle window function
  • Basic knowledge of MATLAB syntax and matrix operations
  • Concept of signal leakage in frequency analysis
NEXT STEPS
  • Research MATLAB's built-in window functions and their applications
  • Learn about reshaping matrices in MATLAB to ensure compatibility
  • Explore the effects of different window functions on FFT results
  • Investigate signal leakage and methods to mitigate it in frequency analysis
USEFUL FOR

This discussion is beneficial for MATLAB users, signal processing engineers, and students working on FFT analysis and windowing techniques in signal processing.

diredragon
Messages
321
Reaction score
15

Homework Statement


I am suppose to write a program that compares the FFT (Fast Fourier Transform Diagrams) of a sampled signal without the use of a window function and with it. The window function should be as long as the signal and the signal should have N points, N chosen as to not cause leakage of the specter of the signal.
**The window function should be such that it's components diminish from 0 to it's end.

Homework Equations


3. The Attempt at a Solution [/B]
I am having troubles applying the window functions because i get some weird output signal from a pretty simple line of code so I'm sure I'm not getting how this is suppose to work in MATLAB. Let's say I am trying to use the triangle window function because I am not sure what is meant by the ** condition in the assignment. Maybe that the triangle function should be symmetric on the y axis?
Matlab:
f1 = 1000;
f2 = 1270;
fs = 15000;
F1 = 100/1500; %minimum N so i wouldn't have signal leaks on the frequency diagrams.
F2 = 127/1500;
N = 1500;
n = 0:N-1;
x = 8*cos(2*pi*F1*n)+5*cos(2*pi*F2*n);

% i have found that the triangle window function is called with triang(L)
window = triang(N); %length should be N as the signal is of length N
xwindowed=x.*window;

figure 
stem(n, x);
pause

figure 
stem(n, xwindowed);
pause
The original signal outputs like this:
original.jpg

and the windowed like this:
windowed.JPG

which makes no sense and is not how this is suppose to work. What don't i understand here?
 

Attachments

  • original.jpg
    original.jpg
    65.1 KB · Views: 713
  • windowed.JPG
    windowed.JPG
    24.2 KB · Views: 691
Physics news on Phys.org
I'm not sure what the second plot looks like it does. What are you getting for the FFTs?
 
DrClaude said:
I'm not sure what the second plot looks like it does. What are you getting for the FFTs?
It turns out that the built in function returns Nx1 (for some reason) matrix and the signal is 1xN. Reshaping the result of the window function makes it work.
 
  • Like
Likes   Reactions: DrClaude

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K