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

In summary, the conversation discusses the task of writing a program that compares the FFT of a sampled signal without and with the use of a window function. The window function should have components that diminish from 0 to the end and be as long as the signal, which has N points. The person is having trouble applying the window function in MATLAB, specifically with the triangle window function. They mention getting a weird output signal and not fully understanding how it should work. They also mention issues with the size of the matrix from the built-in function and reshaping it to make it work.
  • #1
diredragon
323
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: 546
  • windowed.JPG
    windowed.JPG
    24.2 KB · Views: 577
Physics news on Phys.org
  • #2
I'm not sure what the second plot looks like it does. What are you getting for the FFTs?
 
  • #3
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 DrClaude

1. How do I apply a window function to a signal in MATLAB?

To apply a window function to a signal in MATLAB, you can use the built-in function window(). This function takes in the signal as its first argument, and the desired window function as its second argument. The output will be the signal multiplied by the window function.

2. What are the most commonly used window functions in MATLAB?

The most commonly used window functions in MATLAB include the rectangular window, Hamming window, Hanning window, and Blackman window. These window functions have different characteristics and are suitable for different types of signals and applications.

3. Can I customize the parameters of a window function in MATLAB?

Yes, you can customize the parameters of a window function in MATLAB. For example, the window() function allows you to specify the length of the window, the type of window function, and any additional parameters specific to the chosen window function.

4. How do I plot a signal with a window function in MATLAB?

To plot a signal with a window function in MATLAB, you can use the plot() function. First, apply the window function to the signal using the window() function, then plot the original signal and the windowed signal on the same plot.

5. Can I use window functions for signal processing in MATLAB?

Yes, window functions can be useful in signal processing tasks such as filtering and spectral analysis in MATLAB. By applying a window function to a signal, you can reduce the effects of spectral leakage and improve the accuracy of frequency analysis.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
11
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
748
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
Back
Top