plotting x[n] with various points from a file
์กฐํ ์: 3 (์ต๊ทผ 30์ผ)
์ด์ ๋๊ธ ํ์
Jorge Avila
2020๋
10์ 27์ผ
๋ต๋ณ: Alan Moses
2020๋
10์ 29์ผ
So I have an assignment that requires to do this. I have only started on point number 1.
I also have a txt file named: 'signal.txt' that has a whole bunch of points like so:
5.2529
5.2530
5.2531
5.2534
5.2539
5.2544
5.2550
5.2558
5.2567
5.2577
5.2588
5.2601
5.2615
5.2630
5.2646
5.2663
5.2682
etc.....
- The input signal ๐ฅ[๐] is contained in a text file: signal.txt. The data format is โ%1.4f\nโ and there are 1028 samples. Write the code to read these 1028 values into a floating-point array. Plot the signal ๐ฅ[๐].
- Write code to calculate the 1028-point DFT of the signal of ๐ฅ[๐]: ๐1(๐)=ฮฃ๐ฅ[๐]๐๐2๐๐๐๐๐โ1๐=0
- Plot the magnitude and phase of ๐1(๐).
Below is my code, but what I am having trouble with is plotting x[n] (on point number 1 with the various points). I do not know how to really plot x[n]. I am confused on how long the horizontal axis is going to be and the compiler keeps throwing an error since the arguments inside stem() have to be the same size. Thank you and any help is appreciated.
% Jorge Avila - 1001543128
clc
clear
close all
% This project will require you to implement the DFT computation for a
% given signal in a MATLAB script and compare your output to the output of
% the MATLAB fft() function.
% formatSpec = '%1.4f\n';
formatSpec = '%f';
fp = fopen('signal.txt','r');
numberArray = fscanf(fp,formatSpec);
arraySize = size(numberArray);
% plot x[n]
subplot(2,2,1);
% maybe do a for loop????????
stem(1028, numberArray);
% really do not care what the x & y labels are.
xlabel('n and k values');
ylabel('x[n] and X[k]');
title('Plot of number generated');
% close the file pointer
fclose(fp);
๋๊ธ ์: 0
์ฑํ๋ ๋ต๋ณ
Alan Moses
2020๋
10์ 29์ผ
Stem function requires both X and Y inputs to be vectors or matrices of the same size. You may use the following line of code:
stem(1:arraySize, numberArray);
๋๊ธ ์: 0
์ถ๊ฐ ๋ต๋ณ (0๊ฐ)
์ฐธ๊ณ ํญ๋ชฉ
์นดํ ๊ณ ๋ฆฌ
Help Center ๋ฐ File Exchange์์ Spectral Measurements์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!