Professional Documents
Culture Documents
frequency = 1;
time_period = 1/frequency;
num_cycle = 3;
duration = num_cycle/frequency;
amplitude = 1;
sample = 10000;
t = linspace(0, duration, duration * sample);
%Generating a sin function
sin_wave = amplitude*sin(2*pi*frequency*t);
plot(t, sin_wave,'linewidth',2);
title('Sine Wave');
xlabel('Time (s)');
ylabel('Amplitude(m)');
legend ('sin wave')
grid on;
///////////////////////////////////////
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^?////////////////////////
witn linspace command
% Define parameters
frequency = 1;
amplitude = 1;
max_cycles = 100;
sampling_rate = 1000;
duration = max_cycles / frequency;
t_original = linspace(0, duration, duration * sampling_rate);
original_signal = amplitude * sin(2 * pi * frequency * t_original);
% Extract the first three cycles
Extract_cycle = 3;
Extracting_duration = Extract_cycle / frequency;
Extracted_time = linspace(0, Extracting_duration, Extracting_duration *
sampling_rate);
extracted_signal = amplitude * sin(2 * pi * frequency * Extracted_time);
% Plot the original and extracted signals
subplot(2, 1, 1);
plot(t_original, original_signal,'linewidth',2);
title('Original Signal (100 Cycles)');
xlabel('Time (s)');
ylabel('Amplitude');
legend('orignal signal')
grid on;
subplot(2, 1, 2);
plot(Extracted_time, extracted_signal,'--r','linewidth',2);
title('Extracted Signal (3 Cycles)');
xlabel('Time (s)');
ylabel('Amplitude');
legend('Extracted signal')
grid on;
subplot(2, 1, 2);
plot(t_original, extracted_signal,':g','linewidth',2);
xlim([0 3])
title('Extracted Signal (3 Cycles)');
xlabel('Time (s)');
ylabel('Amplitude(m)');
legend('t extracted')
grid on;
//////////////////////////////////
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&7777777777777777777777777777777777777
in LAB TASK 03
warning Integer operands are required for colon operator when used as index
to remove this we use I've rounded the indices in the frequencies vector
calculation using round(N/2) to ensure that they are integers, which will remove
the warning.
% Define parameters
Fs = 10000; % Sampling frequency (Hz)
t = 0:1/Fs:1; % Time vector from 0 to 1 second
frequencies = [500, 2500, 4000]; % Frequencies of the three components (Hz)
A_initial = 1; % Initial equal amplitude for all components