Question

In: Computer Science

So, I have this Matlab program that I have made for a lab, and despite having...

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;

Solutions

Expert Solution

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!


Related Solutions

I have this matlab program, and need to turn it into a C++ program. Can anyone...
I have this matlab program, and need to turn it into a C++ program. Can anyone help me with this? % Prompt the user for the values x and y x = input ('Enter the x coefficient: '); y = input ('Enter the y coefficient: '); % Calculate the function f(x,y) based upon % the signs of x and y. if x >= 0    if y >= 0        fun = x + y;    else        fun = x + y^2;    end...
I have a project due and am having problems compiling a program: The only program I...
I have a project due and am having problems compiling a program: The only program I have written is check.c everything else is given and correct. Can you modify check.c to simply print out the chessboard, in other words, to get it to compile by any means thank you. The only thing you have to modify again is check.c nothing else. Just get it to print something thanks. program chess.c #include #include #include "chess.h" void get_valid_move(int mover) { int x_from,...
** USING MATLAB TO PROGRAM The main objective of this lab is to create a game...
** USING MATLAB TO PROGRAM The main objective of this lab is to create a game that involves betting on the sum of two dice. The player will start out with some initial total amount of money. During each round, the player can bet some money that the sum of the two dice will be equal to a certain number. If the player wins the bet, that player adds the amount of the bet to his or her current total....
I want to create an image compression program with matlab use PCA. I have the code...
I want to create an image compression program with matlab use PCA. I have the code listed below. But this code is fail, the image is colorless, but still gray. Can you help me to fix my code. clc clear all picture = im2double(imread('picture1.jpg')); Red = picture(:,:,1); premean = mean(Red(:)); premax = max(Red(:)); premin = min(Red(:)); x = size(Red,1); y = size(Red,2); Z = ones(x,y)*premean; A = (Red - Z)*(1/premax - premin); B = cov(A); [veceig,eig,C] = pcacov(B); NewRed =...
hello! So I have this CIS assignment lab but when I try to make the code...
hello! So I have this CIS assignment lab but when I try to make the code I don't really know where to start from. My professor is very hard and he likes to see the outcomes as they are shown in the problem. Please help me! Write a program that can be used as a math helper for an elementary student. The program should display two random integer numbers that are to be added, such as:     247 + 129...
So I have a lab practical coming up; how do I know when to take an...
So I have a lab practical coming up; how do I know when to take an IR spec versus making a TLC chamber? Follow up question: Can someone walk me through the interpretation of a TLC chamber?
I have the below program and I am having issues putting all the output in one...
I have the below program and I am having issues putting all the output in one line instead of two. how can I transform the program for the user enter format ( HH:MM) Like: Enter time using 24 format ( HH:MM) : " and the user enter format " 14:25 then the program convert. instead of doing two lines make all one line. Currently I have the user enter first the Hour and then the minutes but i'd like to...
I am having a trouble with a python program. I am to create a program that...
I am having a trouble with a python program. I am to create a program that calculates the estimated hours and mintutes. Here is my code. #!/usr/bin/env python3 #Arrival Date/Time Estimator # # from datetime import datetime import locale mph = 0 miles = 0 def get_departure_time():     while True:         date_str = input("Estimated time of departure (HH:MM AM/PM): ")         try:             depart_time = datetime.strptime(date_str, "%H:%M %p")         except ValueError:             print("Invalid date format. Try again.")             continue        ...
Fix the bugs in this matlab program so that it solves. clear clf clc time =...
Fix the bugs in this matlab program so that it solves. clear clf clc time = linspace(0, 5, 100); m = 1; k = 100; c = 1; delta = 0.2; [period, response] = Exmp(m, k, c, delta, time); plot(time, response) grid %Exmp(m, k, c, delta, time) % %________________________________________ function [T, x] = Exmp(m, k, c, delta, t) omega = sqrt(k/m); cC = 2*m*omega; if c>= cC disp('Not an underdamped system') T = 0; x = 0; return; end %...
I'm new in MATLAB and I have to write a code in MATLAB which converts a...
I'm new in MATLAB and I have to write a code in MATLAB which converts a number from one base to another without using base2base, etc
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT