幅值为5、频率为10Hz的正弦信号,并写入数据文件MySin.txt,并读取文本文件MySin.txt 中的数据文件,进行绘图.
% Applying the Mysin function to generate a sine waveform
...with amplitude and frequency are 5 and 10 respectively,and then
...writing the sine wave data to the text file-Mysin.txt
clear;clc;
A = 5; % The amplitude of sinusoid.
fre = 10; % The frequency of sinusoid.
N = 1024; % The number of sampling points.
Fs = 1024; % Sampling frequency.
dt = 1/Fs; % Time interval.
t = (0:(N-1))*dt; % Time vector.
Xt = A*sin(2*pi*f*t + 3*pi/4); % Generating a sine function.
file_type = fopen('D:\MySin.txt','w'); % open text file-MySin.txt.
...(Creat a text file unless this text file is exist) fprintf(file_type,'%12f\n',Xt); % Formatting the input data,and the to the text file. fclose(file_type); % close the text file-Mysin.txt.
% Reading the data in the text file-Mysin.txt,and then ploting the sinusoid.
B = load('D:\MySin.txt'); % Loading the data of sinusoid.
plot(t,B); % ploting the sinusoid.
ylim([-max(B)-max(B)/4 max(B)+max(B)/4]); % Set the range of Y axis.
title('正弦信号X=5*sin(20*\pi*t+3*\pi/4)','FontName','黑体','FontSize',10); % Add the title.
xlabel('Time/(s)','FontName','黑体','FontSize',10); % Add the label
of X axis.
ylabel('X(t)','FontName','New Times Roman','FontSize',10); % Add the label of Y axis.