In: Computer Science
So, I have this Matlab program that I have made for a lab, and despite having different frequencies, when I go to plot them, the graphs look exactly the same. Can someone tell me why that is? I also need to know how to determine the digital frequencies(rad/sec) and how many samples per period of both of the waves? Thank you
Code:
N = 100; % Total number of time domain samples in simulation.
A1 = 1; % Amplitude of wave-1.
A2 = 1; % Amplitude of wave-2.
Fs = 100 ;% sampling frequency.
F1 = 10; % frequency of wave - 1.
F2 = 90; % frequency of wave - 2.
phi = 0; % zero phase signal.
t=0:(1/Fs):(2); % time samples.
y1 =A1*sin(2*pi*F1*t+phi); %first sinwave.
y2= A2*sin(2*pi*F2*t+phi); %second sinwave
% plotting above functions in continuous and discrete time.
subplot 221; plot(t, y1); xlabel('Time in sec'); ylabel('Amplitude'); grid on;
subplot 222; plot(t, y2); xlabel('Time in sec'); ylabel('Amplitude'); grid on;
You got confused by the density of the plot and two different plots... they are not the same.
I modified the plotting and overlapped them, have a look:
As you can see, they are clearly separable!!!
Modified script for your reference:
%=====================================================
N = 100; % Total number of time domain samples in simulation.
A1 = 1; % Amplitude of wave-1.
A2 = 1; % Amplitude of wave-2.
Fs = 100 ;% sampling frequency.
F1 = 10; % frequency of wave - 1.
F2 = 90; % frequency of wave - 2.
phi = 0; % zero phase signal.
t=0:(1/Fs):(2); % time samples.
y1 =A1*sin(2*pi*F1*t+phi); %first sinwave.
y2= A2*sin(2*pi*F2*t+phi); %second sinwave
% plotting above functions in continuous and discrete time.
figure
plot(t, y1,'--o');
hold on
plot(t, y2,'-.^');
xlabel('Time in sec');
ylabel('Amplitude');
xlim([0 2]);
ylim([-2 2]);
grid on;
legend('y1 plot','y2 plot');
%=====================================================
To find the frequency and other stuff, you can use findpeaks command in matlab. Measure the location of consecutive peaks and calculate the time for data.. Moreover, fft has also been used for the similar purposes!