Facebook
From Mihana, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 148
  1. % Define the parameters
  2. frequency = 10; % Frequency in Hertz
  3. amplitude = 1; % Amplitude of the sine wave
  4. phase = 0; % Phase shift in radians
  5. samplingRate = 8000; % Sampling rate in samples per second
  6. duration = 0.25; % Duration of the signal in seconds
  7.  
  8. % Create the time vector
  9. t = 0:1/samplingRate:duration;
  10.  
  11. % Generate the sine wave
  12. y = amplitude * sin(2 * pi * frequency * t + phase);
  13.  
  14. % Plot the sine wave
  15. plot(t, y);
  16. xlabel('Time (s)');
  17. ylabel('Amplitude');
  18. title('Sine Wave');
  19.  
  20. % Define the parameters
  21. frequency = 10; % Frequency in Hertz
  22. amplitude = 1; % Amplitude of the cosine wave
  23. phase = 0; % Phase shift in radians
  24. samplingRate = 8000; % Sampling rate in samples per second
  25. duration = 0.25; % Duration of the signal in seconds
  26.  
  27. % Create the time vector
  28. t = 0:1/samplingRate:duration;
  29.  
  30. % Generate the cosine wave
  31. y = amplitude * cos(2 * pi * frequency * t + phase);
  32.  
  33. % Plot the cosine wave
  34. plot(t, y);
  35. xlabel('Time (s)');
  36. ylabel('Amplitude');
  37. title('Cosine Wave');
  38.  
  39. % Define the parameters
  40. frequency = 10; % Frequency in Hertz
  41. amplitude = 1; % Amplitude of the waves
  42. phase = 0; % Phase shift in radians
  43. samplingRate = 8000; % Sampling rate in samples per second
  44. duration = 0.25; % Duration of the signal in seconds
  45.  
  46. % Create the time vector
  47. t = 0:1/samplingRate:duration;
  48.  
  49. % Generate the sine and cosine waves
  50. y_sin = amplitude * sin(2 * pi * frequency * t + phase);
  51. y_cos = amplitude * cos(2 * pi * frequency * t + phase);
  52.  
  53. % Plot the sine wave in red
  54. plot(t, y_sin, 'r');
  55. hold on; % This command holds the current plot
  56.  
  57. % Plot the cosine wave in black
  58. plot(t, y_cos, 'b');
  59. hold off; % This command releases the current plot
  60.  
  61. % Add labels and title
  62. xlabel('Time (s)');
  63. ylabel('Amplitude');
  64. title('Sine and Cosine Waves');
  65. legend('Sine Wave', 'Cosine Wave'); % Add a legend