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:
- 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.
formatSpec = '%f';
fp = fopen('signal.txt','r');
numberArray = fscanf(fp,formatSpec);
arraySize = size(numberArray);
xlabel('n and k values');
ylabel('x[n] and X[k]');
title('Plot of number generated');