Matlab演奏《我和我的祖国》

2023-12-29 15:59
文章标签 matlab 演奏 祖国

本文主要是介绍Matlab演奏《我和我的祖国》,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

没有假期,但是节日快乐
在这里插入图片描述

每年都会听到这首歌,但总听不腻,最近看到matlab演奏歌曲的代码,就想自己试一试,其实还挺简单的,就是有点难(bushi),主要是不会识谱(丢人),代码是按照我微薄的乐理知识来写的,可能细节上有点问题,我会找时间修正的。

%前奏
y1 = gen_wave(1,0.25);
y2 = gen_wave(2,0.25);
y3 = gen_wave(3,0.25);
y4 = gen_wave(2,0.25);
y5 = gen_wave(1,0.25);
y6 = gen_wave(6,0.25);
y = [y1,y2,y3,y4,y5,y6];y1 = gen_wave(7,0.25);
y2 = gen_wave(6,0.25);
y3 = gen_wave(3,0.25);
y4 = gen_wave(5,1);
y = [y,y1,y2,y3,y4];y1 = gen_wave(1,0.25);
y2 = gen_wave(2,0.25);
y3 = gen_wave(3,0.25);
y4 = gen_wave(2,0.25);
y5 = gen_wave(1,0.25);
y6 = gen_wave(6,0.25);
y = [y,y1,y2,y3,y4,y5,y6];y1 = gen_wave(7,0.25);
y2 = gen_wave(5,0.25);
y3 = gen_wave(3,0.25);
y4 = gen_wave(6,1);
y = [y,y1,y2,y3,y4];y1 = gen_wave(5,0.25);
y2 = gen_wave(4,0.25);
y3 = gen_wave(3,0.25);
y4 = gen_wave(2,1);
y5 = gen_wave1(7,0.25);
y6 = gen_wave1(6,0.25);
y7 = gen_wave1(5,0.25);
y8 = gen_wave(3,1);
y = [y,y1,y2,y3,y4,y5,y6,y7,y8];y1 = gen_wave1(4,1);
y2 = gen_wave(2,1);
y3 = gen_wave(1,1);
y4 = gen_wave(1,1);
y = [y,y1,y2,y3,y4];%我和我的祖国
y1 = gen_wave(5,0.25);
y2 = gen_wave(6,0.25);
y3 = gen_wave(5,0.25);
y4 = gen_wave(4,0.25);
y5 = gen_wave(3,0.25);
y6 = gen_wave(2,0.25);
y7 = gen_wave(1,1);
y8 = gen_wave1(5,1);
y = [y,y1,y2,y3,y4,y5,y6,y7,y8];%一刻也不能分割
y1 = gen_wave1(1,0.25);
y2 = gen_wave(3,0.25);
y3 = gen_wave(1,0.25);
y4 = gen_wave1(7,0.25);
y5 = gen_wave1(6,0.25);
y6 = gen_wave1(3,0.25);
y7 = gen_wave1(5,1);
y = [y,y1,y2,y3,y4,y5,y6,y7];%无论我走到哪里
y1 = gen_wave(6,0.25);
y2 = gen_wave(7,0.25);
y3 = gen_wave(6,0.25);
y4 = gen_wave(5,0.25);
y5 = gen_wave(4,0.25);
y6 = gen_wave(3,0.25);
y7 = gen_wave(2,1);
y8 = gen_wave1(6,1);
y = [y,y1,y2,y3,y4,y5,y6,y7,y8];%都流出一首赞歌
y1 = gen_wave1(7,0.25);
y2 = gen_wave1(6,0.25);
y3 = gen_wave1(5,0.25);
y4 = gen_wave(5,0.25);
y5 = gen_wave(1,0.25);
y6 = gen_wave(2,0.25);
y7 = gen_wave(3,1);
y = [y,y1,y2,y3,y4,y5,y6,y7];%我歌唱每一座高山
y1 = gen_wave(5,0.25);
y2 = gen_wave(6,0.25);
y3 = gen_wave(5,0.25);
y4 = gen_wave(4,0.25);
y5 = gen_wave(3,0.25);
y6 = gen_wave(2,0.25);
y7 = gen_wave(1,1);
y8 = gen_wave1(5,1);
y = [y,y1,y2,y3,y4,y5,y6,y7,y8];%我歌唱每一条河
y1 = gen_wave(1,0.25);
y2 = gen_wave(3,0.25);
y3 = gen_wave(1,0.25);
y4 = gen_wave(7,0.25);
y5 = gen_wave(2,0.25);
y6 = gen_wave(1,0.25);
y7 = gen_wave(6,1);
y = [y,y1,y2,y3,y4,y5,y6,y7];%袅袅炊烟
y1 = gen_wave(1,0.25);
y2 = gen_wave(7,0.25);
y3 = gen_wave(6,0.25);
y4 = gen_wave(5,1);
y = [y,y1,y2,y3,y4];%小小村落
y1 = gen_wave(6,0.25);
y2 = gen_wave(5,0.25);
y3 = gen_wave(4,0.25);
y4 = gen_wave(3,1);
y = [y,y1,y2,y3,y4];%路上一道辙
y1 = gen_wave1(7,1);
y2 = gen_wave1(6,1);
y3 = gen_wave1(5,0.5);
y4 = gen_wave(2,1);
y5 = gen_wave(1,1);
y = [y,y1,y2,y3,y4,y5];% 我最亲爱的祖国
y1 = gen_wave(1,0.25);
y2 = gen_wave(2,0.25);
y3 = gen_wave(3,0.25);
y4 = gen_wave(2,0.25);
y5 = gen_wave(1,0.25);
y6 = gen_wave(6,0.25);
y7 = gen_wave(7,0.25);
y8 = gen_wave(6,0.25);
y9 = gen_wave(3,0.25);
y10 = gen_wave(5,1);
y = [y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10];%我永远紧依着你的心窝
y1 = gen_wave(1,0.25);
y2 = gen_wave(2,0.25);
y3 = gen_wave(3,0.25);
y4 = gen_wave(2,0.25);
y5 = gen_wave(1,0.25);
y6 = gen_wave(6,0.25);
y7 = gen_wave(7,0.25);
y8 = gen_wave(5,0.25);
y9 = gen_wave(3,0.25);
y10 = gen_wave(6,1);
y = [y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10];%你用你那  母亲的脉搏和我诉说
y1 = gen_wave1(5,0.25);
y2 = gen_wave(4,0.25);
y3 = gen_wave(3,0.25);
y4 = gen_wave(2,1);
y=[y,y1,y2,y3,y4];y1 = gen_wave1(7,0.25);
y2 = gen_wave1(6,0.5);
y3 = gen_wave1(6,0.5);
y4 = gen_wave1(5,0.25);
y5 = gen_wave(3,1);
y6 = gen_wave(3,1);
y7 = gen_wave(2,1);
y8 = gen_wave(1,1);
% y13 = gen_wave(1,1);
% y14 = gen_wave(8,1);
y = [y,y1,y2,y3,y4,y5,y6,y7,y8 ];sound(y);
%plot(y);

gen_wave1函数:

function y = gen_wave1( tone, rhythm )
%UNTITLED3 此处显示有关此函数的摘要
%   此处显示详细说明Fs = 8192;freqs = [261,293,329,349,392,440,493];x = linspace(0,2*pi*rhythm,floor(Fs*rhythm));y = sin(freqs(tone)*x).*(1-x/(rhythm*2*pi));
end

gen_wave函数:

function y = gen_wave( tone, rhythm )
%UNTITLED2 此处显示有关此函数的摘要
%   此处显示详细说明Fs = 8192;freqs = [523,587,659,698,783,880,988,0];x = linspace(0,2*pi*rhythm,floor(Fs*rhythm));y = sin(freqs(tone)*x).*(1-x/(rhythm*2*pi));
end

这篇关于Matlab演奏《我和我的祖国》的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/549941

相关文章

matlab读取NC文件(含group)

matlab读取NC文件(含group): NC文件数据结构: 代码: % 打开 NetCDF 文件filename = 'your_file.nc'; % 替换为你的文件名% 使用 netcdf.open 函数打开文件ncid = netcdf.open(filename, 'NC_NOWRITE');% 查看文件中的组% 假设我们想读取名为 "group1" 的组groupName

利用matlab bar函数绘制较为复杂的柱状图,并在图中进行适当标注

示例代码和结果如下:小疑问:如何自动选择合适的坐标位置对柱状图的数值大小进行标注?😂 clear; close all;x = 1:3;aa=[28.6321521955954 26.2453660695847 21.69102348512086.93747104431360 6.25442246899816 3.342835958564245.51365061796319 4.87

C# double[] 和Matlab数组MWArray[]转换

C# double[] 转换成MWArray[], 直接赋值就行             MWNumericArray[] ma = new MWNumericArray[4];             double[] dT = new double[] { 0 };             double[] dT1 = new double[] { 0,2 };

libsvm在matlab中的使用方法

原文地址:libsvm在matlab中的使用方法 作者: lwenqu_8lbsk 前段时间,gyp326曾在论坛里问libsvm如何在matlab中使用,我还奇怪,认为libsvm是C的程序,应该不能。没想到今天又有人问道,难道matlab真的能运行libsvm。我到官方网站看了下,原来,真的提供了matlab的使用接口。 接口下载在: http://www.csie.ntu.edu.

Matlab/Simulink中PMSM模型的反电动势系数和转矩系数

Matlab/Simulink中PMSM模型的反电动势系数和转矩系数_matlab pmsm-CSDN博客

MATLAB层次聚类分析法

转自:http://blog.163.com/lxg_1123@126/blog/static/74841406201022774051963/ 层次聚类是基于距离的聚类方法,MATLAB中通过pdist、linkage、dendrogram、cluster等函数来完成。层次聚类的过程可以分这么几步: (1) 确定对象(实际上就是数据集中的每个数据点)之间的相似性,实际上就是定义一个表征

MATLAB的fix(),floor()和ceil()函数的区别与联系

fix(x),floor(x)和ceil(x)函数都是对x取整,只不过取整方向不同而已。 这里的方向是以x轴作为横坐标来看的,向右就是朝着正轴方向,向左就是朝着负轴方向。 fix(x):向0取整(也可以理解为向中间取整) floor(x):向左取整 ceil(x):向右取整 举例: 4个数:a=3.3、b=3.7、c=-3.3、d=-3.7 fix(a)=3 fl

MATLAB中的eig函数

在MATLAB中,计算矩阵A的特征值和特征向量的函数是eig(A),常用的调用格式有5种: E=eig(A):求矩阵A的全部特征值,构成向量E。 [V,D]=eig(A):求矩阵A的全部特征值,构成对角阵D,并求A的特征向量构成V的列向量。 [V,D]=eig(A,'nobalance'):与第2种格式类似,但第2种格式中先对A作相似变换后求矩阵A的特征值和特征向量,而格式3直接求矩阵A的特

MATLAB中的diag函数

diag函数功能:矩阵对角元素的提取和创建对角阵 设以下X为方阵,v为向量 1、X = diag(v,k)当v是一个含有n个元素的向量时,返回一个n+abs(k)阶方阵X,向量v在矩阵X中的第k个对角线上,k=0表示主对角线,k>0表示在主对角线上方,k<0表示在主对角线下方。例1: v=[1 2 3]; diag(v, 3) ans =      0     0     0

Matlab simulink建模与仿真 第十章(模型扩展功能库)

参考视频:simulink1.1simulink简介_哔哩哔哩_bilibili 一、模型扩展功能库中的模块概览         注:下面不会对Block Support Table模块进行介绍。 二、基于触发的和基于时间的线性化模块 1、Trigger-Based Linearization基于触发的线性化模块 (1)每次当模块受到触发时,都会调用linmod或者dlinmod函数